How to ignore certain coding standard errors in PHP CodeSniffer

Posted by Tom on Pro Webmasters See other posts from Pro Webmasters or by Tom
Published on 2010-07-16T23:25:39Z Indexed on 2011/01/12 10:59 UTC
Read the original article Hit count: 396

Filed under:
|
|
|

We have a PHP 5 web application and we're currently evaluating PHP CodeSniffer in order to decide whether forcing code standards improves code quality without causing too much of a headache. If it seems good we will add a SVN pre-commit hook to ensure all new files committed on the dev branch are free from coding standard smells.

Is there a way to configure PHP codeSniffer to ignore a particular type of error? or get it to treat a certain error as a warning instead?

Here an example to demonstrate the issue:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<div>
    <?php
    echo getTabContent('Programming', 1, $numX, $numY);

    if (isset($msg)) {
        echo $msg;
    }
    ?>
</div>
</body>
</html>

And this is the output of PHP_CodeSniffer:

> phpcs test.php 

--------------------------------------------------------------------------------
FOUND 2 ERROR(S) AND 1 WARNING(S) AFFECTING 3 LINE(S)
--------------------------------------------------------------------------------
  1 | WARNING | Line exceeds 85 characters; contains 121 characters
  9 | ERROR   | Missing file doc comment
 11 | ERROR   | Line indented incorrectly; expected 0 spaces, found 4
--------------------------------------------------------------------------------

I have a issue with the "Line indented incorrectly" error. I guess it happens because I am mixing the PHP indentation with the HTML indentation. But this makes it more readable doesn't it? (taking into account that I don't have the resouces to move to a MVC framework right now). So I'd like to ignore it please.

© Pro Webmasters or respective owner

Related posts about standards

Related posts about code