PHP_CodeSniffer: notify-send report

I use emacs as IDE, and wanted to have direct feedback about the validity of my .php files when writing them. The most easy way was to add a save hook that runs PHP_CodeSniffer - but the results should be displayed in a nice, unobtrusive way.

phpcs has multiple reporting modes - xml, checkstyle, csv etc. - but nothing for the desktop. I thought that notify-send would be the right fit since it is able to display pretty popup messages without getting in the way.

So I hacked a bit and send a pull request to Greg that got merged today. So in the next version of PHP_CodeSniffer, you will be able to enjoy it, too!

So when running

$ phpcs --report=notifysend file.php

you will see something along this:

phpcs error phpcs ok

emacs integration

The integration into emacs is pretty simple. Just put the following into your .emacs file:

(defun phpcs-notifysend()
  "Performs a PHP code sniffer check on the current file and shows a
popup message." (interactive)
   "phpcs" nil
   (format "phpcs --standard=TYPO3 --report=notifysend \"%s\""

Using M-x phpcs-notifysend, you'll run the check immediately. Running it automatically when a file gets saved isn't hard either:

(defun phpcs-notifysend-hook ()
  (when (string-match "\.php$" buffer-file-truename)
(add-hook 'after-save-hook 'phpcs-notifysend-hook)


Hans-Peter Buniat told me about his tool Testy which runs unit tests and has many options to notify you about the results - including notify-send, dbus and Growl. It could be started from within emacs, too.

Written by Christian Weiske.

Comments? Please send an e-mail.