Changeset 1173

Show
Ignore:
Timestamp:
12/21/07 17:42:37 (1 year ago)
Author:
richi
Message:

coding standards: updated & extended sniffs for PHP_CodeSniffer

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/org/stubbles/codeSniffer/stubbles/StubblesCodingStandard.php

    r1131 r1173  
    3333                'Generic/Sniffs/PHP/DisallowShortOpenTagSniff.php', 
    3434                'Generic/Sniffs/WhiteSpace/DisallowTabIndentSniff.php', 
     35                'Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php', 
    3536 
    3637                // PEAR 
    3738                'PEAR/Sniffs/Functions/FunctionCallArgumentSpacingSniff.php', 
    3839                'PEAR/Sniffs/Functions/ValidDefaultValueSniff.php', 
    39                 'PEAR/Sniffs/WhiteSpace/ScopeClosingBraceSniff.php', 
    40                 'PEAR/Sniffs/WhiteSpace/ScopeIndentSniff.php', 
    4140 
    4241                // Squiz 
     
    4645                'Squiz/Sniffs/Classes/LowercaseClassKeywordsSniff.php', 
    4746                'Squiz/Sniffs/Classes/SelfMemberReferenceSniff.php', 
    48               # 'Squiz/Sniffs/ControlStructures/SwitchDeclarationSniff.php', 
    4947                'Squiz/Sniffs/Commenting/BlockCommentSniff.php', 
    5048                'Squiz/Sniffs/Commenting/DocCommentAlignmentSniff.php', 
  • trunk/src/main/php/org/stubbles/codeSniffer/stubbles/sniffs/Functions/stubFunctionCallSignatureSniff.php

    r1131 r1173  
    22/** 
    33 * This sniff checks for whitespace in functions calls: 
    4  * 
    5  * Copied and adapted content from PEAR/Sniffs/Functions/FunctionCallSignatureSniff 
    6  * because of no extending possibility (no methods/attributes to overwrite). 
    74 * 
    85 * @package   Functions 
     
    3330 *                          'net.stubbles.bar.foo.bar); 
    3431 * 
    35  * 
    36  * Copied and adapted content from PEAR/Sniffs/Functions/FunctionCallSignatureSniff 
    37  * because of no extending possibility (no methods/attributes to overwrite). 
    38  * 
    3932 * @package   Functions 
    4033 */ 
    41 class Stubbles_Sniffs_Functions_stubFunctionCallSignatureSniff implements PHP_CodeSniffer_Sniff 
     34class Stubbles_Sniffs_Functions_stubFunctionCallSignatureSniff extends PEAR_Sniffs_Functions_FunctionCallSignatureSniff 
    4235{ 
    4336    /** 
     
    6457        $tokens = $phpcsFile->getTokens(); 
    6558 
    66         /* 
    67          * Stubbles 
    68          */ 
    6959        if ($tokens[$stackPtr-2]['content'] === 'stubClassLoader' && 
    7060            $tokens[$stackPtr-1]['content'] === '::' && 
     
    7464        } 
    7565 
    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   } 
    13968} 
    14069?>