cvs: pear /PHP_CodeSniffer package.xml /PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Functions FunctionDeclarationArgumentSpacingSniff.php
/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Functions FunctionDeclarationArgumentSpacingUnitTest.inc
FunctionDeclarationArgumentSpacingUnitTest.php

From: Date: Thu, 01 Mar 2007 00:47:47 +0000
Subject: cvs: pear /PHP_CodeSniffer package.xml /PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Functions FunctionDeclarationArgumentSpacingSniff.php
/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Functions FunctionDeclarationArgumentSpacingUnitTest.inc
FunctionDeclarationArgumentSpacingUnitTest.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-44917@lists.php.net to get a copy of this message
squiz Thu Mar 1 00:47:47 2007 UTC Modified files: /pear/PHP_CodeSniffer package.xml /pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Functions FunctionDeclarationArgumentSpacingSniff.php /pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Functions FunctionDeclarationArgumentSpacingUnitTest.inc FunctionDeclarationArgumentSpacingUnitTest.php Log: Fixed problems caused by references and type hints in Squiz FunctionDeclarationArgumentSpacingSniff

http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/package.xml?r1=1.38&r2=1.39&diff_format=u Index: pear/PHP_CodeSniffer/package.xml diff -u pear/PHP_CodeSniffer/package.xml:1.38 pear/PHP_CodeSniffer/package.xml:1.39 --- pear/PHP_CodeSniffer/package.xml:1.38 Wed Feb 28 05:58:01 2007 +++ pear/PHP_CodeSniffer/package.xml Thu Mar 1 00:47:47 2007 @@ -34,7 +34,9 @@ <notes> - Added MemberVarSpacingSniff to Squiz standard - Fixed undefined index error in AbstractVariableSniff for variables inside an interface function definition + - Fixed problems caused by references and type hints in Squiz FunctionDeclarationArgumentSpacingSniff - PHP_CodeSniffer_File::isReference() now correctly returns for references in function declarations + - PHP_CodeSniffer_File::isReference() now returns false if you don't pass it a T_BITWISE_AND token </notes> <contents> <dir name="/"> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Functions/FunctionDeclarationArgumentSpacingSniff.php?r1=1.4&r2=1.5&diff_format=u Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Functions/FunctionDeclarationArgumentSpacingSniff.php diff -u pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Functions/FunctionDeclarationArgumentSpacingSniff.php:1.4 pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Functions/FunctionDeclarationArgumentSpacingSniff.php:1.5 --- pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Functions/FunctionDeclarationArgumentSpacingSniff.php:1.4 Thu Jan 11 01:09:58 2007 +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Functions/FunctionDeclarationArgumentSpacingSniff.php Thu Mar 1 00:47:47 2007 @@ -10,7 +10,7 @@ * @author Marc McIntyre <mmcintyre@squiz.net> * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600) * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence - * @version CVS: $Id: FunctionDeclarationArgumentSpacingSniff.php,v 1.4 2007/01/11 01:09:58 squiz Exp $ + * @version CVS: $Id: FunctionDeclarationArgumentSpacingSniff.php,v 1.5 2007/03/01 00:47:47 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ @@ -126,35 +126,85 @@ } } - if ($params !== array()) { - if ($tokens[($nextParam - 1)]['code'] !== T_WHITESPACE) { - $arg = $tokens[$nextParam]['content']; - $error = "Expected 1 space between comma and argument \"$arg\"; 0 found"; - $phpcsFile->addError($error, $nextToken); - } else { - $space = $tokens[($nextParam - 1)]; - if (strlen($space['content']) !== 1) { - $gap = strlen($space['content']); - $arg = $tokens[$nextParam]['content']; - $error = "Expected 1 space between between comma and argument \"$arg\"; $gap found"; + // Take references into account when expecting the + // location of whitespace. + if ($phpcsFile->isReference($nextParam - 1) === true) { + $whitespace = $tokens[($nextParam - 2)]; + } else { + $whitespace = $tokens[($nextParam - 1)]; + } + + if (empty($params) === false) { + // This is not the first argument in the function declaration. + $arg = $tokens[$nextParam]['content']; + + if ($whitespace['code'] === T_WHITESPACE) { + $gap = strlen($whitespace['content']); + + // Before we throw an error, make sure there is no type hint. + $comma = $phpcsFile->findPrevious(T_COMMA, ($nextParam - 1)); + $nextToken = $phpcsFile->findNext(T_WHITESPACE, ($comma + 1), null, true); + if ($phpcsFile->isReference($nextToken) === true) { + $nextToken++; + } + + if ($nextToken !== $nextParam) { + // There was a type hint, so check the spacing between + // the hint and the variable as well. + $hint = $tokens[$nextToken]['content']; + + if ($gap !== 1) { + $error = "Expected 1 space between type hint and argument \"$arg\"; $gap found"; + $phpcsFile->addError($error, $nextToken); + } + + if ($tokens[($comma + 1)]['code'] !== T_WHITESPACE) { + $error = "Expected 1 space between comma and type hint \"$hint\"; 0 found"; + $phpcsFile->addError($error, $nextToken); + } else { + $gap = strlen($tokens[($comma + 1)]['content']); + if ($gap !== 1) { + $error = "Expected 1 space between comma and type hint \"$hint\"; $gap found"; + $phpcsFile->addError($error, $nextToken); + } + } + } else if ($gap !== 1) { + $error = "Expected 1 space between comma and argument \"$arg\"; $gap found"; $phpcsFile->addError($error, $nextToken); } + } else { + $error = "Expected 1 space between comma and argument \"$arg\"; 0 found"; + $phpcsFile->addError($error, $nextToken); } } else { - if ($tokens[($nextParam - 1)]['code'] === T_WHITESPACE) { - $gap = strlen($tokens[($nextParam - 1)]['content']); + // First argument in function declaration + if ($whitespace['code'] === T_WHITESPACE) { + $gap = strlen($whitespace['content']); $arg = $tokens[$nextParam]['content']; // Before we throw an error, make sure there is no type hint. - $bracket = $phpcsFile->findPrevious(T_OPEN_PARENTHESIS, ($nextParam - 1)); - if ($bracket === ($nextParam - 3)) { - // There was a type hint, so just check the spacing between - // the hint and the variable. + $bracket = $phpcsFile->findPrevious(T_OPEN_PARENTHESIS, ($nextParam - 1)); + $nextToken = $phpcsFile->findNext(T_WHITESPACE, ($bracket + 1), null, true); + if ($phpcsFile->isReference($nextToken) === true) { + $nextToken++; + } + + if ($nextToken !== $nextParam) { + // There was a type hint, so check the spacing between + // the hint and the variable as well. + $hint = $tokens[$nextToken]['content']; + if ($gap !== 1) { $error = "Expected 1 space between type hint and argument \"$arg\"; $gap found"; $phpcsFile->addError($error, $nextToken); } - } else { + + if ($tokens[($bracket + 1)]['code'] === T_WHITESPACE) { + $gap = strlen($tokens[($bracket + 1)]['content']); + $error = "Expected 0 spaces between opening bracket and type hint \"$hint\"; $gap found"; + $phpcsFile->addError($error, $nextToken); + } + } else { $error = "Expected 0 spaces between opening bracket and argument \"$arg\"; $gap found"; $phpcsFile->addError($error, $nextToken); } http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Functions/FunctionDeclarationArgumentSpacingUnitTest.inc?r1=1.2&r2=1.3&diff_format=u Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Functions/FunctionDeclarationArgumentSpacingUnitTest.inc diff -u pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Functions/FunctionDeclarationArgumentSpacingUnitTest.inc:1.2 pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Functions/FunctionDeclarationArgumentSpacingUnitTest.inc:1.3 --- pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Functions/FunctionDeclarationArgumentSpacingUnitTest.inc:1.2 Mon Jan 8 05:15:08 2007 +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Functions/FunctionDeclarationArgumentSpacingUnitTest.inc Thu Mar 1 00:47:47 2007 @@ -12,4 +12,8 @@ function myFunc(PHP_CodeSniffer $object, array $array=array(), $blah3='yo') {} function myFunc( $blah='hello' , $blah2= 'hi', $blah3 = 'yo' ) {} function myFunc(PHP_CodeSniffer $object, array $array=array(), $blah3='yo') {} +function myFunc( PHP_CodeSniffer $object, array $array=array(), $blah3='yo') {} +function myFunc( array &$one, array &$two) {} +function myFunc(&$blah) {} +function myFunc( &$blah ) {} ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Functions/FunctionDeclarationArgumentSpacingUnitTest.php?r1=1.3&r2=1.4&diff_format=u Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Functions/FunctionDeclarationArgumentSpacingUnitTest.php diff -u pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Functions/FunctionDeclarationArgumentSpacingUnitTest.php:1.3 pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Functions/FunctionDeclarationArgumentSpacingUnitTest.php:1.4 --- pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Functions/FunctionDeclarationArgumentSpacingUnitTest.php:1.3 Wed Jan 10 03:14:44 2007 +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Functions/FunctionDeclarationArgumentSpacingUnitTest.php Thu Mar 1 00:47:47 2007 @@ -10,7 +10,7 @@ * @author Marc McIntyre <mmcintyre@squiz.net> * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600) * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence - * @version CVS: $Id: FunctionDeclarationArgumentSpacingUnitTest.php,v 1.3 2007/01/10 03:14:44 squiz Exp $ + * @version CVS: $Id: FunctionDeclarationArgumentSpacingUnitTest.php,v 1.4 2007/03/01 00:47:47 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ @@ -52,6 +52,9 @@ 11 => 2, 13 => 7, 14 => 2, + 15 => 2, + 16 => 4, + 18 => 2, ); }//end getErrorList()
« previous php.pear.cvs (#44917) next »