phpでコーディング規約に沿っているかチェックするPHP_CodeSniffer(javaでいうcheckstyle的な)

phpでコーディング規約に沿っているかチェックする

インストール

pear install PHP_CodeSniffer

Zendのコーディング規約でチェックする

phpcs --standard=Zend users_controller.php

[出力結果]
FILE: /home/hogehoge/public_html/app/controllers/users_controller.php
——————————————————————————–
FOUND 20 ERROR(S) AFFECTING 21 LINE(S)
——————————————————————————–
10 | ERROR | Opening brace of a class must be on the line after the
| | definition
19 | ERROR | Opening brace should be on a new line
24 | ERROR | Opening brace should be on a new line
31 | ERROR | Opening brace should be on a new line
44 | ERROR | Opening brace should be on a new line
47 | ERROR | Expected “if (…) {\n”; found “if (…)\n {\n”
56 | ERROR | Space found before comma in function call
57 | ERROR | Space found before comma in function call
64 | ERROR | Opening brace should be on a new line
67 | ERROR | Expected “if (…) {\n”; found “if (…)\n {\n”
71 | WARNING | Line exceeds 120 characters; contains 139 characters
77 | ERROR | Space found before comma in function call
85 | ERROR | Opening brace should be on a new line
93 | ERROR | Expected “if (…) {\n”; found “if (…)\n {\n”
97 | ERROR | Line exceeds maximum limit of 140 characters; contains 142
| | characters
107 | ERROR | Opening brace should be on a new line
108 | ERROR | Spaces must be used to indent lines; tabs are not allowed
116 | ERROR | Opening brace should be on a new line
124 | ERROR | Opening brace should be on a new line
126 | ERROR | Expected “if (…) {\n”; found “if (…)\n {\n”
139 | ERROR | Expected “if (…) {\n”; found “if (…)\n {\n”
——————————————————————————–

デフォルトのコーディング規約をZendに設定

phpcs --config-set default_standard Zend

これでいちいち規約を設定しなくてもおk

Tags: , , , , , ,

This entry was posted on 火曜日, 9月 7th, 2010 at 8:39 PM and is filed under php, 備忘録. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply