Re: PHP_CodeSniffer Add in a specific Sniff for every file

From: Date: Wed, 16 May 2007 06:03:09 +0000
Subject: Re: PHP_CodeSniffer Add in a specific Sniff for every file
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-27308@lists.php.net to get a copy of this message
Paul Scott wrote:
I too, am now trying to deploy a webservice based on CodeSniffer that the developers on our projects can use to check their code. My problem is that at the top of every file we have a security check (except on index.php) that looks like this: // security check - must be included in all scripts if (!$GLOBALS['kewl_entry_point_run']) { die("You cannot view this page directly"); } // end security check Now, I still would like to include and use the Generic FileCommentSniff (slightly modified) as well. I see that there is a check to ignore the vim: bits and pieces, but this doesn't really suit my needs. Could anyone shed some light here for me? I think that this is an awesome piece of code, and will decrease peer review time drastically. Thanks to Squiz for this one and well done! --Paul Hi Paul,
If you want to check for the existence of this security code in each file, you can write a new sniff to do so. Get this sniff to check that the code is there, is formatted how you want, and is placed in the correct location. Leave the FileCommentSniff to check your file comments and place your security code below your file comment. If you want your security code to be at the top of the file before the file comment, you'll need to disable the FileCommentSniff and write your own version. I'd still recommend a separate sniff for checking that the security code exists. Either way, you'll need to create your own coding standard directory and a coding standard class (check the docs for a tutorial). In your coding standard class, you'll want to define a list of sniffs that your new standard includes. It will include your new security code sniff by default (and your copy of the FileCommentSniff if you wrote one) as they will be in the Sniffs sub-directory of your standard, but you'll also want to pick and choose which Generic, PEAR and Squiz sniffs you'd like to include. Take a look at the PEAR or Squiz coding standard classes for an example of this. Hope that gets you started. Greg

« previous php.pear.general (#27308) next »