PHPのコーディング規約をチェックするライブラリがあるようなので、遊んでみた。
PHPコーディング標準への適応状況をチェックする PHP_CodeSniffer
まずはインストール。
~% sudo pear install PHP_CodeSniffer-alpha
まだalphaらしい。インストールすると、phpcsというコマンドが使えるようになって、そのヘルプは以下。
~% phpcs -h Usage: phpcs [-nvi] [--report=] [--standard= ] ... : one or more files and/or directories to check : the name of the coding standard to use : print either the "full" or "summary" report -n : do not print warnings -v : print verbose output -i : show a list of installed coding standards -h --help : print this help message --version : print version information
以下は、標準で対応しているコーディング規約。まだPEARのみ。
~% phpcs -i The only coding standard installed is PEAR
コーディング規約は自分でも増やせるらしいけど、その辺は細かく追ってなし。
で、例のごとくEmacs用に適当に書いとく。
;;; ;;; PHPファイルの規約チェック (defun php-code-standard-check () "Performs a PHP code-standard-check on the current file." (interactive) (shell-command (concat "phpcs -v --standard=PEAR --report=full " (buffer-file-name))))
会社では、デイリービルドっぽくUnitTestを毎朝自動実行してる訳だけど、併せてこの辺もやっとくといいのかな?

