├── .gitignore ├── Kohana ├── KohanaCodingStandard.php ├── Sniffs │ ├── Classes │ │ └── EmptyConstructorCallSniff.php │ ├── Commenting │ │ ├── DocBlockParamSniff.php │ │ ├── DocBlockSeeSniff.php │ │ └── OneLineCommentSniff.php │ ├── ControlStructures │ │ ├── ElseIfSniff.php │ │ ├── SingleLineIfSniff.php │ │ └── SwitchSniff.php │ ├── Functions │ │ └── RegularExpressionSniff.php │ ├── NamingConventions │ │ ├── UpperCaseConstantNameSniff.php │ │ ├── ValidFunctionNameSniff.php │ │ └── ValidVariableNameSniff.php │ ├── Operators │ │ ├── ComparisonOperatorSniff.php │ │ ├── TernaryOperatorSniff.php │ │ └── TypeCastingSniff.php │ └── WhiteSpace │ │ ├── NoConcatenationSpaceSniff.php │ │ └── ParenthesesSniff.php └── ruleset.xml ├── LICENSE.md ├── README.md ├── composer.json └── test └── PHP_CodeSniffer └── CodeSniffer └── Standards └── Kohana └── Tests ├── Classes ├── EmptyConstructorCallUnitTest.inc └── EmptyConstructorCallUnitTest.php ├── Commenting ├── DocBlockParamUnitTest.inc ├── DocBlockParamUnitTest.php ├── DocBlockSeeUnitTest.inc ├── DocBlockSeeUnitTest.php ├── OneLineCommentUnitTest.inc └── OneLineCommentUnitTest.php ├── ControlStructures ├── ElseIfUnitTest.inc ├── ElseIfUnitTest.php ├── SingleLineIfUnitTest.inc ├── SingleLineIfUnitTest.php ├── SwitchUnitTest.inc └── SwitchUnitTest.php ├── Functions ├── RegularExpressionUnitTest.inc └── RegularExpressionUnitTest.php ├── NamingConventions ├── ValidFunctionNameUnitTest.inc ├── ValidFunctionNameUnitTest.php ├── ValidVariableNameUnitTest.inc └── ValidVariableNameUnitTest.php ├── Operators ├── ComparisonOperatorUnitTest.inc ├── ComparisonOperatorUnitTest.php ├── TernaryOperatorUnitTest.inc ├── TernaryOperatorUnitTest.php ├── TypeCastingUnitTest.inc └── TypeCastingUnitTest.php └── WhiteSpace ├── NoConcatenationSpaceUnitTest.inc ├── NoConcatenationSpaceUnitTest.php ├── ParenthesesUnitTest.inc └── ParenthesesUnitTest.php /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | *.swo 3 | *.tgz 4 | package.xml 5 | -------------------------------------------------------------------------------- /Kohana/KohanaCodingStandard.php: -------------------------------------------------------------------------------- 1 | 10 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 11 | * @version CVS: $Id$ 12 | * @link http://pear.php.net/package/PHP_CodeSniffer 13 | */ 14 | 15 | if (class_exists('PHP_CodeSniffer_Standards_CodingStandard', true) === false) { 16 | throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_Standards_CodingStandard not found'); 17 | } 18 | 19 | /** 20 | * Kohana Coding Standard. 21 | * 22 | * @category PHP 23 | * @package PHP_CodeSniffer 24 | * @author Matthew Turland 25 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 26 | * @version Release: @release_version@ 27 | * @link http://pear.php.net/package/PHP_CodeSniffer 28 | */ 29 | class PHP_CodeSniffer_Standards_Kohana_KohanaCodingStandard extends PHP_CodeSniffer_Standards_CodingStandard 30 | { 31 | /** 32 | * Return a list of external sniffs to include with this standard. 33 | * 34 | * The PEAR standard uses some generic sniffs. 35 | * 36 | * @return array 37 | */ 38 | public function getIncludedSniffs() 39 | { 40 | return array( 41 | 'Generic/Sniffs/Functions/OpeningFunctionBraceBsdAllmanSniff.php', 42 | 'Generic/Sniffs/NamingConventions/UpperCaseConstantNameSniff.php' 43 | ); 44 | } 45 | } 46 | 47 | ?> 48 | -------------------------------------------------------------------------------- /Kohana/Sniffs/Classes/EmptyConstructorCallSniff.php: -------------------------------------------------------------------------------- 1 | 10 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 11 | * @version CVS: $Id$ 12 | * @link http://pear.php.net/package/PHP_CodeSniffer 13 | */ 14 | 15 | /** 16 | * This sniff prohibits the use of parentheses for constructor calls that 17 | * do not accept parameters. 18 | * 19 | * @category PHP 20 | * @package PHP_CodeSniffer 21 | * @author Matthew Turland 22 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 23 | * @version Release: @package_version@ 24 | * @link http://pear.php.net/package/PHP_CodeSniffer 25 | */ 26 | class Kohana_Sniffs_Classes_EmptyConstructorCallSniff implements PHP_CodeSniffer_Sniff 27 | { 28 | /** 29 | * Returns the token types that this sniff is interested in. 30 | * 31 | * @return array(int) 32 | */ 33 | public function register() 34 | { 35 | return array( 36 | T_NEW 37 | ); 38 | } 39 | 40 | /** 41 | * Processes the tokens that this sniff is interested in. 42 | * 43 | * @param PHP_CodeSniffer_File $phpcsFile File where the token was found 44 | * @param int $stackPtr Position in the stack where the token was found 45 | * @return void 46 | */ 47 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) 48 | { 49 | $open = $phpcsFile->findNext( 50 | T_OPEN_PARENTHESIS, 51 | $stackPtr, 52 | null, 53 | false, 54 | null, 55 | true 56 | ); 57 | 58 | if ($open !== false 59 | && $phpcsFile->getTokensAsString($open, 2) == '()') { 60 | $phpcsFile->addError( 61 | 'Parentheses should not be used in calls to class constructors without parameters', 62 | $stackPtr 63 | ); 64 | } 65 | } 66 | } 67 | 68 | ?> 69 | -------------------------------------------------------------------------------- /Kohana/Sniffs/Commenting/DocBlockParamSniff.php: -------------------------------------------------------------------------------- 1 | getTokens(); 24 | $content = $tokens[$stackPtr]['content']; 25 | 26 | // Capture text after '@param' 27 | if (preg_match('/^\s+\*\s+@param\s+(.*)$/', $content, $matches)) 28 | { 29 | if ( ! preg_match('/^\S+\s+\$\S/', $matches[1])) 30 | { 31 | // Second "word" (non-whitespace) does not start with $ 32 | $phpcsFile->addWarning('@param tag should have the parameter name', $stackPtr); 33 | } 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Kohana/Sniffs/Commenting/DocBlockSeeSniff.php: -------------------------------------------------------------------------------- 1 | getTokens(); 24 | $content = $tokens[$stackPtr]['content']; 25 | 26 | if (preg_match('#^\s+\*\s+@see\s+\S+://#', $content)) 27 | { 28 | // Text after '@see' has a scheme, a colon and two slashes 29 | $phpcsFile->addWarning('@see tag should refer to code; use @link for hyperlinks', $stackPtr); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Kohana/Sniffs/Commenting/OneLineCommentSniff.php: -------------------------------------------------------------------------------- 1 | 10 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 11 | * @version CVS: $Id$ 12 | * @link http://pear.php.net/package/PHP_CodeSniffer 13 | */ 14 | 15 | /** 16 | * This sniff prohibits the use of parentheses for constructor calls that 17 | * do not accept parameters. 18 | * 19 | * @category PHP 20 | * @package PHP_CodeSniffer 21 | * @author Matthew Turland 22 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 23 | * @version Release: @package_version@ 24 | * @link http://pear.php.net/package/PHP_CodeSniffer 25 | */ 26 | class Kohana_Sniffs_Commenting_OneLineCommentSniff implements PHP_CodeSniffer_Sniff 27 | { 28 | /** 29 | * Returns an array of tokens this test wants to listen for. 30 | * 31 | * @return array 32 | */ 33 | public function register() 34 | { 35 | return array( 36 | T_COMMENT 37 | ); 38 | } 39 | 40 | /** 41 | * Processes this test, when one of its tokens is encountered. 42 | * 43 | * @param PHP_CodeSniffer_File $phpcsFile File being scanned 44 | * @param int $stackPtr Position of the current token in the stack 45 | * passed in $tokens. 46 | * @return void 47 | */ 48 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) 49 | { 50 | $tokens = $phpcsFile->getTokens(); 51 | $content = $tokens[$stackPtr]['content']; 52 | 53 | if (preg_match('/^\s*(?:\/\/[^ ]|#)/', $content)) { 54 | $error = 'Single-line comments must begin with "// " (e.g. // My comment)'; 55 | $phpcsFile->addError($error, $stackPtr); 56 | } 57 | } 58 | } 59 | 60 | ?> 61 | -------------------------------------------------------------------------------- /Kohana/Sniffs/ControlStructures/ElseIfSniff.php: -------------------------------------------------------------------------------- 1 | 10 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 11 | * @version CVS: $Id$ 12 | * @link http://pear.php.net/package/PHP_CodeSniffer 13 | */ 14 | 15 | /** 16 | * Throws errors if "else if" is used rather than "elseif." 17 | * 18 | * @category PHP 19 | * @package PHP_CodeSniffer 20 | * @author Matthew Turland 21 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 22 | * @version Release: @release_version@ 23 | * @link http://pear.php.net/package/PHP_CodeSniffer 24 | */ 25 | class Kohana_Sniffs_ControlStructures_ElseIfSniff implements PHP_CodeSniffer_Sniff 26 | { 27 | /** 28 | * Returns an array of tokens this test wants to listen for. 29 | * 30 | * @return array 31 | */ 32 | public function register() 33 | { 34 | return array( 35 | T_ELSE 36 | ); 37 | } 38 | 39 | /** 40 | * Processes this test, when one of its tokens is encountered. 41 | * 42 | * @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the 43 | * document 44 | * @param int $stackPtr Position of the current token in the stack passed 45 | * in $tokens 46 | * @return void 47 | */ 48 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) 49 | { 50 | $tokens = $phpcsFile->getTokens(); 51 | $tokenPtr = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, null, true); 52 | 53 | if ($tokens[$tokenPtr]['type'] == 'T_IF') { 54 | $error = 'elseif should be used rather than else if'; 55 | $phpcsFile->addError($error, $stackPtr); 56 | } 57 | } 58 | } 59 | 60 | ?> 61 | -------------------------------------------------------------------------------- /Kohana/Sniffs/ControlStructures/SingleLineIfSniff.php: -------------------------------------------------------------------------------- 1 | 10 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 11 | * @version CVS: $Id$ 12 | * @link http://pear.php.net/package/PHP_CodeSniffer 13 | */ 14 | 15 | /** 16 | * Throws errors if single-line if statements are used for anything that 17 | * does not break normal execution. 18 | * 19 | * @category PHP 20 | * @package PHP_CodeSniffer 21 | * @author Matthew Turland 22 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 23 | * @version Release: @release_version@ 24 | * @link http://pear.php.net/package/PHP_CodeSniffer 25 | */ 26 | class Kohana_Sniffs_ControlStructures_SingleLineIfSniff implements PHP_CodeSniffer_Sniff 27 | { 28 | /** 29 | * Returns an array of tokens this test wants to listen for. 30 | * 31 | * @return array 32 | */ 33 | public function register() 34 | { 35 | return array( 36 | T_IF 37 | ); 38 | } 39 | 40 | /** 41 | * Processes this test, when one of its tokens is encountered. 42 | * 43 | * @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the 44 | * document 45 | * @param int $stackPtr Position of the current token in the stack passed 46 | * in $tokens 47 | * @return void 48 | */ 49 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) 50 | { 51 | $tokens = $phpcsFile->getTokens(); 52 | 53 | // Shift the stack pointer past the if condition 54 | $tokenPtr = $phpcsFile->findNext(T_OPEN_PARENTHESIS, $stackPtr); 55 | $tokenPtr = $tokens[$tokenPtr]['parenthesis_closer']; 56 | 57 | // Find the first non-whitespace token following the if condition 58 | $tokenPtr = $phpcsFile->findNext(T_WHITESPACE, $tokenPtr + 1, null, true); 59 | 60 | switch ($tokens[$tokenPtr]['type']) { 61 | // Ignore branches that are not single-line 62 | case 'T_COLON': 63 | case 'T_OPEN_CURLY_BRACKET': 64 | 65 | // Ignore branches that break normal execution 66 | case 'T_RETURN': 67 | case 'T_CONTINUE': 68 | case 'T_BREAK': 69 | case 'T_THROW': 70 | case 'T_EXIT': 71 | return; 72 | 73 | // Generate an error for all other branches 74 | default: 75 | $error = 'Single-line if statements should only be used when breaking normal execution'; 76 | $phpcsFile->addError($error, $stackPtr); 77 | } 78 | } 79 | } 80 | 81 | ?> 82 | -------------------------------------------------------------------------------- /Kohana/Sniffs/ControlStructures/SwitchSniff.php: -------------------------------------------------------------------------------- 1 | 10 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 11 | * @version CVS: $Id$ 12 | * @link http://pear.php.net/package/PHP_CodeSniffer 13 | */ 14 | 15 | /** 16 | * Throws errors if switch structures do not conform to the coding standard. 17 | * 18 | * @category PHP 19 | * @package PHP_CodeSniffer 20 | * @author Matthew Turland 21 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 22 | * @version Release: @release_version@ 23 | * @link http://pear.php.net/package/PHP_CodeSniffer 24 | */ 25 | class Kohana_Sniffs_ControlStructures_SwitchSniff implements PHP_CodeSniffer_Sniff 26 | { 27 | /** 28 | * Returns an array of tokens this test wants to listen for. 29 | * 30 | * @return array 31 | */ 32 | public function register() 33 | { 34 | return array( 35 | T_CASE, 36 | T_DEFAULT, 37 | T_BREAK 38 | ); 39 | } 40 | 41 | /** 42 | * Processes this test, when one of its tokens is encountered. 43 | * 44 | * @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the 45 | * document 46 | * @param int $stackPtr Position of the current token in the stack passed 47 | * in $tokens 48 | * @return void 49 | */ 50 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) 51 | { 52 | $tokens = $phpcsFile->getTokens(); 53 | $line = $tokens[$stackPtr]['line']; 54 | $tokenCount = $phpcsFile->numTokens - 1; 55 | 56 | // Each case, break, and default should be on a separate line 57 | $start = $end = $stackPtr; 58 | while ($tokens[$start]['line'] == $line && $start > 0) { 59 | $start--; 60 | } 61 | while ($tokens[$end]['line'] == $line && $end < $tokenCount) { 62 | $end++; 63 | } 64 | 65 | $lineTokens = array_slice($tokens, $start, $end - $start + 1, true); 66 | foreach ($lineTokens as $tokenPtr => $token) { 67 | switch ($token['type']) { 68 | case 'T_CASE': 69 | case 'T_DEFAULT': 70 | case 'T_BREAK': 71 | if ($tokenPtr > $stackPtr) { 72 | $error = 'Each case, break, and default should be on a separate line'; 73 | $phpcsFile->addError($error, $stackPtr); 74 | } 75 | } 76 | } 77 | 78 | if ($tokens[$stackPtr]['type'] == 'T_BREAK') { 79 | return; 80 | } 81 | 82 | // In this context the scope opener is either a colon or semicolon 83 | $stackPtrScopeOpener = $tokens[$stackPtr]['scope_opener']; 84 | 85 | // Account for typos using ; instead of : on case lines 86 | if ($tokens[$stackPtrScopeOpener]['type'] === 'T_SEMICOLON') { 87 | $error = 'Potential use of ; instead of : on a case line'; 88 | $phpcsFile->addWarning($error, $stackPtr); 89 | return; 90 | } 91 | 92 | // Code inside case and default blocks should be indented 93 | for ( 94 | $open = $tokens[$stackPtr]['scope_opener']; 95 | $tokens[$open]['line'] == $line; 96 | $open++ 97 | ); 98 | 99 | for ( 100 | $close = $tokens[$stackPtr]['scope_closer']; 101 | $tokens[$close]['line'] == $tokens[$close + 1]['line']; 102 | $close-- 103 | ); 104 | 105 | $indent = $phpcsFile->getTokensAsString($start, $stackPtr - $start); 106 | $tabCount = substr_count($indent, "\t") + 1; 107 | $tabString = str_repeat("\t", $tabCount); 108 | 109 | foreach (range($open, $close) as $tokenPtr) { 110 | 111 | // The first condition checks that we're on a new line (so we can check the indent) 112 | // The second checks to see if there is sufficient indent 113 | if ($tokens[$tokenPtr]['line'] == $tokens[$tokenPtr - 1]['line'] + 1 114 | && substr($tokens[$tokenPtr]['content'], 0, $tabCount) != $tabString) { 115 | 116 | // Empty lines are exempt from the indentation rule 117 | $empty_line = TRUE; 118 | 119 | // We now need to have a look along the line and see if there're any case / default 120 | // tags in case we're allowing conditions to drop through 121 | for ( 122 | $localTokenPtr = $tokenPtr; 123 | $tokens[$localTokenPtr]['line'] === $tokens[$localTokenPtr + 1]['line']; 124 | $localTokenPtr++ 125 | ) { 126 | // If there's a break or default tag on this line then we need to move onto the next line 127 | if(in_array($tokens[$localTokenPtr]['type'], array('T_CASE', 'T_DEFAULT'))) { 128 | continue 2; 129 | } 130 | 131 | if($tokens[$localTokenPtr]['type'] !== 'T_WHITESPACE') 132 | { 133 | $empty_line = FALSE; 134 | } 135 | } 136 | 137 | // Empty lines are exempt from the indentation rules 138 | if( ! $empty_line) 139 | { 140 | $phpcsFile->addError('Code inside case and default blocks should be indented', $tokenPtr); 141 | } 142 | } 143 | } 144 | } 145 | } 146 | 147 | ?> 148 | -------------------------------------------------------------------------------- /Kohana/Sniffs/Functions/RegularExpressionSniff.php: -------------------------------------------------------------------------------- 1 | 10 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 11 | * @version CVS: $Id$ 12 | * @link http://pear.php.net/package/PHP_CodeSniffer 13 | */ 14 | 15 | /** 16 | * Throws errors if ternary expressions use parentheses improperly or exceed 17 | * 80 characters in length on a single line. 18 | * 19 | * @category PHP 20 | * @package PHP_CodeSniffer 21 | * @author Matthew Turland 22 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 23 | * @version Release: @release_version@ 24 | * @link http://pear.php.net/package/PHP_CodeSniffer 25 | */ 26 | class Kohana_Sniffs_Functions_RegularExpressionSniff implements PHP_CodeSniffer_Sniff 27 | { 28 | /** 29 | * Returns an array of tokens this test wants to listen for. 30 | * 31 | * @return array 32 | */ 33 | public function register() 34 | { 35 | return array( 36 | T_STRING 37 | ); 38 | } 39 | 40 | /** 41 | * Processes this test, when one of its tokens is encountered. 42 | * 43 | * @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the 44 | * document 45 | * @param int $stackPtr Position of the current token in the stack passed 46 | * in $tokens 47 | * @return void 48 | */ 49 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) 50 | { 51 | $tokens = $phpcsFile->getTokens(); 52 | 53 | // Is this a function call? 54 | $prevPtr = $phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, null, true); 55 | $nextPtr = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, null, true); 56 | if ($tokens[$prevPtr]['type'] != 'T_FUNCTION' 57 | && $tokens[$nextPtr]['type'] == 'T_OPEN_PARENTHESIS') { 58 | 59 | // Is this a POSIX function? 60 | if (preg_match('/^(ereg|spliti?|sql_regcase)$/', $tokens[$stackPtr]['content'])) { 61 | $error = 'PCRE (preg) functions are preferred over POSIX (ereg) functions'; 62 | $phpcsFile->addError($error, $stackPtr); 63 | 64 | // Is this a PCRE function? 65 | } elseif (strpos($tokens[$stackPtr]['content'], 'preg') === 0) { 66 | 67 | // Is the regular expression surrounded by single quotes? 68 | $nextPtr = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, $nextPtr + 1); 69 | $content = $tokens[$nextPtr]['content']; 70 | if (substr($content, 0, 1) == '"') { 71 | $error = 'Regular expressions must be surrounded by single quotes'; 72 | $phpcsFile->addError($error, $stackPtr); 73 | } 74 | 75 | // Does the regular expression have a EOL hole? 76 | if (preg_match('/\$\/[^D]*$/', $content)) { 77 | $error = 'Regular expression may have an EOL hole and need /D modifier'; 78 | $phpcsFile->addWarning($error, $stackPtr); 79 | } 80 | 81 | // Is this function preg_replace? 82 | if ($tokens[$stackPtr]['content'] != 'preg_replace') { 83 | return; 84 | } 85 | 86 | // Is the replacement surrounded by single quotes? 87 | // In some cases this functionality is required, hence this is a warning 88 | $nextPtr = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, $nextPtr + 1); 89 | $content = $tokens[$nextPtr]['content']; 90 | if (substr($content, 0, 1) == '"') { 91 | $error = 'It is recommended that regular expression replacements are surrounded by single quotes'; 92 | $phpcsFile->addWarning($error, $stackPtr); 93 | } 94 | 95 | // Is the replacement using the $n notation for backreferences? 96 | if (preg_match('/\\\\[0-9]+/', $content)) { 97 | $error = 'Backreferences in regular expressions must use $n notation rather than \\n notation'; 98 | $phpcsFile->addError($error, $stackPtr); 99 | } 100 | } 101 | } 102 | } 103 | } 104 | 105 | ?> 106 | -------------------------------------------------------------------------------- /Kohana/Sniffs/NamingConventions/UpperCaseConstantNameSniff.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Marc McIntyre 11 | * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600) 12 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 13 | * @version CVS: $Id: UpperCaseConstantNameSniff.php 291908 2009-12-09 03:56:09Z squiz $ 14 | * @link http://pear.php.net/package/PHP_CodeSniffer 15 | */ 16 | 17 | /** 18 | * Kohana_Sniffs_NamingConventions_UpperCaseConstantNameSniff. 19 | * 20 | * Ensures that constant names are all uppercase. 21 | * 22 | * @category PHP 23 | * @package PHP_CodeSniffer 24 | * @author Greg Sherwood 25 | * @author Marc McIntyre 26 | * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600) 27 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 28 | * @version Release: 1.2.2 29 | * @link http://pear.php.net/package/PHP_CodeSniffer 30 | */ 31 | class Kohana_Sniffs_NamingConventions_UpperCaseConstantNameSniff extends Generic_Sniffs_NamingConventions_UpperCaseConstantNameSniff 32 | { 33 | 34 | 35 | /** 36 | * Returns an array of tokens this test wants to listen for. 37 | * 38 | * @return array 39 | */ 40 | public function register() 41 | { 42 | return array( 43 | T_STRING, 44 | T_TRUE, 45 | T_FALSE, 46 | T_NULL, 47 | T_LOGICAL_AND, 48 | T_LOGICAL_OR, 49 | T_LOGICAL_XOR 50 | ); 51 | 52 | }//end register() 53 | 54 | }//end class 55 | 56 | ?> 57 | -------------------------------------------------------------------------------- /Kohana/Sniffs/NamingConventions/ValidFunctionNameSniff.php: -------------------------------------------------------------------------------- 1 | 10 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 11 | * @version CVS: $Id$ 12 | * @link http://pear.php.net/package/PHP_CodeSniffer 13 | */ 14 | 15 | if (class_exists('PEAR_Sniffs_NamingConventions_ValidFunctionNameSniff', true) === false) { 16 | throw new PHP_CodeSniffer_Exception('Class PEAR_Sniffs_NamingConventions_ValidFunctionNameSniff not found'); 17 | } 18 | 19 | /** 20 | * Ensures methods and functions are named correctly. 21 | * 22 | * @category PHP 23 | * @package PHP_CodeSniffer 24 | * @author Matthew Turland 25 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 26 | * @version Release: @release_version@ 27 | * @link http://pear.php.net/package/PHP_CodeSniffer 28 | */ 29 | class Kohana_Sniffs_NamingConventions_ValidFunctionNameSniff extends PHP_CodeSniffer_Standards_AbstractScopeSniff 30 | { 31 | // Copied from the base class because it's declared as private there 32 | protected $_magicMethods = array( 33 | 'construct', 34 | 'destruct', 35 | 'call', 36 | 'callStatic', 37 | 'get', 38 | 'set', 39 | 'isset', 40 | 'unset', 41 | 'sleep', 42 | 'wakeup', 43 | 'toString', 44 | 'set_state', 45 | 'clone', 46 | ); 47 | 48 | // Copied from the base class because it's declared as private there 49 | protected $_magicFunctions = array( 50 | 'autoload', 51 | ); 52 | 53 | /** 54 | * Constructor. 55 | * 56 | * @return void 57 | */ 58 | public function __construct() 59 | { 60 | parent::__construct(array(T_CLASS, T_INTERFACE), array(T_FUNCTION), true); 61 | } 62 | 63 | /** 64 | * Supporting method to validate a function or method name. 65 | * 66 | * @param string $name Name of the function or method to validate 67 | * @return bool TRUE if the function or method name is valid, FALSE 68 | * otherwise 69 | */ 70 | protected function isInvalidName($name) 71 | { 72 | return !preg_match('#^(?:__)?(?:(?:[a-z_\x7f-\xff][a-z0-9_\x7f-\xff]*)|toString)$#', $name); 73 | } 74 | 75 | /** 76 | * Processes the tokens within the scope. 77 | * 78 | * @param PHP_CodeSniffer_File $phpcsFile File being processed 79 | * @param int $stackPtr Position where this token was found 80 | * @param int $currScope Position of the current scope 81 | * 82 | * @return void 83 | */ 84 | protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope) 85 | { 86 | $className = $phpcsFile->getDeclarationName($currScope); 87 | $methodName = $phpcsFile->getDeclarationName($stackPtr); 88 | 89 | // Ignore anonymous functions used within a class 90 | if ( ! $methodName) 91 | return; 92 | 93 | // Ignore magic methods 94 | if (substr($methodName, 0, 2) == '__') { 95 | $magicPart = substr($methodName, 2); 96 | if (in_array($magicPart, $this->_magicMethods) === false) { 97 | $error = 'Method name "' . $className . '::' . $methodName . '" is invalid; only PHP magic methods should be prefixed with a double underscore'; 98 | $phpcsFile->addError($error, $stackPtr); 99 | } 100 | return; 101 | } 102 | 103 | // Ignore Iterator methods 104 | if (preg_match('/^offset(?:Get|Set|Exists|Unset)$/', $methodName)) { 105 | return; 106 | } 107 | 108 | // Evaluate all other functions and methods 109 | if ($this->isInvalidName($methodName)) { 110 | $error = 'Method name "' . $methodName . '" is not in all lowercase using underscores for word separators'; 111 | $phpcsFile->addError($error, $stackPtr); 112 | } 113 | } 114 | 115 | /** 116 | * Processes the tokens outside the scope. 117 | * 118 | * @param PHP_CodeSniffer_File $phpcsFile File being processed 119 | * @param int $stackPtr Position where this token was found 120 | * @return void 121 | */ 122 | protected function processTokenOutsideScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr) 123 | { 124 | $functionName = $phpcsFile->getDeclarationName($stackPtr); 125 | 126 | // Ignore anonymous functions 127 | if ( ! $functionName) 128 | return; 129 | 130 | // Ignore magic functions 131 | if (substr($functionName, 0, 2) == '__') { 132 | if (in_array(substr($functionName, 2), $this->_magicFunctions) === false) { 133 | $error = "Function name \"$functionName\" is invalid; only PHP magic functions should be prefixed with a double underscore"; 134 | $phpcsFile->addError($error, $stackPtr); 135 | } 136 | return; 137 | } 138 | 139 | // Ignore internal functions 140 | $functions = get_defined_functions(); 141 | $functions = $functions['internal']; 142 | if (in_array($functionName, $functions)) { 143 | return; 144 | } 145 | 146 | // Evaluate all other functions and methods 147 | if ($this->isInvalidName($functionName)) { 148 | $error = 'Function name "' . $functionName . '" is not in all lowercase using underscores for word separators'; 149 | $phpcsFile->addError($error, $stackPtr); 150 | } 151 | } 152 | } 153 | 154 | ?> 155 | -------------------------------------------------------------------------------- /Kohana/Sniffs/NamingConventions/ValidVariableNameSniff.php: -------------------------------------------------------------------------------- 1 | 10 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 11 | * @version CVS: $Id$ 12 | * @link http://pear.php.net/package/PHP_CodeSniffer 13 | */ 14 | 15 | if (class_exists('PHP_CodeSniffer_Standards_AbstractVariableSniff', true) === false) { 16 | $error = 'Class PHP_CodeSniffer_Standards_AbstractVariableSniff not found'; 17 | throw new PHP_CodeSniffer_Exception($error); 18 | } 19 | 20 | /** 21 | * Checks the naming of variables. 22 | * 23 | * @category PHP 24 | * @package PHP_CodeSniffer 25 | * @author Matthew Turland 26 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 27 | * @version Release: @release_version@ 28 | * @link http://pear.php.net/package/PHP_CodeSniffer 29 | */ 30 | class Kohana_Sniffs_NamingConventions_ValidVariableNameSniff extends PHP_CodeSniffer_Standards_AbstractVariableSniff 31 | { 32 | /** 33 | * Supporting method to validate variable names. 34 | * 35 | * @param PHP_CodeSniffer_File $phpcsFile File being scanned 36 | * @param int $stackPtr Position of the current token in the stack 37 | * passed in $tokens 38 | * @return bool TRUE if the variable name is valid, FALSE otherwise 39 | */ 40 | private function validateName(PHP_CodeSniffer_File $phpcsFile, $stackPtr) 41 | { 42 | $tokens = $phpcsFile->getTokens(); 43 | $variable = ltrim($tokens[$stackPtr]['content'], '$'); 44 | 45 | // If the variable name is dynamic, just ignore it 46 | if (preg_match('/^\{.*\}$/', $variable)) { 47 | return; 48 | } 49 | 50 | if (!preg_match('#^(?:GLOBALS|_(?:SERVER|GET|POST|FILES|COOKIE|SESSION|REQUEST|ENV)|(?:[a-z_\x7f-\xff][a-z0-9_\x7f-\xff]*))$#', $variable)) { 51 | $phpcsFile->addError('Variable name $' . $variable . ' is not in all lowercase using underscores for word separators', $stackPtr); 52 | } 53 | } 54 | 55 | /** 56 | * Processes class member variables. 57 | * 58 | * @param PHP_CodeSniffer_File $phpcsFile File being scanned 59 | * @param int $stackPtr Position of the current token in the stack 60 | * passed in $tokens 61 | * @return void 62 | */ 63 | protected function processMemberVar(PHP_CodeSniffer_File $phpcsFile, $stackPtr) 64 | { 65 | $this->validateName($phpcsFile, $stackPtr); 66 | } 67 | 68 | /** 69 | * Processes normal variables. 70 | * 71 | * @param PHP_CodeSniffer_File $phpcsFile File where this token was found 72 | * @param int $stackPtr Position where the token was found 73 | * @return void 74 | */ 75 | protected function processVariable(PHP_CodeSniffer_File $phpcsFile, $stackPtr) 76 | { 77 | $this->validateName($phpcsFile, $stackPtr); 78 | } 79 | 80 | /** 81 | * Processes interpolated variables in double quoted strings. 82 | * 83 | * @param PHP_CodeSniffer_File $phpcsFile File where this token was found 84 | * @param int $stackPtr Position where the token was found 85 | * @return void 86 | */ 87 | protected function processVariableInString(PHP_CodeSniffer_File $phpcsFile, $stackPtr) 88 | { 89 | // Ignore these 90 | return; 91 | } 92 | } 93 | 94 | ?> 95 | -------------------------------------------------------------------------------- /Kohana/Sniffs/Operators/ComparisonOperatorSniff.php: -------------------------------------------------------------------------------- 1 | 10 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 11 | * @version CVS: $Id$ 12 | * @link http://pear.php.net/package/PHP_CodeSniffer 13 | */ 14 | 15 | /** 16 | * Throws errors if boolean comparison operators are used rather than 17 | * logical ones. 18 | * 19 | * @category PHP 20 | * @package PHP_CodeSniffer 21 | * @author Matthew Turland 22 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 23 | * @version Release: @release_version@ 24 | * @link http://pear.php.net/package/PHP_CodeSniffer 25 | */ 26 | class Kohana_Sniffs_Operators_ComparisonOperatorSniff implements PHP_CodeSniffer_Sniff 27 | { 28 | /** 29 | * Returns an array of tokens this test wants to listen for. 30 | * 31 | * @return array 32 | */ 33 | public function register() 34 | { 35 | return array( 36 | T_BOOLEAN_AND, 37 | T_BOOLEAN_OR, 38 | T_IS_GREATER_OR_EQUAL, 39 | T_IS_SMALLER_OR_EQUAL, 40 | T_IS_EQUAL, 41 | T_IS_NOT_EQUAL, 42 | T_IS_IDENTICAL, 43 | T_IS_NOT_IDENTICAL, 44 | T_IS_NOT_EQUAL, 45 | T_GREATER_THAN, 46 | T_LESS_THAN 47 | ); 48 | } 49 | 50 | /** 51 | * Processes this test, when one of its tokens is encountered. 52 | * 53 | * @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the 54 | * document 55 | * @param int $stackPtr Position of the current token in the stack passed 56 | * in $tokens 57 | * @return void 58 | */ 59 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) 60 | { 61 | $tokens = $phpcsFile->getTokens(); 62 | 63 | switch ($tokens[$stackPtr]['type']) { 64 | case 'T_BOOLEAN_AND': 65 | case 'T_BOOLEAN_OR': 66 | $error = 'Operators && and || are not allowed, use AND and OR instead'; 67 | $phpcsFile->addError($error, $stackPtr); 68 | break; 69 | 70 | default: 71 | $beforePtr = $phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, null, true); 72 | $afterPtr = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, null, true); 73 | if ($tokens[$afterPtr]['type'] == 'T_VARIABLE') { 74 | switch ($tokens[$beforePtr]['type']) { 75 | case 'T_STRING': 76 | $beforePtr = $phpcsFile->findPrevious(T_WHITESPACE, $beforePtr - 1, null, true); 77 | if ($tokens[$beforePtr]['type'] == 'T_OBJECT_OPERATOR') { 78 | break; 79 | } 80 | case 'T_FALSE': 81 | case 'T_TRUE': 82 | case 'T_NULL': 83 | $error = 'Variables should precede constants in comparison operations'; 84 | $phpcsFile->addError($error, $stackPtr); 85 | break; 86 | } 87 | } 88 | break; 89 | } 90 | } 91 | } 92 | 93 | ?> 94 | -------------------------------------------------------------------------------- /Kohana/Sniffs/Operators/TernaryOperatorSniff.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Chris Bandy 11 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 12 | * @link http://pear.php.net/package/PHP_CodeSniffer 13 | */ 14 | 15 | /** 16 | * Logs an error when a ternary operation is not in parentheses. Operands must also be in 17 | * parentheses unless it is a single variable, array access, object access or function call. 18 | * 19 | * @category PHP 20 | * @package PHP_CodeSniffer 21 | * @author Matthew Turland 22 | * @author Chris Bandy 23 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 24 | * @link http://pear.php.net/package/PHP_CodeSniffer 25 | */ 26 | class Kohana_Sniffs_Operators_TernaryOperatorSniff implements PHP_CodeSniffer_Sniff 27 | { 28 | /** 29 | * Returns an array of tokens this test wants to listen for. 30 | * 31 | * @return array 32 | */ 33 | public function register() 34 | { 35 | return array( 36 | T_INLINE_THEN 37 | ); 38 | } 39 | 40 | /** 41 | * Processes this test, when one of its tokens is encountered. 42 | * 43 | * @param PHP_CodeSniffer_File $phpcsFile 44 | * @param int $stackPtr Position of the current token in the stack 45 | * @return void 46 | */ 47 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) 48 | { 49 | $tokens = $phpcsFile->getTokens(); 50 | 51 | if (empty($tokens[$stackPtr]['nested_parenthesis'])) 52 | { 53 | $allowed = array( 54 | T_EQUAL, 55 | T_RETURN, 56 | T_ECHO, 57 | T_AND_EQUAL, 58 | T_CONCAT_EQUAL, 59 | T_DIV_EQUAL, 60 | T_MINUS_EQUAL, 61 | T_MOD_EQUAL, 62 | T_MUL_EQUAL, 63 | T_OR_EQUAL, 64 | T_PLUS_EQUAL, 65 | T_SL_EQUAL, 66 | T_SR_EQUAL, 67 | T_XOR_EQUAL, 68 | 69 | // To detect end of previous statement 70 | T_SEMICOLON, 71 | ); 72 | 73 | $startPtr = $this->_find_previous($allowed, $tokens, $stackPtr - 1, 0, NULL); 74 | $endPtr = $phpcsFile->findNext(array(T_CLOSE_TAG, T_SEMICOLON), $stackPtr + 1); 75 | 76 | if ($tokens[$startPtr]['code'] === T_SEMICOLON) 77 | { 78 | $error = 'Ternary operation must occur within assignment, echo or return statement'; 79 | $phpcsFile->addError($error, $stackPtr, 'TernaryStart'); 80 | } 81 | 82 | $colonPtr = $this->_find_next(T_COLON, $tokens, $stackPtr + 1, $endPtr, NULL); 83 | } 84 | else 85 | { 86 | // Inside an array or function call 87 | $endPtr = end($tokens[$stackPtr]['nested_parenthesis']); 88 | $startPtr = key($tokens[$stackPtr]['nested_parenthesis']); 89 | 90 | if ($comma = $this->_find_previous(array(T_COMMA, T_DOUBLE_ARROW), $tokens, $stackPtr - 1, $startPtr, $startPtr)) 91 | { 92 | $startPtr = $comma; 93 | } 94 | 95 | $colonPtr = $this->_find_next(T_COLON, $tokens, $stackPtr + 1, $endPtr, $endPtr); 96 | 97 | if ($comma = $this->_find_next(T_COMMA, $tokens, $colonPtr + 1, $endPtr, $endPtr)) 98 | { 99 | $endPtr = $comma; 100 | } 101 | } 102 | 103 | if ($tokens[$startPtr]['line'] < $tokens[$stackPtr]['line'] - 1) 104 | { 105 | $error = 'Ternary operator must appear on the same or following line of its condition'; 106 | $phpcsFile->addError($error, $stackPtr, 'TernaryLine'); 107 | } 108 | 109 | if ($tokens[$colonPtr]['line'] > $tokens[$stackPtr]['line'] + 1) 110 | { 111 | $error = 'Colon must appear on the same or following line of its ternary operator'; 112 | $phpcsFile->addError($error, $stackPtr, 'TernaryColonLine'); 113 | } 114 | 115 | $this->_evaluate_portion($phpcsFile, 'condition', $startPtr + 1, $stackPtr - 1); 116 | $this->_evaluate_portion($phpcsFile, 'true value', $stackPtr + 1, $colonPtr - 1); 117 | $this->_evaluate_portion($phpcsFile, 'false value', $colonPtr + 1, $endPtr - 1); 118 | } 119 | 120 | /** 121 | * Verifies one operand of a ternary operation follows Kohana coding standards 122 | * 123 | * @param PHP_CodeSniffer_Sniff $file 124 | * @param string $name Portion being evaluated. Used in error messages. 125 | * @param integer $start Index of the first token in the portion 126 | * @param integer $end Index of the last token in the portion 127 | * @return void 128 | */ 129 | protected function _evaluate_portion(PHP_CodeSniffer_File $file, $name, $start, $end) 130 | { 131 | // Skip any whitespace or casts 132 | $current = $file->findNext(array( 133 | T_WHITESPACE, 134 | T_ARRAY_CAST, 135 | T_BOOL_CAST, 136 | T_DOUBLE_CAST, 137 | T_INT_CAST, 138 | T_OBJECT_CAST, 139 | T_STRING_CAST, 140 | T_UNSET_CAST, 141 | ), $start, $end, TRUE); 142 | 143 | // Trim any trailing whitespace 144 | $end = $file->findPrevious(T_WHITESPACE, $end, $current, TRUE); 145 | 146 | $tokens = $file->getTokens(); 147 | $is_static_call = FALSE; 148 | 149 | if ($tokens[$current]['code'] === T_OPEN_PARENTHESIS) 150 | { 151 | // Skip any variables or whitespace 152 | $next = $file->findNext(array(T_VARIABLE, T_WHITESPACE), $current + 1, NULL, TRUE); 153 | 154 | if ($tokens[$next]['code'] === T_CLOSE_PARENTHESIS) 155 | { 156 | $error = 'A single variable should not have parenthesis in the '.$name.' portion of ternary operations'; 157 | $file->addError($error, $current, 'TernaryParenthesizedVariable'); 158 | } 159 | } 160 | else 161 | { 162 | $next = $file->findNext(T_WHITESPACE, $current + 1, $end, TRUE); 163 | 164 | if ($tokens[$current]['code'] === T_STRING AND $tokens[$next]['code'] === T_DOUBLE_COLON) 165 | { 166 | // Static access 167 | $current = $this->_find_next_invokation_or_access($current, $next, $tokens, $end, $name, $file); 168 | } 169 | 170 | if ($tokens[$current]['code'] === T_VARIABLE) 171 | { 172 | $current = $this->_find_next_invokation_or_access($current, $next, $tokens, $end, $name, $file); 173 | } 174 | else 175 | { 176 | if ($tokens[$current]['code'] === T_NEW) 177 | { 178 | // Skip to class 179 | $current = $file->findNext(T_WHITESPACE, $current + 1, $end, TRUE); 180 | } 181 | 182 | if ($tokens[$current]['code'] === T_STRING 183 | OR $tokens[$current]['code'] === T_ARRAY 184 | OR $tokens[$current]['code'] === T_EMPTY 185 | OR $tokens[$current]['code'] === T_ISSET) 186 | { 187 | // Constant, function call or array 188 | 189 | // Skip to parenthesis 190 | $current = $file->findNext(T_WHITESPACE, $current + 1, $end, TRUE); 191 | 192 | if ($tokens[$current]['code'] === T_OPEN_PARENTHESIS) 193 | { 194 | $current = $tokens[$current]['parenthesis_closer']; 195 | } 196 | } 197 | elseif ($tokens[$current]['code'] === T_MINUS) 198 | { 199 | // Negation 200 | 201 | // Skip to negated value 202 | $current = $file->findNext(T_WHITESPACE, $current + 1, $end, TRUE); 203 | } 204 | 205 | if ($current AND $current < $end) 206 | { 207 | // The current position is NOT the end. Some other comparison, operation, etc must be happening. 208 | $error = 'Comparisons and operations must be in parentheses in the '.$name.' portion of ternary operations'; 209 | $file->addError($error, $current, 'TernaryParenthesized'); 210 | } 211 | } 212 | } 213 | } 214 | 215 | /** 216 | * Find the next invokation or access of an object's or static class' members. 217 | * 218 | * @param integer The current position in the token stack 219 | * @param integer The next token position 220 | * @param array Array of file's tokens 221 | * @param integer Pointer to token at end of section 222 | * @param string Section name (i.e. condition or value) 223 | * @param PHP_CodeSniffer_File The file we're examining 224 | * @return integer The position of the last token in the call (i.e. last non-whitespace token) 225 | */ 226 | protected function _find_next_invokation_or_access($current, $next, $tokens, $end, $name, PHP_CodeSniffer_File $file) 227 | { 228 | while ($next = $file->findNext(T_WHITESPACE, $current + 1, $end, TRUE)) 229 | { 230 | if ($tokens[$next]['code'] === T_OPEN_SQUARE_BRACKET 231 | OR $tokens[$next]['code'] === T_OPEN_CURLY_BRACKET) 232 | { 233 | // Array or String access 234 | $current = $tokens[$next]['bracket_closer']; 235 | } 236 | elseif ($tokens[$next]['code'] === T_OBJECT_OPERATOR 237 | OR $tokens[$next]['code'] === T_STRING 238 | OR $tokens[$next]['code'] === T_VARIABLE) 239 | { 240 | // Object access 241 | $current = $next + 1; 242 | } 243 | elseif ($tokens[$next]['code'] === T_OPEN_PARENTHESIS) 244 | { 245 | // Call 246 | $current = $tokens[$next]['parenthesis_closer']; 247 | } 248 | elseif ($tokens[$next]['code'] === T_DOUBLE_COLON) 249 | { 250 | $current = $next + 1; 251 | } 252 | else 253 | { 254 | $error = 'Comparisons and operations must be in parentheses in the '.$name.' portion of ternary operations'; 255 | $file->addError($error, $current, 'TernaryParenthesized'); 256 | break; 257 | } 258 | 259 | } 260 | 261 | return $current; 262 | } 263 | 264 | /** 265 | * Find the index of the next token of a certain type in a particular parentheses group 266 | * 267 | * @param array|integer $type Token type(s) to find 268 | * @param array $tokens Tokens to search 269 | * @param integer $start Index from which to begin 270 | * @param integer $end Index at which to abort 271 | * @param integer $parenthesis Index of the closing parenthesis or NULL 272 | * @return integer|FALSE Index of the next token or FALSE 273 | */ 274 | protected function _find_next($type, $tokens, $start, $end, $parenthesis) 275 | { 276 | if ( ! is_array($type)) 277 | { 278 | $type = array($type); 279 | } 280 | 281 | if ($parenthesis === NULL) 282 | { 283 | for ($i = $start; $i < $end; ++$i) 284 | { 285 | if (in_array($tokens[$i]['code'], $type) AND empty($tokens[$i]['nested_parenthesis'])) 286 | return $i; 287 | } 288 | } 289 | else 290 | { 291 | for ($i = $start; $i < $end; ++$i) 292 | { 293 | if (in_array($tokens[$i]['code'], $type) AND ! empty($tokens[$i]['nested_parenthesis']) AND $parenthesis === end($tokens[$i]['nested_parenthesis'])) 294 | return $i; 295 | } 296 | } 297 | 298 | return FALSE; 299 | } 300 | 301 | /** 302 | * Find the index of the previous token of a certain type in a particular parentheses group 303 | * 304 | * @param array|integer $type Token type(s) to find 305 | * @param array $tokens Tokens to search 306 | * @param integer $start Index from which to begin 307 | * @param integer $end Index at which to abort 308 | * @param integer $parenthesis Index of the opening parenthesis or NULL 309 | * @return integer|FALSE Index of the next token or FALSE 310 | */ 311 | protected function _find_previous($type, $tokens, $start, $end, $parenthesis) 312 | { 313 | if ( ! is_array($type)) 314 | { 315 | $type = array($type); 316 | } 317 | 318 | if ($parenthesis === NULL) 319 | { 320 | for ($i = $start; $i >= $end; --$i) 321 | { 322 | if (in_array($tokens[$i]['code'], $type) AND empty($tokens[$i]['nested_parenthesis'])) 323 | return $i; 324 | } 325 | } 326 | else 327 | { 328 | for ($i = $start; $i >= $end; --$i) 329 | { 330 | if (in_array($tokens[$i]['code'], $type) AND ! empty($tokens[$i]['nested_parenthesis'])) 331 | { 332 | end($tokens[$i]['nested_parenthesis']); 333 | 334 | if ($parenthesis === key($tokens[$i]['nested_parenthesis'])) 335 | return $i; 336 | } 337 | } 338 | } 339 | } 340 | } 341 | -------------------------------------------------------------------------------- /Kohana/Sniffs/Operators/TypeCastingSniff.php: -------------------------------------------------------------------------------- 1 | 10 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 11 | * @version CVS: $Id$ 12 | * @link http://pear.php.net/package/PHP_CodeSniffer 13 | */ 14 | 15 | /** 16 | * Throws errors if type-casting expressions are not spaced properly or if 17 | * long forms of type-casting operators are used. 18 | * 19 | * @category PHP 20 | * @package PHP_CodeSniffer 21 | * @author Matthew Turland 22 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 23 | * @version Release: @release_version@ 24 | * @link http://pear.php.net/package/PHP_CodeSniffer 25 | */ 26 | class Kohana_Sniffs_Operators_TypeCastingSniff implements PHP_CodeSniffer_Sniff 27 | { 28 | /** 29 | * Returns an array of tokens this test wants to listen for. 30 | * 31 | * @return array 32 | */ 33 | public function register() 34 | { 35 | return array( 36 | T_ARRAY_CAST, 37 | T_BOOL_CAST, 38 | T_DOUBLE_CAST, 39 | T_INT_CAST, 40 | T_OBJECT_CAST, 41 | T_STRING_CAST, 42 | T_UNSET_CAST 43 | ); 44 | } 45 | 46 | /** 47 | * Processes this test, when one of its tokens is encountered. 48 | * 49 | * @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the 50 | * document 51 | * @param int $stackPtr Position of the current token in the stack passed 52 | * in $tokens 53 | * @return void 54 | */ 55 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) 56 | { 57 | $tokens = $phpcsFile->getTokens(); 58 | $before = $tokens[$stackPtr - 1]; 59 | $after = $tokens[$stackPtr + 1]; 60 | 61 | if (($after['type'] !== 'T_WHITESPACE' OR $after['content'] !== ' ') 62 | OR ($before['type'] !== 'T_STRING_CONCAT' 63 | AND ($before['type'] !== 'T_WHITESPACE' OR $before['content'] !== ' ') 64 | AND $tokens[$stackPtr]['line'] !== $tokens[$stackPtr - 2]['line'] + 1)) 65 | { 66 | $error = 'Typecast operators must be first on the line or have a space on either side'; 67 | $phpcsFile->addError($error, $stackPtr); 68 | } 69 | 70 | switch (strtolower($tokens[$stackPtr]['content'])) { 71 | case '(integer)': 72 | case '(boolean)': 73 | $error = '(int) and (bool) should be used instead of (integer) and (boolean)'; 74 | $phpcsFile->addError($error, $stackPtr); 75 | break; 76 | } 77 | } 78 | } 79 | 80 | ?> 81 | -------------------------------------------------------------------------------- /Kohana/Sniffs/WhiteSpace/NoConcatenationSpaceSniff.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Chris Bandy 11 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 12 | * @version CVS: $Id$ 13 | * @link http://pear.php.net/package/PHP_CodeSniffer 14 | */ 15 | 16 | /** 17 | * Throws errors if spaces are used on either side of a concatenation 18 | * operator. 19 | * 20 | * @category PHP 21 | * @package PHP_CodeSniffer 22 | * @author Matthew Turland 23 | * @author Chris Bandy 24 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 25 | * @version Release: @release_version@ 26 | * @link http://pear.php.net/package/PHP_CodeSniffer 27 | */ 28 | class Kohana_Sniffs_WhiteSpace_NoConcatenationSpaceSniff implements PHP_CodeSniffer_Sniff 29 | { 30 | /** 31 | * Returns an array of tokens this test wants to listen for. 32 | * 33 | * @return array 34 | */ 35 | public function register() 36 | { 37 | return array( 38 | T_STRING_CONCAT 39 | ); 40 | } 41 | 42 | /** 43 | * Processes this test, when one of its tokens is encountered. 44 | * 45 | * @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the 46 | * document 47 | * @param int $stackPtr Position of the current token in the stack passed 48 | * in $tokens 49 | * @return void 50 | */ 51 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) 52 | { 53 | $tokens = $phpcsFile->getTokens(); 54 | 55 | if ($tokens[$stackPtr + 1]['code'] === T_WHITESPACE) 56 | { 57 | $phpcsFile->addError('No space is allowed after concatenation operators', $stackPtr); 58 | } 59 | 60 | // Find the previous token in this statement that is not whitespace 61 | $prevPtr = $phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, 0, TRUE, NULL, TRUE); 62 | 63 | if ($prevPtr !== FALSE AND $prevPtr !== ($stackPtr - 1)) 64 | { 65 | // Previous token is separated by whitespace 66 | 67 | if ($tokens[$prevPtr]['line'] === $tokens[$stackPtr]['line']) 68 | { 69 | $phpcsFile->addError('No space is allowed before concatenation operators', $stackPtr); 70 | } 71 | elseif ($tokens[$prevPtr]['line'] !== ($tokens[$stackPtr]['line'] - 1)) 72 | { 73 | $phpcsFile->addError('No blank lines are allowed before concatenation operators', $stackPtr); 74 | } 75 | } 76 | } 77 | } 78 | 79 | ?> 80 | -------------------------------------------------------------------------------- /Kohana/Sniffs/WhiteSpace/ParenthesesSniff.php: -------------------------------------------------------------------------------- 1 | 10 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 11 | * @version CVS: $Id$ 12 | * @link http://pear.php.net/package/PHP_CodeSniffer 13 | */ 14 | 15 | /** 16 | * Throws errors if spaces are used improperly around constructs, 17 | * parentheses, and some operators. 18 | * 19 | * @category PHP 20 | * @package PHP_CodeSniffer 21 | * @author Matthew Turland 22 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 23 | * @version Release: @release_version@ 24 | * @link http://pear.php.net/package/PHP_CodeSniffer 25 | */ 26 | class Kohana_Sniffs_WhiteSpace_ParenthesesSniff implements PHP_CodeSniffer_Sniff 27 | { 28 | /** 29 | * Returns an array of tokens this test wants to listen for. 30 | * 31 | * @return array 32 | */ 33 | public function register() 34 | { 35 | return array( 36 | T_IF, 37 | T_ELSE, 38 | T_ELSEIF, 39 | T_SWITCH, 40 | T_WHILE, 41 | T_FOR, 42 | T_FOREACH, 43 | T_OPEN_PARENTHESIS, 44 | T_CLOSE_PARENTHESIS, 45 | T_BITWISE_AND, 46 | T_BOOLEAN_NOT 47 | ); 48 | } 49 | 50 | /** 51 | * Processes this test, when one of its tokens is encountered. 52 | * 53 | * @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the 54 | * document 55 | * @param int $stackPtr Position of the current token in the stack passed 56 | * in $tokens 57 | * @return void 58 | */ 59 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) 60 | { 61 | $tokens = $phpcsFile->getTokens(); 62 | 63 | switch ($tokens[$stackPtr]['type']) { 64 | case 'T_ELSE': 65 | $nextPtr = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, null, true); 66 | if ($tokens[$nextPtr]['type'] != 'T_IF') { 67 | break; 68 | } 69 | case 'T_IF': 70 | case 'T_ELSEIF': 71 | case 'T_SWITCH': 72 | case 'T_WHILE': 73 | case 'T_FOR': 74 | case 'T_FOREACH': 75 | if ($tokens[$stackPtr + 1]['type'] != 'T_WHITESPACE' 76 | || $tokens[$stackPtr + 1]['content'] != ' ') { 77 | $error = 'Construct names should be separated from opening parentheses by a single space'; 78 | $phpcsFile->addError($error, $stackPtr); 79 | } 80 | break; 81 | 82 | case 'T_OPEN_PARENTHESIS': 83 | $prevPtr = $phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, null, true); 84 | if ($tokens[$stackPtr + 1]['type'] == 'T_WHITESPACE' 85 | && !in_array($tokens[$prevPtr]['type'], array('T_STRING', 'T_ARRAY')) 86 | && !in_array($tokens[$stackPtr + 2]['type'], array('T_BITWISE_AND', 'T_BOOLEAN_NOT', 'T_ARRAY_CAST', 'T_BOOL_CAST', 'T_DOUBLE_CAST', 'T_INT_CAST', 'T_OBJECT_CAST', 'T_STRING_CAST', 'T_UNSET_CAST'))) { 87 | $error = 'Whitespace after an opening parenthesis is only allowed when !, &, or a typecasting operator immediately follows'; 88 | $phpcsFile->addError($error, $stackPtr); 89 | } 90 | break; 91 | 92 | case 'T_CLOSE_PARENTHESIS': 93 | $opener = $tokens[$stackPtr]['parenthesis_opener']; 94 | $prevPtr = $phpcsFile->findPrevious(T_WHITESPACE, $opener - 1, null, true); 95 | if (!in_array($tokens[$prevPtr]['type'], array('T_STRING', 'T_ARRAY')) 96 | && $tokens[$stackPtr - 1]['type'] == 'T_WHITESPACE') { 97 | $error = 'Whitespace before a closing parenthesis is not allowed'; 98 | $phpcsFile->addError($error, $stackPtr); 99 | } 100 | break; 101 | 102 | case 'T_BITWISE_AND': 103 | // Allow the =& operator 104 | $before = $tokens[$stackPtr - 1]; 105 | if($before['type'] === 'T_EQUAL' || $before['content'] === '=') { 106 | continue; 107 | } 108 | case 'T_BOOLEAN_NOT': 109 | $before = $tokens[$stackPtr - 1]; 110 | $after = $tokens[$stackPtr + 1]; 111 | if ($before['type'] != 'T_WHITESPACE' 112 | || $before['content'] != ' ' 113 | || $after['type'] != 'T_WHITESPACE' 114 | || $after['content'] != ' ') { 115 | $error = 'A single space is required on either side of ! and & operators'; 116 | $phpcsFile->addError($error, $stackPtr); 117 | } 118 | break; 119 | } 120 | } 121 | } 122 | 123 | ?> 124 | -------------------------------------------------------------------------------- /Kohana/ruleset.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | The Kohana coding standard. 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # Kohana License Agreement 2 | 3 | This license is a legal agreement between you and the Kohana Team for the use of Kohana Framework (the "Software"). By obtaining the Software you agree to comply with the terms and conditions of this license. 4 | 5 | Copyright (c) 2007-2010 Kohana Team 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 11 | * 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. 12 | * Neither the name of the Kohana nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 13 | 14 | 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 THE COPYRIGHT OWNER OR CONTRIBUTORS 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. 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PHP Codesniffer standard for the Kohana Framework 2 | 3 | This package contains a set of coding standard tests for the [kohana](http://kohanaframework.org) PHP framework. 4 | The original tests were written by [Matthew Turland](http://matthewturland.com), see his [github repo](http://github.com/elazar/phpcs-kohana) for more info. 5 | 6 | These tests are meant to be a guide and may not be 100% accurate. If you find a bug please report it on the [kohana issue tracker](http://dev.kohanaframework.org). 7 | 8 | ## Requirements 9 | 10 | These tests are built for usage with [PHP Codesniffer](https://github.com/squizlabs/PHP_CodeSniffer). 11 | 12 | ## Installation - Composer 13 | 14 | Add the package to the development dependencies in your project's composer.json 15 | 16 | { 17 | "require-dev": { 18 | "kohana/coding-standards": "*", 19 | } 20 | } 21 | 22 | Run `composer --dev update` to update your composer.lock file and install the package. The sniffs will be installed in 23 | `vendor/kohana/coding-standards` in your project root directory and the `phpcs` command will be installed to `bin/phpcs`. 24 | 25 | ## Installation - Manually or with PEAR 26 | 27 | If you want the standard to be available system wide you can symlink them into the code sniffer dir like so: 28 | 29 | git clone https://github.com/kohana/coding-standards.git kohana-coding-standards 30 | cd kohana-coding-standards 31 | sudo ln -sfn `pwd`/Kohana `pear config-get php_dir`/PHP/CodeSniffer/Standards/Kohana 32 | sudo ln -sfn `pwd`/test/PHP_CodeSniffer/CodeSniffer/Standards/Kohana `pear config-get test_dir`/PHP_CodeSniffer/CodeSniffer/Standards/Kohana 33 | 34 | ## Running 35 | 36 | If you installed with composer, reference the standard from your vendor directory: 37 | 38 | bin/phpcs --standard=vendor/kohana/coding-standards/Kohana modules/ 39 | 40 | Or, from a raw clone, you can simply reference the local copy: 41 | 42 | phpcs --standard=path/to/coding-standards/Kohana kohana/core 43 | 44 | If installed globally (symlinked into PEAR), you can reference the standard like so: 45 | 46 | phpcs --standard=Kohana application/ 47 | 48 | ## Customising your project standard 49 | 50 | It is also possible to extend the rules in use for your project, or to include some but not all of the Kohana standards 51 | (for example, if you are working on something that is not intended as a kohana module). You do this by adding a 52 | `coding_standard.xml` to your project root which specifies which rules to include and customises any variables. See the 53 | [PHP_CodeSniffer docs](https://pear.php.net/manual/en/package.php.php-codesniffer.annotated-ruleset.php) for more 54 | details. 55 | 56 | ## Testing 57 | 58 | Like all things code related, sniffs need to be tested! To run the tests they need to be in the codesniffer dir 59 | (i.e. you should run the above commands to symlink the sniffs / tests in) and you need to 60 | [patch phpcs' AllSniffs.php](http://pear.php.net/bugs/bug.php?id=17902&edit=12&patch=fix-cant-run-symlinked-tests.patch&revision=latest) 61 | 62 | Then just run the tests like so: 63 | 64 | phpunit --bootstrap=`pear config-get php_dir`/PHP/CodeSniffer.php `pear config-get test_dir`/PHP_CodeSniffer/CodeSniffer/Standards/AllSniffs.php 65 | 66 | ### Known issues 67 | 68 | * There are some problems with expressions in ternary operators 69 | 70 | Please report any new issues to the K3 bug tracker and file it under "PHPCS Coding Standards" 71 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "kohana/coding-standards", 3 | "type": "library", 4 | "description": "PHP_CodeSniffer rules for the Kohana Framework coding style", 5 | "keywords": ["kohana", "code standard", "coding stanards", "code style", "standards", "phpcs"], 6 | "homepage": "https://github.com/kohana/coding-standards", 7 | "license": "BSD-3-Clause", 8 | "support": { 9 | "issues": "https://github.com/kohana/coding-standards/issues", 10 | "wiki": "https://github.com/kohana/coding-standards/wiki", 11 | "irc": "irc://irc.freenode.org/kohana" 12 | }, 13 | "authors": [ 14 | { 15 | "name": "Kohana Team", 16 | "email": "team@kohanaframework.org", 17 | "homepage": "http://www.kohanaframework.org", 18 | "role": "Maintainer" 19 | } 20 | ], 21 | "require": { 22 | "squizlabs/php_codesniffer": "1.*" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /test/PHP_CodeSniffer/CodeSniffer/Standards/Kohana/Tests/Classes/EmptyConstructorCallUnitTest.inc: -------------------------------------------------------------------------------- 1 | 5 | -------------------------------------------------------------------------------- /test/PHP_CodeSniffer/CodeSniffer/Standards/Kohana/Tests/Classes/EmptyConstructorCallUnitTest.php: -------------------------------------------------------------------------------- 1 | 10 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 11 | * @version CVS: $Id$ 12 | * @link http://pear.php.net/package/PHP_CodeSniffer 13 | */ 14 | 15 | /** 16 | * Unit test class for EmptyConstructorCallSniff. 17 | * 18 | * @category PHP 19 | * @package PHP_CodeSniffer 20 | * @author Matthew Turland 21 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 22 | * @version Release: @release_version@ 23 | * @link http://pear.php.net/package/PHP_CodeSniffer 24 | */ 25 | class Kohana_Tests_Classes_EmptyConstructorCallUnitTest extends AbstractSniffUnitTest 26 | { 27 | /** 28 | * Returns the lines where errors should occur. 29 | * 30 | * The key of the array should represent the line number and the value 31 | * should represent the number of errors that should occur on that line. 32 | * 33 | * @return array(int => int) 34 | */ 35 | public function getErrorList() 36 | { 37 | return array( 38 | 3 => 1 39 | ); 40 | } 41 | 42 | /** 43 | * Returns the lines where warnings should occur. 44 | * 45 | * The key of the array should represent the line number and the value 46 | * should represent the number of warnings that should occur on that line. 47 | * 48 | * @return array(int => int) 49 | */ 50 | public function getWarningList() 51 | { 52 | return array(); 53 | } 54 | } 55 | 56 | ?> 57 | -------------------------------------------------------------------------------- /test/PHP_CodeSniffer/CodeSniffer/Standards/Kohana/Tests/Commenting/DocBlockParamUnitTest.inc: -------------------------------------------------------------------------------- 1 | number) pairs 18 | */ 19 | public function getErrorList() 20 | { 21 | return array(); 22 | } 23 | 24 | /** 25 | * Returns the number of warnings that should occur on each line. 26 | * 27 | * @return array Array of (line => number) pairs 28 | */ 29 | public function getWarningList() 30 | { 31 | return array( 32 | 4 => 1, 33 | 12 => 1, 34 | ); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /test/PHP_CodeSniffer/CodeSniffer/Standards/Kohana/Tests/Commenting/DocBlockSeeUnitTest.inc: -------------------------------------------------------------------------------- 1 | number) pairs 18 | */ 19 | public function getErrorList() 20 | { 21 | return array(); 22 | } 23 | 24 | /** 25 | * Returns the number of warnings that should occur on each line. 26 | * 27 | * @return array Array of (line => number) pairs 28 | */ 29 | public function getWarningList() 30 | { 31 | return array( 32 | 6 => 1, 33 | ); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /test/PHP_CodeSniffer/CodeSniffer/Standards/Kohana/Tests/Commenting/OneLineCommentUnitTest.inc: -------------------------------------------------------------------------------- 1 | 6 | -------------------------------------------------------------------------------- /test/PHP_CodeSniffer/CodeSniffer/Standards/Kohana/Tests/Commenting/OneLineCommentUnitTest.php: -------------------------------------------------------------------------------- 1 | 10 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 11 | * @version CVS: $Id$ 12 | * @link http://pear.php.net/package/PHP_CodeSniffer 13 | */ 14 | 15 | /** 16 | * Unit test class for OneLineCommentSniff. 17 | * 18 | * @category PHP 19 | * @package PHP_CodeSniffer 20 | * @author Matthew Turland 21 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 22 | * @version Release: @release_version@ 23 | * @link http://pear.php.net/package/PHP_CodeSniffer 24 | */ 25 | class Kohana_Tests_Commenting_OneLineCommentUnitTest extends AbstractSniffUnitTest 26 | { 27 | /** 28 | * Returns the lines where errors should occur. 29 | * 30 | * The key of the array should represent the line number and the value 31 | * should represent the number of errors that should occur on that line. 32 | * 33 | * @return array(int => int) 34 | */ 35 | public function getErrorList() 36 | { 37 | return array( 38 | 3 => 1, 39 | 4 => 1 40 | ); 41 | } 42 | 43 | /** 44 | * Returns the lines where warnings should occur. 45 | * 46 | * The key of the array should represent the line number and the value 47 | * should represent the number of warnings that should occur on that line. 48 | * 49 | * @return array(int => int) 50 | */ 51 | public function getWarningList() 52 | { 53 | return array(); 54 | } 55 | } 56 | 57 | ?> 58 | -------------------------------------------------------------------------------- /test/PHP_CodeSniffer/CodeSniffer/Standards/Kohana/Tests/ControlStructures/ElseIfUnitTest.inc: -------------------------------------------------------------------------------- 1 | 10 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 11 | * @version CVS: $Id$ 12 | * @link http://pear.php.net/package/PHP_CodeSniffer 13 | */ 14 | 15 | /** 16 | * Unit test class for the ElseIf sniff. 17 | * 18 | * A sniff unit test checks a .inc file for expected violations of a single 19 | * coding standard. Expected errors and warnings are stored in this class. 20 | * 21 | * @category PHP 22 | * @package PHP_CodeSniffer 23 | * @author Matthew Turland 24 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 25 | * @version Release: @release_version@ 26 | * @link http://pear.php.net/package/PHP_CodeSniffer 27 | */ 28 | class Kohana_Tests_ControlStructures_ElseIfUnitTest extends AbstractSniffUnitTest 29 | { 30 | /** 31 | * Returns the lines where errors should occur. 32 | * 33 | * The key of the array should represent the line number and the value 34 | * should represent the number of errors that should occur on that line. 35 | * 36 | * @return array(int => int) 37 | */ 38 | public function getErrorList() 39 | { 40 | return array( 41 | 3 => 1 42 | ); 43 | } 44 | 45 | 46 | /** 47 | * Returns the lines where warnings should occur. 48 | * 49 | * The key of the array should represent the line number and the value 50 | * should represent the number of warnings that should occur on that line. 51 | * 52 | * @return array(int => int) 53 | */ 54 | public function getWarningList() 55 | { 56 | return array(); 57 | } 58 | } 59 | 60 | ?> 61 | -------------------------------------------------------------------------------- /test/PHP_CodeSniffer/CodeSniffer/Standards/Kohana/Tests/ControlStructures/SingleLineIfUnitTest.inc: -------------------------------------------------------------------------------- 1 | 10 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 11 | * @version CVS: $Id$ 12 | * @link http://pear.php.net/package/PHP_CodeSniffer 13 | */ 14 | 15 | /** 16 | * Unit test class for the SingleLineIf sniff. 17 | * 18 | * A sniff unit test checks a .inc file for expected violations of a single 19 | * coding standard. Expected errors and warnings are stored in this class. 20 | * 21 | * @category PHP 22 | * @package PHP_CodeSniffer 23 | * @author Matthew Turland 24 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 25 | * @version Release: @release_version@ 26 | * @link http://pear.php.net/package/PHP_CodeSniffer 27 | */ 28 | class Kohana_Tests_ControlStructures_SingleLineIfUnitTest extends AbstractSniffUnitTest 29 | { 30 | /** 31 | * Returns the lines where errors should occur. 32 | * 33 | * The key of the array should represent the line number and the value 34 | * should represent the number of errors that should occur on that line. 35 | * 36 | * @return array(int => int) 37 | */ 38 | public function getErrorList() 39 | { 40 | return array( 41 | 15 => 1 42 | ); 43 | } 44 | 45 | 46 | /** 47 | * Returns the lines where warnings should occur. 48 | * 49 | * The key of the array should represent the line number and the value 50 | * should represent the number of warnings that should occur on that line. 51 | * 52 | * @return array(int => int) 53 | */ 54 | public function getWarningList() 55 | { 56 | return array(); 57 | } 58 | } 59 | 60 | ?> 61 | -------------------------------------------------------------------------------- /test/PHP_CodeSniffer/CodeSniffer/Standards/Kohana/Tests/ControlStructures/SwitchUnitTest.inc: -------------------------------------------------------------------------------- 1 | 10 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 11 | * @version CVS: $Id$ 12 | * @link http://pear.php.net/package/PHP_CodeSniffer 13 | */ 14 | 15 | /** 16 | * Unit test class for the Switch sniff. 17 | * 18 | * A sniff unit test checks a .inc file for expected violations of a single 19 | * coding standard. Expected errors and warnings are stored in this class. 20 | * 21 | * @category PHP 22 | * @package PHP_CodeSniffer 23 | * @author Matthew Turland 24 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 25 | * @version Release: @release_version@ 26 | * @link http://pear.php.net/package/PHP_CodeSniffer 27 | */ 28 | class Kohana_Tests_ControlStructures_SwitchUnitTest extends AbstractSniffUnitTest 29 | { 30 | /** 31 | * Returns the lines where errors should occur. 32 | * 33 | * The key of the array should represent the line number and the value 34 | * should represent the number of errors that should occur on that line. 35 | * 36 | * @return array(int => int) 37 | */ 38 | public function getErrorList() 39 | { 40 | return array( 41 | 7 => 1, 42 | 9 => 1, 43 | 14 => 1 44 | ); 45 | } 46 | 47 | 48 | /** 49 | * Returns the lines where warnings should occur. 50 | * 51 | * The key of the array should represent the line number and the value 52 | * should represent the number of warnings that should occur on that line. 53 | * 54 | * @return array(int => int) 55 | */ 56 | public function getWarningList() 57 | { 58 | return array( 59 | 12 => 1 60 | ); 61 | } 62 | } 63 | 64 | ?> 65 | -------------------------------------------------------------------------------- /test/PHP_CodeSniffer/CodeSniffer/Standards/Kohana/Tests/Functions/RegularExpressionUnitTest.inc: -------------------------------------------------------------------------------- 1 | 10 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 11 | * @version CVS: $Id$ 12 | * @link http://pear.php.net/package/PHP_CodeSniffer 13 | */ 14 | 15 | /** 16 | * Unit test class for the RegularExpression sniff. 17 | * 18 | * A sniff unit test checks a .inc file for expected violations of a single 19 | * coding standard. Expected errors and warnings are stored in this class. 20 | * 21 | * @category PHP 22 | * @package PHP_CodeSniffer 23 | * @author Matthew Turland 24 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 25 | * @version Release: @release_version@ 26 | * @link http://pear.php.net/package/PHP_CodeSniffer 27 | */ 28 | class Kohana_Tests_Functions_RegularExpressionUnitTest extends AbstractSniffUnitTest 29 | { 30 | /** 31 | * Returns the lines where errors should occur. 32 | * 33 | * The key of the array should represent the line number and the value 34 | * should represent the number of errors that should occur on that line. 35 | * 36 | * @return array(int => int) 37 | */ 38 | public function getErrorList() 39 | { 40 | return array( 41 | 3 => 1, 42 | 5 => 1 43 | ); 44 | } 45 | 46 | 47 | /** 48 | * Returns the lines where warnings should occur. 49 | * 50 | * The key of the array should represent the line number and the value 51 | * should represent the number of warnings that should occur on that line. 52 | * 53 | * @return array(int => int) 54 | */ 55 | public function getWarningList() 56 | { 57 | return array( 58 | 7 => 1 59 | ); 60 | } 61 | } 62 | 63 | ?> 64 | -------------------------------------------------------------------------------- /test/PHP_CodeSniffer/CodeSniffer/Standards/Kohana/Tests/NamingConventions/ValidFunctionNameUnitTest.inc: -------------------------------------------------------------------------------- 1 | 182 | -------------------------------------------------------------------------------- /test/PHP_CodeSniffer/CodeSniffer/Standards/Kohana/Tests/NamingConventions/ValidFunctionNameUnitTest.php: -------------------------------------------------------------------------------- 1 | 10 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 11 | * @version CVS: $Id$ 12 | * @link http://pear.php.net/package/PHP_CodeSniffer 13 | */ 14 | 15 | /** 16 | * Unit test class for the ValidFunctionName sniff. 17 | * 18 | * A sniff unit test checks a .inc file for expected violations of a single 19 | * coding standard. Expected errors and warnings are stored in this class. 20 | * 21 | * @category PHP 22 | * @package PHP_CodeSniffer 23 | * @author Matthew Turland 24 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 25 | * @version Release: @release_version@ 26 | * @link http://pear.php.net/package/PHP_CodeSniffer 27 | */ 28 | class Kohana_Tests_NamingConventions_ValidFunctionNameUnitTest extends AbstractSniffUnitTest 29 | { 30 | /** 31 | * Returns the lines where errors should occur. 32 | * 33 | * The key of the array should represent the line number and the value 34 | * should represent the number of errors that should occur on that line. 35 | * 36 | * @return array(int => int) 37 | */ 38 | public function getErrorList() 39 | { 40 | return array( 41 | 6 => 1, 42 | 7 => 1, 43 | 9 => 1, 44 | 10 => 1, 45 | 12 => 1, 46 | 13 => 1, 47 | 14 => 1, 48 | 15 => 1, 49 | 16 => 1, 50 | 18 => 1, 51 | 19 => 1, 52 | 20 => 1, 53 | 22 => 1, 54 | 23 => 1, 55 | 25 => 1, 56 | 26 => 1, 57 | 27 => 1, 58 | 28 => 1, 59 | 29 => 1, 60 | 31 => 1, 61 | 32 => 1, 62 | 33 => 1, 63 | 35 => 1, 64 | 36 => 1, 65 | 38 => 1, 66 | 39 => 1, 67 | 40 => 1, 68 | 41 => 1, 69 | 42 => 1, 70 | 44 => 1, 71 | 45 => 1, 72 | 46 => 1, 73 | 48 => 1, 74 | 49 => 1, 75 | 51 => 1, 76 | 52 => 1, 77 | 53 => 1, 78 | 54 => 1, 79 | 55 => 1, 80 | 57 => 1, 81 | 57 => 1, 82 | 58 => 1, 83 | 59 => 1, 84 | 65 => 1, 85 | 66 => 1, 86 | 68 => 1, 87 | 69 => 1, 88 | 70 => 1, 89 | 71 => 1, 90 | 72 => 1, 91 | 74 => 1, 92 | 75 => 1, 93 | 76 => 1, 94 | 78 => 1, 95 | 79 => 1, 96 | 81 => 1, 97 | 82 => 1, 98 | 83 => 1, 99 | 84 => 1, 100 | 85 => 1, 101 | 87 => 1, 102 | 88 => 1, 103 | 89 => 1, 104 | 91 => 1, 105 | 92 => 1, 106 | 94 => 1, 107 | 95 => 1, 108 | 96 => 1, 109 | 97 => 1, 110 | 98 => 1, 111 | 100 => 1, 112 | 101 => 1, 113 | 102 => 1, 114 | 104 => 1, 115 | 105 => 1, 116 | 107 => 1, 117 | 108 => 1, 118 | 109 => 1, 119 | 110 => 1, 120 | 111 => 1, 121 | 113 => 1, 122 | 114 => 1, 123 | 115 => 1, 124 | 119 => 1, 125 | 120 => 1, 126 | 121 => 1, 127 | 122 => 1, 128 | 123 => 1, 129 | 124 => 1, 130 | 125 => 1, 131 | 126 => 1, 132 | 127 => 1, 133 | 128 => 1, 134 | 129 => 1, 135 | 130 => 1, 136 | 146 => 1, 137 | 147 => 1, 138 | 148 => 1, 139 | 151 => 1, 140 | 152 => 1, 141 | 153 => 1, 142 | 154 => 1, 143 | 155 => 1, 144 | 156 => 1, 145 | 157 => 1, 146 | 158 => 1, 147 | 159 => 1, 148 | 160 => 1, 149 | 161 => 1, 150 | 162 => 1, 151 | 163 => 1, 152 | 165 => 1, 153 | 166 => 1, 154 | 169 => 1, 155 | 170 => 1 156 | ); 157 | } 158 | 159 | 160 | /** 161 | * Returns the lines where warnings should occur. 162 | * 163 | * The key of the array should represent the line number and the value 164 | * should represent the number of warnings that should occur on that line. 165 | * 166 | * @return array(int => int) 167 | */ 168 | public function getWarningList() 169 | { 170 | return array(); 171 | } 172 | } 173 | 174 | ?> 175 | -------------------------------------------------------------------------------- /test/PHP_CodeSniffer/CodeSniffer/Standards/Kohana/Tests/NamingConventions/ValidVariableNameUnitTest.inc: -------------------------------------------------------------------------------- 1 | def["POP_{$cc}_A"]}' 56 | and POP_{$cc}_B = 57 | '{$this->def["POP_{$cc}_B"]}')"; 58 | } 59 | } 60 | ?> 61 | -------------------------------------------------------------------------------- /test/PHP_CodeSniffer/CodeSniffer/Standards/Kohana/Tests/NamingConventions/ValidVariableNameUnitTest.php: -------------------------------------------------------------------------------- 1 | 10 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 11 | * @version CVS: $Id$ 12 | * @link http://pear.php.net/package/PHP_CodeSniffer 13 | */ 14 | 15 | /** 16 | * Unit test class for the ValidVariableName sniff. 17 | * 18 | * A sniff unit test checks a .inc file for expected violations of a single 19 | * coding standard. Expected errors and warnings are stored in this class. 20 | * 21 | * @category PHP 22 | * @package PHP_CodeSniffer 23 | * @author Matthew Turland 24 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 25 | * @version Release: @release_version@ 26 | * @link http://pear.php.net/package/PHP_CodeSniffer 27 | */ 28 | class Kohana_Tests_NamingConventions_ValidVariableNameUnitTest extends AbstractSniffUnitTest 29 | { 30 | /** 31 | * Returns the lines where errors should occur. 32 | * 33 | * The key of the array should represent the line number and the value 34 | * should represent the number of errors that should occur on that line. 35 | * 36 | * @return array(int => int) 37 | */ 38 | public function getErrorList() 39 | { 40 | return array( 41 | 4 => 1, 42 | 7 => 1, 43 | 9 => 1, 44 | 12 => 1, 45 | 14 => 1, 46 | 17 => 1, 47 | 19 => 1, 48 | 22 => 1, 49 | 46 => 1 50 | ); 51 | } 52 | 53 | /** 54 | * Returns the lines where warnings should occur. 55 | * 56 | * The key of the array should represent the line number and the value 57 | * should represent the number of warnings that should occur on that line. 58 | * 59 | * @return array(int => int) 60 | */ 61 | public function getWarningList() 62 | { 63 | return array(); 64 | } 65 | } 66 | 67 | ?> 68 | -------------------------------------------------------------------------------- /test/PHP_CodeSniffer/CodeSniffer/Standards/Kohana/Tests/Operators/ComparisonOperatorUnitTest.inc: -------------------------------------------------------------------------------- 1 | 10 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 11 | * @version CVS: $Id$ 12 | * @link http://pear.php.net/package/PHP_CodeSniffer 13 | */ 14 | 15 | /** 16 | * Unit test class for the ComparisonOperator sniff. 17 | * 18 | * A sniff unit test checks a .inc file for expected violations of a single 19 | * coding standard. Expected errors and warnings are stored in this class. 20 | * 21 | * @category PHP 22 | * @package PHP_CodeSniffer 23 | * @author Matthew Turland 24 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 25 | * @version Release: @release_version@ 26 | * @link http://pear.php.net/package/PHP_CodeSniffer 27 | */ 28 | class Kohana_Tests_Operators_ComparisonOperatorUnitTest extends AbstractSniffUnitTest 29 | { 30 | /** 31 | * Returns the lines where errors should occur. 32 | * 33 | * The key of the array should represent the line number and the value 34 | * should represent the number of errors that should occur on that line. 35 | * 36 | * @return array(int => int) 37 | */ 38 | public function getErrorList() 39 | { 40 | return array( 41 | 3 => 3, 42 | 5 => 1 43 | ); 44 | } 45 | 46 | 47 | /** 48 | * Returns the lines where warnings should occur. 49 | * 50 | * The key of the array should represent the line number and the value 51 | * should represent the number of warnings that should occur on that line. 52 | * 53 | * @return array(int => int) 54 | */ 55 | public function getWarningList() 56 | { 57 | return array(); 58 | } 59 | } 60 | 61 | ?> 62 | -------------------------------------------------------------------------------- /test/PHP_CodeSniffer/CodeSniffer/Standards/Kohana/Tests/Operators/TernaryOperatorUnitTest.inc: -------------------------------------------------------------------------------- 1 | 5) ? ($bar + $foo) : strlen($bar); 6 | $foo = $bar > 5 ? $bar + $foo : strlen($bar); 7 | $foo = ($bar == $foo) 8 | ? $foo 9 | : $bar; 10 | $foo = $bar ? -1 : $bar; 11 | $foo = $bar ? (string) $foobar : $bar; 12 | $foo = $bar ? ($baz ? $baz : FALSE) : $foobar; 13 | $foo = $bar ? array() : $baz; 14 | $foo = $bar ? new MyClass : FALSE; 15 | $foo = ($bar = NULL) ? $foo : $bar; 16 | $foo = new DateTimeZone($bar ? $bar : date_default_timezone_get()); 17 | $foo = new DateTime($bar, new DateTimeZone($baz ? $baz : date_default_timezone_get())); 18 | $foo = $bar['a'][0] ? $baz->foo : FALSE; 19 | echo MyClass::$property ? MyClass::CONSTANT : MyClass::method(); 20 | return isset($this->$key) ? $this->$key : NULL; 21 | array('a' => $foo ? $bar : $baz); 22 | array('a', 'b' => $foo ? $bar : $baz); 23 | $foo = Auth::instance()->logged_in() ? 'yay' : 'nay'; 24 | $foo = TRUE ? Auth::instance()->username() : Auth::instance()->user()->guest; 25 | $var = Auth::instance()->logged_in() 26 | ? Auth::instance()->get_user()->profile->default_language 27 | : $lol; 28 | -------------------------------------------------------------------------------- /test/PHP_CodeSniffer/CodeSniffer/Standards/Kohana/Tests/Operators/TernaryOperatorUnitTest.php: -------------------------------------------------------------------------------- 1 | 10 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 11 | * @version CVS: $Id$ 12 | * @link http://pear.php.net/package/PHP_CodeSniffer 13 | */ 14 | 15 | /** 16 | * Unit test class for the TernaryOperator sniff. 17 | * 18 | * A sniff unit test checks a .inc file for expected violations of a single 19 | * coding standard. Expected errors and warnings are stored in this class. 20 | * 21 | * @category PHP 22 | * @package PHP_CodeSniffer 23 | * @author Matthew Turland 24 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 25 | * @version Release: @release_version@ 26 | * @link http://pear.php.net/package/PHP_CodeSniffer 27 | */ 28 | class Kohana_Tests_Operators_TernaryOperatorUnitTest extends AbstractSniffUnitTest 29 | { 30 | /** 31 | * Returns the lines where errors should occur. 32 | * 33 | * The key of the array should represent the line number and the value 34 | * should represent the number of errors that should occur on that line. 35 | * 36 | * @return array(int => int) 37 | */ 38 | public function getErrorList() 39 | { 40 | return array( 41 | 4 => 2, 42 | 6 => 2 43 | ); 44 | } 45 | 46 | 47 | /** 48 | * Returns the lines where warnings should occur. 49 | * 50 | * The key of the array should represent the line number and the value 51 | * should represent the number of warnings that should occur on that line. 52 | * 53 | * @return array(int => int) 54 | */ 55 | public function getWarningList() 56 | { 57 | return array(); 58 | } 59 | } 60 | 61 | ?> 62 | -------------------------------------------------------------------------------- /test/PHP_CodeSniffer/CodeSniffer/Standards/Kohana/Tests/Operators/TypeCastingUnitTest.inc: -------------------------------------------------------------------------------- 1 | 10 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 11 | * @version CVS: $Id$ 12 | * @link http://pear.php.net/package/PHP_CodeSniffer 13 | */ 14 | 15 | /** 16 | * Unit test class for the TypeCasting sniff. 17 | * 18 | * A sniff unit test checks a .inc file for expected violations of a single 19 | * coding standard. Expected errors and warnings are stored in this class. 20 | * 21 | * @category PHP 22 | * @package PHP_CodeSniffer 23 | * @author Matthew Turland 24 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 25 | * @version Release: @release_version@ 26 | * @link http://pear.php.net/package/PHP_CodeSniffer 27 | */ 28 | class Kohana_Tests_Operators_TypeCastingUnitTest extends AbstractSniffUnitTest 29 | { 30 | /** 31 | * Returns the lines where errors should occur. 32 | * 33 | * The key of the array should represent the line number and the value 34 | * should represent the number of errors that should occur on that line. 35 | * 36 | * @return array(int => int) 37 | */ 38 | public function getErrorList() 39 | { 40 | return array( 41 | 3 => 1, 42 | 6 => 1, 43 | 7 => 1, 44 | 11 => 1, 45 | ); 46 | } 47 | 48 | 49 | /** 50 | * Returns the lines where warnings should occur. 51 | * 52 | * The key of the array should represent the line number and the value 53 | * should represent the number of warnings that should occur on that line. 54 | * 55 | * @return array(int => int) 56 | */ 57 | public function getWarningList() 58 | { 59 | return array(); 60 | } 61 | } 62 | 63 | ?> 64 | -------------------------------------------------------------------------------- /test/PHP_CodeSniffer/CodeSniffer/Standards/Kohana/Tests/WhiteSpace/NoConcatenationSpaceUnitTest.inc: -------------------------------------------------------------------------------- 1 | 10 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 11 | * @version CVS: $Id$ 12 | * @link http://pear.php.net/package/PHP_CodeSniffer 13 | */ 14 | 15 | /** 16 | * Unit test class for the NoConcatenationSpace sniff. 17 | * 18 | * A sniff unit test checks a .inc file for expected violations of a single 19 | * coding standard. Expected errors and warnings are stored in this class. 20 | * 21 | * @category PHP 22 | * @package PHP_CodeSniffer 23 | * @author Matthew Turland 24 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 25 | * @version Release: @release_version@ 26 | * @link http://pear.php.net/package/PHP_CodeSniffer 27 | */ 28 | class Kohana_Tests_WhiteSpace_NoConcatenationSpaceUnitTest extends AbstractSniffUnitTest 29 | { 30 | /** 31 | * Returns the lines where errors should occur. 32 | * 33 | * The key of the array should represent the line number and the value 34 | * should represent the number of errors that should occur on that line. 35 | * 36 | * @return array(int => int) 37 | */ 38 | public function getErrorList() 39 | { 40 | return array( 41 | 3 => 2, 42 | 4 => 4, 43 | 8 => 1, 44 | 11 => 1, 45 | 14 => 1, 46 | ); 47 | } 48 | 49 | 50 | /** 51 | * Returns the lines where warnings should occur. 52 | * 53 | * The key of the array should represent the line number and the value 54 | * should represent the number of warnings that should occur on that line. 55 | * 56 | * @return array(int => int) 57 | */ 58 | public function getWarningList() 59 | { 60 | return array(); 61 | } 62 | } 63 | 64 | ?> 65 | -------------------------------------------------------------------------------- /test/PHP_CodeSniffer/CodeSniffer/Standards/Kohana/Tests/WhiteSpace/ParenthesesUnitTest.inc: -------------------------------------------------------------------------------- 1 | 10 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 11 | * @version CVS: $Id$ 12 | * @link http://pear.php.net/package/PHP_CodeSniffer 13 | */ 14 | 15 | /** 16 | * Unit test class for the Parentheses sniff. 17 | * 18 | * A sniff unit test checks a .inc file for expected violations of a single 19 | * coding standard. Expected errors and warnings are stored in this class. 20 | * 21 | * @category PHP 22 | * @package PHP_CodeSniffer 23 | * @author Matthew Turland 24 | * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence 25 | * @version Release: @release_version@ 26 | * @link http://pear.php.net/package/PHP_CodeSniffer 27 | */ 28 | class Kohana_Tests_WhiteSpace_ParenthesesUnitTest extends AbstractSniffUnitTest 29 | { 30 | /** 31 | * Returns the lines where errors should occur. 32 | * 33 | * The key of the array should represent the line number and the value 34 | * should represent the number of errors that should occur on that line. 35 | * 36 | * @return array(int => int) 37 | */ 38 | public function getErrorList() 39 | { 40 | return array( 41 | 5 => 1, 42 | 6 => 2, 43 | 7 => 2, 44 | 8 => 1 45 | ); 46 | } 47 | 48 | 49 | /** 50 | * Returns the lines where warnings should occur. 51 | * 52 | * The key of the array should represent the line number and the value 53 | * should represent the number of warnings that should occur on that line. 54 | * 55 | * @return array(int => int) 56 | */ 57 | public function getWarningList() 58 | { 59 | return array(); 60 | } 61 | } 62 | 63 | ?> 64 | --------------------------------------------------------------------------------