2012-12-05 42 views
3

PHP_CodeSniffer中的設置是否顯示失敗的嗅探器?我將輸出與我們的編碼標準進行比較,逐一使用很難破譯哪個測試失敗,看看我們可能會忽略哪些測試。PHP_CodeSniffer - 顯示失敗的嗅探器

如果有一個簡單的方法來顯示失敗嗅探,那麼我可以更容易,更快地完成配置。

回答

5

您可以使用-s命令行參數顯示錯誤消息的來源。

$ phpcs temp.php -s  

FILE: /Users/gsherwood/Sites/Projects/PHP_CodeSniffer/temp.php 
-------------------------------------------------------------------------------- 
FOUND 4 ERROR(S) AFFECTING 2 LINE(S) 
-------------------------------------------------------------------------------- 
2 | ERROR | Missing file doc comment (PEAR.Commenting.FileComment.Missing) 
2 | ERROR | Missing class doc comment (PEAR.Commenting.ClassComment.Missing) 
2 | ERROR | Opening brace of a class must be on the line after the definition 
    |  | (PEAR.Classes.ClassDeclaration.OpenBraceNewLine) 
3 | ERROR | Missing function doc comment 
    |  | (PEAR.Commenting.FunctionComment.Missing) 
-------------------------------------------------------------------------------- 

Time: 0 seconds, Memory: 4.50Mb 

您還可以使用源報告來顯示所有失敗的嗅探列表。

$ phpcs temp.php --report=source 

PHP CODE SNIFFER VIOLATION SOURCE SUMMARY 
-------------------------------------------------------------------------------- 
STANDARD CATEGORY   SNIFF          COUNT 
-------------------------------------------------------------------------------- 
PEAR  Commenting   File comment missing       1 
PEAR  Commenting   Class comment missing      1 
PEAR  Classes    Class declaration open brace new line  1 
PEAR  Commenting   Function comment missing      1 
-------------------------------------------------------------------------------- 
A TOTAL OF 4 SNIFF VIOLATION(S) WERE FOUND IN 4 SOURCE(S) 
-------------------------------------------------------------------------------- 

Time: 0 seconds, Memory: 4.75Mb 

$ phpcs temp.php --report=source -s 

PHP CODE SNIFFER VIOLATION SOURCE SUMMARY 
-------------------------------------------------------------------------------- 
SOURCE                  COUNT 
-------------------------------------------------------------------------------- 
PEAR.Commenting.FileComment.Missing          1 
PEAR.Commenting.ClassComment.Missing          1 
PEAR.Classes.ClassDeclaration.OpenBraceNewLine        1 
PEAR.Commenting.FunctionComment.Missing         1 
-------------------------------------------------------------------------------- 
A TOTAL OF 4 SNIFF VIOLATION(S) WERE FOUND IN 4 SOURCE(S) 
-------------------------------------------------------------------------------- 

Time: 0 seconds, Memory: 4.75Mb 
+0

任何方式來有兩個選項?我喜歡-s向我顯示因錯誤而失敗的嗅探,然後--report = source的摘要視圖有利於整體覆蓋。但是,看到兩者的能力都會很好。 –

+2

如果需要,您可以打印2份報告,也可以打印多份報告。如果需要,您還可以打印不同的報告到不同的輸出文件。對於我給出的例子,爲了顯示兩個報告,您可以使用命令:'phpcs temp.php -s --report = full --report = source' –

+0

謝謝。這兩份報告的第二個選項正是我所期待的。如果只是這是一個正常的答案,所以我可以再次投票。再次感謝。 –