执行 phpcs 时,提示 FILE: FOUND 1 ERROR AFFECTING 1 LINE 的分析
1、PHP_CodeSniffer 对 PHP、JavaScript 和 CSS 文件进行标记,以检测和修复违反一组定义的编码标准的情况。执行 phpcs 时,提示 FILE: FOUND 1 ERROR AFFECTING 1 LINE 的分析。如图1
PS E:\wwwroot\object> phpcs --standard=PSR1,PSR2,./ruleset.xml --ignore=config/us-zipcode.php app/ routes/ config/ FILE: ...root\object\app\Http\Controllers\CheckoutsController.php ---------------------------------------------------------------------- FOUND 1 ERROR AFFECTING 1 LINE ---------------------------------------------------------------------- 182 | ERROR | [x] Each PHP statement must be on a line by itself ---------------------------------------------------------------------- PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY ---------------------------------------------------------------------- FILE: E:\wwwroot\object\app\Services\ThemeService.php ---------------------------------------------------------------------- FOUND 3 ERRORS AFFECTING 2 LINES ---------------------------------------------------------------------- 66 | ERROR | [x] Line indented incorrectly; expected 8 spaces, | | found 12 66 | ERROR | [x] Closing brace indented incorrectly; expected 8 | | spaces, found 12 128 | ERROR | [x] Function closing brace must go on the next line | | following the body; found 1 blank lines before | | brace ---------------------------------------------------------------------- PHPCBF CAN FIX THE 3 MARKED SNIFF VIOLATIONS AUTOMATICALLY ---------------------------------------------------------------------- Time: 56.87 secs; Memory: 66MB PS E:\wwwroot\object>
2、先确认第一个文件,在 182 行,存在 ;; ,需要删除掉一个 ;。如图2
3、再确认第二个文件,分别在 66 、128 行。在 66 行,行缩进不正确;预计 8 个空格,找到 12 个。在 128 行,函数右大括号必须在正文的下一行;在大括号前找到 1 个空行。在 66 行,可以通过 IDE 格式化代码。如图3
4、执行 phpcs 时,不再提示。如图4
近期评论