Changeset 1173
- Timestamp:
- 12/21/07 17:42:37 (1 year ago)
- Files:
-
- trunk/src/main/php/org/stubbles/codeSniffer/stubbles/StubblesCodingStandard.php (modified) (2 diffs)
- trunk/src/main/php/org/stubbles/codeSniffer/stubbles/sniffs/ControlStructures (added)
- trunk/src/main/php/org/stubbles/codeSniffer/stubbles/sniffs/ControlStructures/stubSwitchDeclarationSniff.php (added)
- trunk/src/main/php/org/stubbles/codeSniffer/stubbles/sniffs/Functions/stubFunctionCallSignatureSniff.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/org/stubbles/codeSniffer/stubbles/StubblesCodingStandard.php
r1131 r1173 33 33 'Generic/Sniffs/PHP/DisallowShortOpenTagSniff.php', 34 34 'Generic/Sniffs/WhiteSpace/DisallowTabIndentSniff.php', 35 'Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php', 35 36 36 37 // PEAR 37 38 'PEAR/Sniffs/Functions/FunctionCallArgumentSpacingSniff.php', 38 39 'PEAR/Sniffs/Functions/ValidDefaultValueSniff.php', 39 'PEAR/Sniffs/WhiteSpace/ScopeClosingBraceSniff.php',40 'PEAR/Sniffs/WhiteSpace/ScopeIndentSniff.php',41 40 42 41 // Squiz … … 46 45 'Squiz/Sniffs/Classes/LowercaseClassKeywordsSniff.php', 47 46 'Squiz/Sniffs/Classes/SelfMemberReferenceSniff.php', 48 # 'Squiz/Sniffs/ControlStructures/SwitchDeclarationSniff.php',49 47 'Squiz/Sniffs/Commenting/BlockCommentSniff.php', 50 48 'Squiz/Sniffs/Commenting/DocCommentAlignmentSniff.php', trunk/src/main/php/org/stubbles/codeSniffer/stubbles/sniffs/Functions/stubFunctionCallSignatureSniff.php
r1131 r1173 2 2 /** 3 3 * This sniff checks for whitespace in functions calls: 4 *5 * Copied and adapted content from PEAR/Sniffs/Functions/FunctionCallSignatureSniff6 * because of no extending possibility (no methods/attributes to overwrite).7 4 * 8 5 * @package Functions … … 33 30 * 'net.stubbles.bar.foo.bar); 34 31 * 35 *36 * Copied and adapted content from PEAR/Sniffs/Functions/FunctionCallSignatureSniff37 * because of no extending possibility (no methods/attributes to overwrite).38 *39 32 * @package Functions 40 33 */ 41 class Stubbles_Sniffs_Functions_stubFunctionCallSignatureSniff implements PHP_CodeSniffer_Sniff34 class Stubbles_Sniffs_Functions_stubFunctionCallSignatureSniff extends PEAR_Sniffs_Functions_FunctionCallSignatureSniff 42 35 { 43 36 /** … … 64 57 $tokens = $phpcsFile->getTokens(); 65 58 66 /*67 * Stubbles68 */69 59 if ($tokens[$stackPtr-2]['content'] === 'stubClassLoader' && 70 60 $tokens[$stackPtr-1]['content'] === '::' && … … 74 64 } 75 65 76 // Find the next non-empty token. 77 $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true); 78 79 if ($tokens[$next]['code'] !== T_OPEN_PARENTHESIS) { 80 // Not a function call. 81 return; 82 } 83 84 if (isset($tokens[$next]['parenthesis_closer']) === false) { 85 // Not a function call. 86 return; 87 } 88 89 // Find the previous non-empty token. 90 $previous = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true); 91 if ($tokens[$previous]['code'] === T_FUNCTION) { 92 // It's a function definition, not a function call. 93 return; 94 } 95 96 if ($tokens[$previous]['code'] === T_NEW) { 97 // We are creating an object, not calling a function. 98 return; 99 } 100 101 if (($stackPtr + 1) !== $next) { 102 // Checking this: $val = my_function[*](...). 103 $error = 'Space before opening parenthesis of function call prohibited'; 104 $phpcsFile->addError($error, $stackPtr); 105 } 106 107 if ($tokens[($next + 1)]['code'] === T_WHITESPACE) { 108 // Checking this: $val = my_function([*]...). 109 $error = 'Space after opening parenthesis of function call prohibited'; 110 $phpcsFile->addError($error, $stackPtr); 111 } 112 113 $closer = $tokens[$next]['parenthesis_closer']; 114 115 if ($tokens[($closer - 1)]['code'] === T_WHITESPACE) { 116 // Checking this: $val = my_function(...[*]). 117 $between = $phpcsFile->findNext(T_WHITESPACE, ($next + 1), null, true); 118 119 // Only throw an error if there is some content between the parenthesis. 120 // IE. Checking for this: $value = my_function(). 121 // If there is no content, then we would have thrown an error in the 122 // previous IF statement because it would look like this: 123 // $value = my_function( ). 124 if ($between !== $closer) { 125 $error = 'Space before closing parenthesis of function call prohibited'; 126 $phpcsFile->addError($error, $closer); 127 } 128 } 129 130 $next = $phpcsFile->findNext(T_WHITESPACE, ($closer + 1), null, true); 131 132 if ($tokens[$next]['code'] === T_SEMICOLON) { 133 if (in_array($tokens[($closer + 1)]['code'], PHP_CodeSniffer_Tokens::$emptyTokens) === true) { 134 $error = 'Space after closing parenthesis of function call prohibited'; 135 $phpcsFile->addError($error, $closer); 136 } 137 } 138 } 66 parent::process($phpcsFile, $stackPtr); 67 } 139 68 } 140 69 ?>
