function RequireConstructorPropertyPromotionSniff::getAssignment
1 call to RequireConstructorPropertyPromotionSniff::getAssignment()
- RequireConstructorPropertyPromotionSniff::process in vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ Classes/ RequireConstructorPropertyPromotionSniff.php - * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *
File
-
vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ Classes/ RequireConstructorPropertyPromotionSniff.php, line 234
Class
Namespace
SlevomatCodingStandard\Sniffs\ClassesCode
private function getAssignment(File $phpcsFile, int $constructorPointer, string $parameterName) : ?int {
$tokens = $phpcsFile->getTokens();
$parameterNameWithoutDollar = substr($parameterName, 1);
for ($i = $tokens[$constructorPointer]['scope_opener'] + 1; $i < $tokens[$constructorPointer]['scope_closer']; $i++) {
if ($tokens[$i]['content'] !== '$this') {
continue;
}
$objectOperatorPointer = TokenHelper::findNextEffective($phpcsFile, $i + 1);
if ($tokens[$objectOperatorPointer]['code'] !== T_OBJECT_OPERATOR) {
continue;
}
$namePointer = TokenHelper::findNextEffective($phpcsFile, $objectOperatorPointer + 1);
if ($tokens[$namePointer]['content'] !== $parameterNameWithoutDollar) {
continue;
}
$equalPointer = TokenHelper::findNextEffective($phpcsFile, $namePointer + 1);
if ($tokens[$equalPointer]['code'] !== T_EQUAL) {
continue;
}
$variablePointer = TokenHelper::findNextEffective($phpcsFile, $equalPointer + 1);
if ($tokens[$variablePointer]['content'] !== $parameterName) {
continue;
}
$semicolonPointer = TokenHelper::findNextEffective($phpcsFile, $variablePointer + 1);
if ($tokens[$semicolonPointer]['code'] !== T_SEMICOLON) {
continue;
}
foreach (array_reverse($tokens[$semicolonPointer]['conditions']) as $conditionTokenCode) {
if (in_array($conditionTokenCode, [
T_IF,
T_ELSEIF,
T_ELSE,
T_SWITCH,
], true)) {
return null;
}
}
return $i;
}
return null;
}