コードレビューをしていただいている中で何度も指摘されているのでさすがに忘れないようにメモしておく
// NG:開きかっこの右、閉じかっこの左にはスペースを入れてはいけない
if ( $value == 3 ) {
// OK
if ($value == 3) {
// NG:カンマの左にスペースを入れてはいけない
explode(',' , $array);
// OK
explode(',', $array);
//NG:コメントを書く際には半角スペースを1つ入れる
// OK
// NG:関数を定義するときの開きかっこは改行する
public function test() {
echo 'test';
}
// OK
public function test()
{
echo 'test';
}
追記
KEINOSさんのコメントを受けてphpcsを導入してみました。
$ phpcs --standard=PSR2 testfile.php
FILE: testfile.php
---------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 64 ERRORS AND 17 WARNINGS AFFECTING 69 LINES
---------------------------------------------------------------------------------------------------------------------------------------------------
1 | WARNING | [ ] A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute
| | logic with side effects, but should not do both. The first symbol is defined on line 10 and the first side effect is on line
| | 2.
10 | ERROR | [ ] Each class must be in a namespace of at least one level (a top-level vendor name)
10 | ERROR | [x] Opening brace of a class must be on the line after the definition
22 | ERROR | [x] Spaces must be used for alignment; tabs are not allowed
22 | ERROR | [x] Whitespace found at end of line
24 | ERROR | [ ] Method name "RepRating::update_rating" is not in camel caps format
28 | ERROR | [x] Spaces must be used to indent lines; tabs are not allowed
28 | ERROR | [x] Expected 1 space(s) after SWITCH keyword; 0 found
29 | ERROR | [x] Spaces must be used to indent lines; tabs are not allowed
…etc
いっぱいエラーがあったおorz