没有不值得去解决的问题,也没有不值得去学习的技术!

An Analysis of the “FILE: FOUND 1 ERROR AFFECTING 1 LINE” Prompt When Running phpcs

PHP_CodeSniffer tokenizes PHP, JavaScript, and CSS files to detect and fix violations of a defined set of coding standards. When running phpcs, it reports "FILE: FOUND 1 ERROR AFFECTING 1 LINE"

1. PHP_CodeSniffer tokenizes PHP, JavaScript, and CSS files to detect and fix violations of a defined set of coding standards. When running phpcs, it reports “FILE: FOUND 1 ERROR AFFECTING 1 LINE”. The analysis is shown in Figure 1.

PHP_CodeSniffer tokenizes PHP, JavaScript, and CSS files to detect and fix violations of a defined set of coding standards. When running phpcs, it reports "FILE: FOUND 1 ERROR AFFECTING 1 LINE"
Figure 1
Plaintext

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. First, checking the first file, line 182 contains ;;, and one ; needs to be removed. As shown in Figure 2.

First, checking the first file, line 182 contains ;;, and one ; needs to be removed
Figure 2

3. Next, checking the second file at lines 66 and 128, respectively. At line 66, the line is indented incorrectly; 8 spaces were expected, but 12 were found. At line 128, the function closing brace must be on the line following the body; 1 blank line was found before the brace. For line 66, the code can be formatted using an IDE. As shown in Figure 3.

Next, checking the second file at lines 66 and 128, respectively. At line 66, the line is indented incorrectly; 8 spaces were expected, but 12 were found. At line 128, the function closing brace must be on the line following the body; 1 blank line was found before the brace. For line 66, the code can be formatted using an IDE
Figure 3

4. When running phpcs, the error is no longer reported. As shown in Figure 4.

When running phpcs, the error is no longer reported
Figure 4

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系