function ValidDefaultValueSniff::process
Processes this test, when one of its tokens is encountered.
Parameters
\PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.:
int $stackPtr The position of the current token in the: stack passed in $tokens.
Return value
void
Overrides Sniff::process
File
-
vendor/
squizlabs/ php_codesniffer/ src/ Standards/ PEAR/ Sniffs/ Functions/ ValidDefaultValueSniff.php, line 44
Class
Namespace
PHP_CodeSniffer\Standards\PEAR\Sniffs\FunctionsCode
public function process(File $phpcsFile, $stackPtr) {
// Flag for when we have found a default in our arg list.
// If there is a value without a default after this, it is an error.
$defaultFound = false;
$params = $phpcsFile->getMethodParameters($stackPtr);
foreach ($params as $param) {
if ($param['variable_length'] === true) {
continue;
}
if (array_key_exists('default', $param) === true) {
$defaultFound = true;
// Check if the arg is type hinted and using NULL for the default.
// This does not make the argument optional - it just allows NULL
// to be passed in.
if ($param['type_hint'] !== '' && strtolower($param['default']) === 'null') {
$defaultFound = false;
}
continue;
}
if ($defaultFound === true) {
$error = 'Arguments with default values must be at the end of the argument list';
$phpcsFile->addError($error, $param['token'], 'NotAtEnd');
return;
}
}
//end foreach
}