1<?php 2/** 3 * Checks that the function call format is correct. 4 * 5 * @author Greg Sherwood <gsherwood@squiz.net> 6 * @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600) 7 * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence 8 */ 9 10namespace PHP_CodeSniffer\Standards\PSR2\Sniffs\Methods; 11 12use PHP_CodeSniffer\Files\File; 13use PHP_CodeSniffer\Standards\PEAR\Sniffs\Functions\FunctionCallSignatureSniff as PEARFunctionCallSignatureSniff; 14use PHP_CodeSniffer\Util\Tokens; 15 16class FunctionCallSignatureSniff extends PEARFunctionCallSignatureSniff 17{ 18 19 /** 20 * If TRUE, multiple arguments can be defined per line in a multi-line call. 21 * 22 * @var boolean 23 */ 24 public $allowMultipleArguments = false; 25 26 27 /** 28 * Processes single-line calls. 29 * 30 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. 31 * @param int $stackPtr The position of the current token 32 * in the stack passed in $tokens. 33 * @param int $openBracket The position of the opening bracket 34 * in the stack passed in $tokens. 35 * @param array $tokens The stack of tokens that make up 36 * the file. 37 * 38 * @return void 39 */ 40 public function isMultiLineCall(File $phpcsFile, $stackPtr, $openBracket, $tokens) 41 { 42 // If the first argument is on a new line, this is a multi-line 43 // function call, even if there is only one argument. 44 $next = $phpcsFile->findNext(Tokens::$emptyTokens, ($openBracket + 1), null, true); 45 if ($tokens[$next]['line'] !== $tokens[$stackPtr]['line']) { 46 return true; 47 } 48 49 $closeBracket = $tokens[$openBracket]['parenthesis_closer']; 50 51 $end = $phpcsFile->findEndOfStatement(($openBracket + 1), [T_COLON]); 52 while ($tokens[$end]['code'] === T_COMMA) { 53 // If the next bit of code is not on the same line, this is a 54 // multi-line function call. 55 $next = $phpcsFile->findNext(Tokens::$emptyTokens, ($end + 1), $closeBracket, true); 56 if ($next === false) { 57 return false; 58 } 59 60 if ($tokens[$next]['line'] !== $tokens[$end]['line']) { 61 return true; 62 } 63 64 $end = $phpcsFile->findEndOfStatement($next, [T_COLON]); 65 } 66 67 // We've reached the last argument, so see if the next content 68 // (should be the close bracket) is also on the same line. 69 $next = $phpcsFile->findNext(Tokens::$emptyTokens, ($end + 1), $closeBracket, true); 70 if ($next !== false && $tokens[$next]['line'] !== $tokens[$end]['line']) { 71 return true; 72 } 73 74 return false; 75 76 }//end isMultiLineCall() 77 78 79}//end class 80