diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..edd20f8 --- /dev/null +++ b/LICENSE @@ -0,0 +1,24 @@ +Copyright (c) 2015-2017, Barracuda Networks, Inc. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/PHP_CodeSniffer/Barracuda/Sniffs/Commenting/DisallowSingleLineMultiCommentsSniff.php b/PHP_CodeSniffer/Barracuda/Sniffs/Commenting/DisallowSingleLineMultiCommentsSniff.php index b646803..f13bb14 100755 --- a/PHP_CodeSniffer/Barracuda/Sniffs/Commenting/DisallowSingleLineMultiCommentsSniff.php +++ b/PHP_CodeSniffer/Barracuda/Sniffs/Commenting/DisallowSingleLineMultiCommentsSniff.php @@ -1,35 +1,26 @@ - * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence - * @version 1.0.00 - * @link http://pear.php.net/package/PHP_CodeSniffer + * @license BSD License 2.0, see LICENSE file. + * @version 2.0.00 + * @link https://github.com/BarracudaNetworks/Cuda-PHP-Code-Standards/ */ + namespace Barracuda\Sniffs\Commenting; + + use PHP_CodeSniffer\Sniffs\Sniff; + use PHP_CodeSniffer\Files\File; + /** - * This sniff prohibits the use of Perl style hash comments. - * - * An example of a hash comment is: - * - * - * /* This is a single line multi line comment, which is prohibited. */ -/* $hello = 'hello'; - * - * - * @category PHP - * @package PHP_CodeSniffer - * @author Ryan Matthews - * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence - * @version Release: 1.0.00 - * @link http://pear.php.net/package/PHP_CodeSniffer + * Prohibits single line block comments. */ -class Barracuda_Sniffs_Commenting_DisallowSingleLineMultiCommentsSniff implements PHP_CodeSniffer_Sniff +class DisallowSingleLineMultiCommentsSniff implements Sniff { @@ -48,13 +39,12 @@ public function register() /** * Processes the tokens that this sniff is interested in. * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. - * @param int $stackPtr The position in the stack where - * the token was found. + * @param File $phpcsFile The file where the token was found. + * @param int $stackPtr The position in the stack where the token was found. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); if (preg_match('/\/\*[^\n]*\*\//', $tokens[$stackPtr]['content'])) @@ -67,4 +57,3 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) }// end process() } // end class - diff --git a/PHP_CodeSniffer/Barracuda/Sniffs/Commenting/DocCommentSniff.php b/PHP_CodeSniffer/Barracuda/Sniffs/Commenting/DocCommentSniff.php index 73f11a5..6c15087 100644 --- a/PHP_CodeSniffer/Barracuda/Sniffs/Commenting/DocCommentSniff.php +++ b/PHP_CodeSniffer/Barracuda/Sniffs/Commenting/DocCommentSniff.php @@ -1,6 +1,27 @@ + * @license BSD License 2.0, see LICENSE file. + * @version 2.0.00 + * @link https://github.com/BarracudaNetworks/Cuda-PHP-Code-Standards/ + */ + +namespace Barracuda\Sniffs\Commenting; + +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Util\Common; + +/** + * Controls requirements for PHP doc blocks. + */ +class DocCommentSniff implements Sniff { /** @@ -71,13 +92,12 @@ public function register() /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token in the stack passed in $tokens. * * @return int */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); @@ -156,14 +176,13 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) /** * Processes each required or optional tag. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * @param int $commentStart Position in the stack where the comment started. + * @param File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token in the stack passed in $tokens. + * @param int $commentStart Position in the stack where the comment started. * * @return void */ - protected function processTags(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $commentStart) + protected function processTags(File $phpcsFile, $stackPtr, $commentStart) { $tokens = $phpcsFile->getTokens(); @@ -255,12 +274,12 @@ protected function processTags(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $comm /** * Process the category tag. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param array $tags The tokens for these tags. + * @param File $phpcsFile The file being scanned. + * @param array $tags The tokens for these tags. * * @return void */ - protected function processCategory(PHP_CodeSniffer_File $phpcsFile, array $tags) + protected function processCategory(File $phpcsFile, array $tags) { $tokens = $phpcsFile->getTokens(); foreach ($tags as $tag) { @@ -270,7 +289,7 @@ protected function processCategory(PHP_CodeSniffer_File $phpcsFile, array $tags) } $content = $tokens[($tag + 2)]['content']; - if (PHP_CodeSniffer::isUnderscoreName($content) !== true) { + if (Common::isUnderscoreName($content) !== true) { $newContent = str_replace(' ', '_', $content); $nameBits = explode('_', $newContent); $firstBit = array_shift($nameBits); @@ -297,12 +316,12 @@ protected function processCategory(PHP_CodeSniffer_File $phpcsFile, array $tags) /** * Process the package tag. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param array $tags The tokens for these tags. + * @param File $phpcsFile The file being scanned. + * @param array $tags The tokens for these tags. * * @return void */ - protected function processPackage(PHP_CodeSniffer_File $phpcsFile, array $tags) + protected function processPackage(File $phpcsFile, array $tags) { $tokens = $phpcsFile->getTokens(); foreach ($tags as $tag) { @@ -312,7 +331,7 @@ protected function processPackage(PHP_CodeSniffer_File $phpcsFile, array $tags) } $content = $tokens[($tag + 2)]['content']; - if (PHP_CodeSniffer::isUnderscoreName($content) === true) { + if (Common::isUnderscoreName($content) === true) { continue; } @@ -343,12 +362,12 @@ protected function processPackage(PHP_CodeSniffer_File $phpcsFile, array $tags) /** * Process the subpackage tag. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param array $tags The tokens for these tags. + * @param File $phpcsFile The file being scanned. + * @param array $tags The tokens for these tags. * * @return void */ - protected function processSubpackage(PHP_CodeSniffer_File $phpcsFile, array $tags) + protected function processSubpackage(File $phpcsFile, array $tags) { $tokens = $phpcsFile->getTokens(); foreach ($tags as $tag) { @@ -358,7 +377,7 @@ protected function processSubpackage(PHP_CodeSniffer_File $phpcsFile, array $tag } $content = $tokens[($tag + 2)]['content']; - if (PHP_CodeSniffer::isUnderscoreName($content) === true) { + if (Common::isUnderscoreName($content) === true) { continue; } @@ -432,12 +451,12 @@ protected function processCopyrights($errorPos) /** * Process the license tag. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param array $tags The tokens for these tags. + * @param File $phpcsFile The file being scanned. + * @param array $tags The tokens for these tags. * * @return void */ - protected function processLicense(PHP_CodeSniffer_File $phpcsFile, array $tags) + protected function processLicense(File $phpcsFile, array $tags) { $tokens = $phpcsFile->getTokens(); foreach ($tags as $tag) { @@ -461,12 +480,12 @@ protected function processLicense(PHP_CodeSniffer_File $phpcsFile, array $tags) /** * Process the version tag. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param array $tags The tokens for these tags. + * @param File $phpcsFile The file being scanned. + * @param array $tags The tokens for these tags. * * @return void */ - protected function processVersion(PHP_CodeSniffer_File $phpcsFile, array $tags) + protected function processVersion(File $phpcsFile, array $tags) { $tokens = $phpcsFile->getTokens(); foreach ($tags as $tag) { diff --git a/PHP_CodeSniffer/Barracuda/Sniffs/Commenting/FunctionCommentSniff.php b/PHP_CodeSniffer/Barracuda/Sniffs/Commenting/FunctionCommentSniff.php index ffce82b..83622a8 100644 --- a/PHP_CodeSniffer/Barracuda/Sniffs/Commenting/FunctionCommentSniff.php +++ b/PHP_CodeSniffer/Barracuda/Sniffs/Commenting/FunctionCommentSniff.php @@ -6,30 +6,23 @@ * * @category PHP * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer + * @author Ryan Matthews + * @license BSD License 2.0, see LICENSE file. + * @version 2.0.00 + * @link https://github.com/BarracudaNetworks/Cuda-PHP-Code-Standards/ */ -if (class_exists('PEAR_Sniffs_Commenting_FunctionCommentSniff', true) === false) { - throw new PHP_CodeSniffer_Exception('Class PEAR_Sniffs_Commenting_FunctionCommentSniff not found'); -} +namespace Barracuda\Sniffs\Commenting; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Util\Common; +use PHP_CodeSniffer\Standards\PEAR\Sniffs\Commenting\FunctionCommentSniff as PEARFunctionCommentSniff; /** - * Parses and verifies the doc comments for functions. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer + * Parses and verifies doc comments for functions. */ -class Barracuda_Sniffs_Commenting_FunctionCommentSniff extends PEAR_Sniffs_Commenting_FunctionCommentSniff +class FunctionCommentSniff extends PEARFunctionCommentSniff { protected $allowedTypes = array( 'int', @@ -38,20 +31,19 @@ class Barracuda_Sniffs_Commenting_FunctionCommentSniff extends PEAR_Sniffs_Comme public function __construct() { - PHP_CodeSniffer::$allowedTypes = array_merge(PHP_CodeSniffer::$allowedTypes, $this->allowedTypes); + Common::$allowedTypes = array_merge(Common::$allowedTypes, $this->allowedTypes); } /** * Process the return comment of this function comment. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * @param int $commentStart The position in the stack where the comment started. + * @param File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token in the stack passed in $tokens. + * @param int $commentStart The position in the stack where the comment started. * * @return void */ - protected function processReturn(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $commentStart) + protected function processReturn(File $phpcsFile, $stackPtr, $commentStart) { $tokens = $phpcsFile->getTokens(); @@ -86,7 +78,7 @@ protected function processReturn(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co $typeNames = explode('|', $content); $suggestedNames = array(); foreach ($typeNames as $i => $typeName) { - $suggestedName = PHP_CodeSniffer::suggestType($typeName); + $suggestedName = Common::suggestType($typeName); if (in_array($suggestedName, $suggestedNames) === false) { $suggestedNames[] = $suggestedName; } @@ -163,14 +155,13 @@ protected function processReturn(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co /** * Process any throw tags that this function comment has. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * @param int $commentStart The position in the stack where the comment started. + * @param File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token in the stack passed in $tokens. + * @param int $commentStart The position in the stack where the comment started. * * @return void */ - protected function processThrows(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $commentStart) + protected function processThrows(File $phpcsFile, $stackPtr, $commentStart) { $tokens = $phpcsFile->getTokens(); @@ -232,14 +223,13 @@ protected function processThrows(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co /** * Process the function parameter comments. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * @param int $commentStart The position in the stack where the comment started. + * @param File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token in the stack passed in $tokens. + * @param int $commentStart The position in the stack where the comment started. * * @return void */ - protected function processParams(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $commentStart) + protected function processParams(File $phpcsFile, $stackPtr, $commentStart) { $tokens = $phpcsFile->getTokens(); @@ -344,7 +334,7 @@ protected function processParams(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co // Check the param type value. $typeNames = explode('|', $param['type']); foreach ($typeNames as $typeName) { - $suggestedName = PHP_CodeSniffer::suggestType($typeName); + $suggestedName = Common::suggestType($typeName); if ($typeName !== $suggestedName) { $error = 'Expected "%s" but found "%s" for parameter type'; $data = array( @@ -373,7 +363,7 @@ protected function processParams(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co $suggestedTypeHint = 'callable'; } else if (strpos($suggestedName, 'callback') !== false) { $suggestedTypeHint = 'callable'; - } else if (in_array($typeName, PHP_CodeSniffer::$allowedTypes) === false) { + } else if (in_array($typeName, Common::$allowedTypes) === false) { $suggestedTypeHint = $suggestedName; } diff --git a/PHP_CodeSniffer/Barracuda/Sniffs/Commenting/SpaceAfterCommentSniff.php b/PHP_CodeSniffer/Barracuda/Sniffs/Commenting/SpaceAfterCommentSniff.php index 5a14db5..88c4639 100755 --- a/PHP_CodeSniffer/Barracuda/Sniffs/Commenting/SpaceAfterCommentSniff.php +++ b/PHP_CodeSniffer/Barracuda/Sniffs/Commenting/SpaceAfterCommentSniff.php @@ -1,5 +1,26 @@ + * @license BSD License 2.0, see LICENSE file. + * @version 2.0.00 + * @link https://github.com/BarracudaNetworks/Cuda-PHP-Code-Standards/ + */ + +namespace Barracuda\Sniffs\Commenting; + +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Files\File; + +/** + * Requires a space after opening of comment. + */ +class SpaceAfterCommentSniff implements Sniff { /** * Returns the token types that this sniff is interested in. @@ -16,13 +37,12 @@ public function register() /** * Processes the tokens that this sniff is interested in. * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. - * @param int $stackPtr The position in the stack where - * the token was found. + * @param File $phpcsFile The file where the token was found. + * @param int $stackPtr The position in the stack where the token was found. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); @@ -48,4 +68,3 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) }// end process() } // end class - diff --git a/PHP_CodeSniffer/Barracuda/Sniffs/Commenting/VariableCommentSniff.php b/PHP_CodeSniffer/Barracuda/Sniffs/Commenting/VariableCommentSniff.php index 56d0596..2f7899d 100644 --- a/PHP_CodeSniffer/Barracuda/Sniffs/Commenting/VariableCommentSniff.php +++ b/PHP_CodeSniffer/Barracuda/Sniffs/Commenting/VariableCommentSniff.php @@ -1,36 +1,28 @@ - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer + * @author Ryan Matthews + * @license BSD License 2.0, see LICENSE file. + * @version 2.0.00 + * @link https://github.com/BarracudaNetworks/Cuda-PHP-Code-Standards/ */ -if (class_exists('PHP_CodeSniffer_Standards_AbstractVariableSniff', true) === false) { - throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_Standards_AbstractVariableSniff not found'); -} +namespace Barracuda\Sniffs\Commenting; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\AbstractVariableSniff; +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Util\Common; /** - * Parses and verifies the variable doc comment. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer + * Parses and verifies variable doc comments. */ - -class Barracuda_Sniffs_Commenting_VariableCommentSniff extends PHP_CodeSniffer_Standards_AbstractVariableSniff +class VariableCommentSniff extends AbstractVariableSniff { protected $allowedTypes = array( 'bool', @@ -39,19 +31,18 @@ class Barracuda_Sniffs_Commenting_VariableCommentSniff extends PHP_CodeSniffer_S public function __construct() { - PHP_CodeSniffer::$allowedTypes = array_merge(PHP_CodeSniffer::$allowedTypes, $this->allowedTypes); + Common::$allowedTypes = array_merge(Common::$allowedTypes, $this->allowedTypes); } /** * Called to process class member vars. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. + * @param File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token in the stack passed in $tokens. * * @return void */ - public function processMemberVar(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function processMemberVar(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $commentToken = array( @@ -127,7 +118,7 @@ public function processMemberVar(PHP_CodeSniffer_File $phpcsFile, $stackPtr) } $varType = $tokens[($foundVar + 2)]['content']; - $suggestedType = PHP_CodeSniffer::suggestType($varType); + $suggestedType = Common::suggestType($varType); if ($varType !== $suggestedType) { $error = 'Expected "%s" but found "%s" for @var tag in member variable comment'; $data = array( @@ -145,13 +136,12 @@ public function processMemberVar(PHP_CodeSniffer_File $phpcsFile, $stackPtr) * * Not required for this sniff. * - * @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where this token was found. - * @param int $stackPtr The position where the double quoted - * string was found. + * @param File $phpcsFile The PHP_CodeSniffer file where this token was found. + * @param int $stackPtr The position where the double quoted string was found. * * @return void */ - protected function processVariable(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + protected function processVariable(File $phpcsFile, $stackPtr) { }//end processVariable() @@ -162,13 +152,12 @@ protected function processVariable(PHP_CodeSniffer_File $phpcsFile, $stackPtr) * * Not required for this sniff. * - * @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where this token was found. - * @param int $stackPtr The position where the double quoted - * string was found. + * @param File $phpcsFile The PHP_CodeSniffer file where this token was found. + * @param int $stackPtr The position where the double quoted string was found. * * @return void */ - protected function processVariableInString(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + protected function processVariableInString(File $phpcsFile, $stackPtr) { }//end processVariableInString() diff --git a/PHP_CodeSniffer/Barracuda/Sniffs/ControlStructures/ControlSignatureSniff.php b/PHP_CodeSniffer/Barracuda/Sniffs/ControlStructures/ControlSignatureSniff.php index bf24b7f..c9eec84 100644 --- a/PHP_CodeSniffer/Barracuda/Sniffs/ControlStructures/ControlSignatureSniff.php +++ b/PHP_CodeSniffer/Barracuda/Sniffs/ControlStructures/ControlSignatureSniff.php @@ -1,12 +1,28 @@ + * @license BSD License 2.0, see LICENSE file. + * @version 2.0.00 + * @link https://github.com/BarracudaNetworks/Cuda-PHP-Code-Standards/ + */ + +namespace Barracuda\Sniffs\ControlStructures; + +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Standards\Squiz\Sniffs\ControlStructures\ControlSignatureSniff as SquizControlSignatureSniff; +use PHP_CodeSniffer\Util\Tokens; + +/** + * Extends SquizControlSignatureSniff to allow dropped braces and prevent same-line braces. + */ +class ControlSignatureSniff extends SquizControlSignatureSniff { /** * A list of tokenizers this sniff supports. @@ -18,13 +34,12 @@ class Barracuda_Sniffs_ControlStructures_ControlSignatureSniff extends Squiz_Sni /** * Processes this test, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. + * @param File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token in the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); @@ -130,7 +145,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) // Skip all empty tokens on the same line as the opener. if ($tokens[$next]['line'] === $tokens[$opener]['line'] - && (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$code]) === true + && (isset(Tokens::$emptyTokens[$code]) === true || $code === T_CLOSE_TAG) ) { continue; @@ -193,7 +208,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) || $tokens[$stackPtr]['code'] === T_ELSEIF || $tokens[$stackPtr]['code'] === T_CATCH ) { - $closer = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true); + $closer = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true); if ($closer === false || $tokens[$closer]['code'] !== T_CLOSE_CURLY_BRACKET) { return; } @@ -239,7 +254,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) // Skip all empty tokens on the same line as the closer. if ($tokens[$next]['line'] === $tokens[$closer]['line'] - && (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$code]) === true + && (isset(Tokens::$emptyTokens[$code]) === true || $code === T_CLOSE_TAG) ) { continue; diff --git a/PHP_CodeSniffer/Barracuda/Sniffs/ControlStructures/NoInlineAssignmentSniff.php b/PHP_CodeSniffer/Barracuda/Sniffs/ControlStructures/NoInlineAssignmentSniff.php index 0a18d81..369e86f 100644 --- a/PHP_CodeSniffer/Barracuda/Sniffs/ControlStructures/NoInlineAssignmentSniff.php +++ b/PHP_CodeSniffer/Barracuda/Sniffs/ControlStructures/NoInlineAssignmentSniff.php @@ -1,6 +1,26 @@ + * @license BSD License 2.0, see LICENSE file. + * @version 2.0.00 + * @link https://github.com/BarracudaNetworks/Cuda-PHP-Code-Standards/ + */ -class Barracuda_Sniffs_ControlStructures_NoInlineAssignmentSniff implements PHP_CodeSniffer_Sniff +namespace Barracuda\Sniffs\ControlStructures; + +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Files\File; + +/** + * Disallows inline variable assignment. + */ +class NoInlineAssignmentSniff implements Sniff { /** * Returns an array of tokens this test wants to listen for. @@ -20,13 +40,12 @@ public function register() /** * Processes this sniff, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. + * @param File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token in the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); @@ -64,4 +83,3 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) } } } - diff --git a/PHP_CodeSniffer/Barracuda/Sniffs/Formatting/SpaceUnaryOperatorSniff.php b/PHP_CodeSniffer/Barracuda/Sniffs/Formatting/SpaceUnaryOperatorSniff.php index f1ca631..17987db 100644 --- a/PHP_CodeSniffer/Barracuda/Sniffs/Formatting/SpaceUnaryOperatorSniff.php +++ b/PHP_CodeSniffer/Barracuda/Sniffs/Formatting/SpaceUnaryOperatorSniff.php @@ -1,8 +1,27 @@ + * @license BSD License 2.0, see LICENSE file. + * @version 2.0.00 + * @link https://github.com/BarracudaNetworks/Cuda-PHP-Code-Standards/ + */ + +namespace Barracuda\Sniffs\Formatting; +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Files\File; +/** + * Prevents spaces from appearing on either side of a unary operator. + */ +class SpaceUnaryOperatorSniff implements Sniff +{ /** * Returns an array of tokens this test wants to listen for. */ @@ -21,8 +40,12 @@ public function register() /** * Processes this test, when one of its tokens is encountered. + * @param File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token in the stack passed in $tokens. + * + * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); diff --git a/PHP_CodeSniffer/Barracuda/Sniffs/Functions/FunctionDeclarationSniff.php b/PHP_CodeSniffer/Barracuda/Sniffs/Functions/FunctionDeclarationSniff.php index dd7fa20..a52b0ae 100644 --- a/PHP_CodeSniffer/Barracuda/Sniffs/Functions/FunctionDeclarationSniff.php +++ b/PHP_CodeSniffer/Barracuda/Sniffs/Functions/FunctionDeclarationSniff.php @@ -1,51 +1,41 @@ - * @copyright 2006-2012 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer + * @author Eric Olson + * @license BSD License 2.0, see LICENSE file. + * @version 2.0.00 + * @link https://github.com/BarracudaNetworks/Cuda-PHP-Code-Standards/ */ -if (class_exists('PEAR_Sniffs_Functions_FunctionDeclarationSniff', true) === false) { - $error = 'Class PEAR_Sniffs_Functions_FunctionDeclarationSniff not found'; - throw new PHP_CodeSniffer_Exception($error); -} +namespace Barracuda\Sniffs\Functions; + +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Standards\PEAR\Sniffs\Functions\FunctionDeclarationSniff as PEARFunctionDeclarationSniff; +use PHP_CodeSniffer\Standards\Generic\Sniffs\Functions\OpeningFunctionBraceBsdAllmanSniff; /** - * Barracuda_Sniffs_Functions_MultiLineFunctionDeclarationSniff. - * - * Ensure single and multi-line function declarations are defined correctly. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @copyright 2006-2012 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: 1.5.0RC4 - * @link http://pear.php.net/package/PHP_CodeSniffer + * Sets requirements for declaration of functions. */ -class Barracuda_Sniffs_Functions_FunctionDeclarationSniff extends PEAR_Sniffs_Functions_FunctionDeclarationSniff +class FunctionDeclarationSniff extends PEARFunctionDeclarationSniff { /** * Processes multi-line declarations. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * @param array $tokens The stack of tokens that make up - * the file. + * @param File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token in the stack passed in $tokens. + * @param array $tokens The stack of tokens that make up the file. * * @return void */ - public function processMultiLineDeclaration(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $tokens) + public function processMultiLineDeclaration($phpcsFile, $stackPtr, $tokens) { // We need to work out how far indented the function // declaration itself is, so we can work out how far to @@ -259,17 +249,14 @@ public function processMultiLineDeclaration(PHP_CodeSniffer_File $phpcsFile, $st /** * Processes the contents of a single set of brackets. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $openBracket The position of the open bracket - * in the stack passed in $tokens. - * @param array $tokens The stack of tokens that make up - * the file. - * @param string $type The type of the token the brackets - * belong to (function or use). + * @param File $phpcsFile The file being scanned. + * @param int $openBracket The position of the open bracket in the stack passed in $tokens. + * @param array $tokens The stack of tokens that make up the file. + * @param string $type The type of the token the brackets belong to (function or use). * * @return void */ - public function processBracket(PHP_CodeSniffer_File $phpcsFile, $openBracket, $tokens, $type='function') + public function processBracket(File $phpcsFile, $openBracket, $tokens, $type='function') { $errorPrefix = ''; if ($type === 'use') { @@ -320,21 +307,15 @@ public function processBracket(PHP_CodeSniffer_File $phpcsFile, $openBracket, $t * * Just uses the Generic BSD-Allman brace sniff. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * @param array $tokens The stack of tokens that make up - * the file. + * @param File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token in the stack passed in $tokens. + * @param array $tokens The stack of tokens that make up the file. * * @return void */ - public function processSingleLineDeclaration(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $tokens) + public function processSingleLineDeclaration($phpcsFile, $stackPtr, $tokens) { - if (class_exists('Generic_Sniffs_Functions_OpeningFunctionBraceBsdAllmanSniff', true) === false) { - throw new PHP_CodeSniffer_Exception('Class Generic_Sniffs_Functions_OpeningFunctionBraceBsdAllmanSniff not found'); - } - - $sniff = new Generic_Sniffs_Functions_OpeningFunctionBraceBsdAllmanSniff(); + $sniff = new OpeningFunctionBraceBsdAllmanSniff(); $sniff->process($phpcsFile, $stackPtr); diff --git a/PHP_CodeSniffer/Barracuda/Sniffs/Whitespace/SuperfluousWhitespaceSniff.php b/PHP_CodeSniffer/Barracuda/Sniffs/Whitespace/SuperfluousWhitespaceSniff.php index 01f0787..dcf6a6c 100644 --- a/PHP_CodeSniffer/Barracuda/Sniffs/Whitespace/SuperfluousWhitespaceSniff.php +++ b/PHP_CodeSniffer/Barracuda/Sniffs/Whitespace/SuperfluousWhitespaceSniff.php @@ -1,35 +1,28 @@ - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @link http://pear.php.net/package/PHP_CodeSniffer + * @author Ryan Matthews + * @license BSD License 2.0, see LICENSE file. + * @version 2.0.00 + * @link https://github.com/BarracudaNetworks/Cuda-PHP-Code-Standards/ */ +namespace Barracuda\Sniffs\Whitespace; + +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Files\File; + /** - * Barracuda_Sniffs_WhiteSpace_SuperfluousWhitespaceSniff. - * - * Checks that no whitespace proceeds the first content of the file, exists - * after the last content of the file, resides after content on any line, or - * are two empty lines in functions. - * - * @category PHP - * @package PHP_CodeSniffer - * @author Greg Sherwood - * @author Marc McIntyre - * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600) - * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence - * @version Release: @package_version@ - * @link http://pear.php.net/package/PHP_CodeSniffer + * Prohibits unnecessary whitespace within a file. */ -class Barracuda_Sniffs_WhiteSpace_SuperfluousWhitespaceSniff implements PHP_CodeSniffer_Sniff +class SuperfluousWhitespaceSniff implements Sniff { /** @@ -75,13 +68,12 @@ public function register() /** * Processes this sniff, when one of its tokens is encountered. * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. + * @param File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token in the stack passed in $tokens. * * @return void */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); diff --git a/README.md b/README.md index 2924b1f..4d37fef 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ INSTALLATION 1. Install [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer#installation) + **NOTE:** The sniffs contained in this repository require PHP_CodeSniffer 3.0 or higher. + 2. Install your editor plugin. - For Sublime Text, install `Phpcs` under Package Control - For Atom, install `linter` and `linter-phpcs`