diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8d659b18..88543fb5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -56,7 +56,7 @@ jobs: with: repository: "phpstan/build-cs" path: "build-cs" - ref: "1.x" + ref: "2.x" - name: "Install PHP" uses: "shivammathur/setup-php@v2" diff --git a/Makefile b/Makefile index 90e23ba0..b2b6703a 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ lint: .PHONY: cs-install cs-install: git clone https://github.com/phpstan/build-cs.git || true - git -C build-cs fetch origin && git -C build-cs reset --hard origin/1.x + git -C build-cs fetch origin && git -C build-cs reset --hard origin/2.x composer install --working-dir build-cs .PHONY: cs diff --git a/src/Rules/BooleansInConditions/BooleanInBooleanAndRule.php b/src/Rules/BooleansInConditions/BooleanInBooleanAndRule.php index aebe8add..a3055694 100644 --- a/src/Rules/BooleansInConditions/BooleanInBooleanAndRule.php +++ b/src/Rules/BooleansInConditions/BooleanInBooleanAndRule.php @@ -16,11 +16,9 @@ class BooleanInBooleanAndRule implements Rule { - /** @var BooleanRuleHelper */ - private $helper; + private BooleanRuleHelper $helper; - /** @var bool */ - private $bleedingEdge; + private bool $bleedingEdge; public function __construct(BooleanRuleHelper $helper, bool $bleedingEdge) { @@ -44,7 +42,7 @@ public function processNode(Node $node, Scope $scope): array $messages[] = RuleErrorBuilder::message(sprintf( 'Only booleans are allowed in %s, %s given on the left side.', $nodeText, - $leftType->describe(VerbosityLevel::typeOnly()) + $leftType->describe(VerbosityLevel::typeOnly()), ))->identifier(sprintf('%s.leftNotBoolean', $identifierType))->build(); } @@ -54,7 +52,7 @@ public function processNode(Node $node, Scope $scope): array $messages[] = RuleErrorBuilder::message(sprintf( 'Only booleans are allowed in %s, %s given on the right side.', $nodeText, - $rightType->describe(VerbosityLevel::typeOnly()) + $rightType->describe(VerbosityLevel::typeOnly()), ))->identifier(sprintf('%s.rightNotBoolean', $identifierType))->build(); } diff --git a/src/Rules/BooleansInConditions/BooleanInBooleanNotRule.php b/src/Rules/BooleansInConditions/BooleanInBooleanNotRule.php index 6fcdd06c..5187cf57 100644 --- a/src/Rules/BooleansInConditions/BooleanInBooleanNotRule.php +++ b/src/Rules/BooleansInConditions/BooleanInBooleanNotRule.php @@ -16,8 +16,7 @@ class BooleanInBooleanNotRule implements Rule { - /** @var BooleanRuleHelper */ - private $helper; + private BooleanRuleHelper $helper; public function __construct(BooleanRuleHelper $helper) { @@ -40,7 +39,7 @@ public function processNode(Node $node, Scope $scope): array return [ RuleErrorBuilder::message(sprintf( 'Only booleans are allowed in a negated boolean, %s given.', - $expressionType->describe(VerbosityLevel::typeOnly()) + $expressionType->describe(VerbosityLevel::typeOnly()), ))->identifier('booleanNot.exprNotBoolean')->build(), ]; } diff --git a/src/Rules/BooleansInConditions/BooleanInBooleanOrRule.php b/src/Rules/BooleansInConditions/BooleanInBooleanOrRule.php index e03911cf..d0b91dd1 100644 --- a/src/Rules/BooleansInConditions/BooleanInBooleanOrRule.php +++ b/src/Rules/BooleansInConditions/BooleanInBooleanOrRule.php @@ -16,11 +16,9 @@ class BooleanInBooleanOrRule implements Rule { - /** @var BooleanRuleHelper */ - private $helper; + private BooleanRuleHelper $helper; - /** @var bool */ - private $bleedingEdge; + private bool $bleedingEdge; public function __construct(BooleanRuleHelper $helper, bool $bleedingEdge) { @@ -44,7 +42,7 @@ public function processNode(Node $node, Scope $scope): array $messages[] = RuleErrorBuilder::message(sprintf( 'Only booleans are allowed in %s, %s given on the left side.', $nodeText, - $leftType->describe(VerbosityLevel::typeOnly()) + $leftType->describe(VerbosityLevel::typeOnly()), ))->identifier(sprintf('%s.leftNotBoolean', $identifierType))->build(); } @@ -54,7 +52,7 @@ public function processNode(Node $node, Scope $scope): array $messages[] = RuleErrorBuilder::message(sprintf( 'Only booleans are allowed in %s, %s given on the right side.', $nodeText, - $rightType->describe(VerbosityLevel::typeOnly()) + $rightType->describe(VerbosityLevel::typeOnly()), ))->identifier(sprintf('%s.rightNotBoolean', $identifierType))->build(); } diff --git a/src/Rules/BooleansInConditions/BooleanInElseIfConditionRule.php b/src/Rules/BooleansInConditions/BooleanInElseIfConditionRule.php index 2501b828..550e9857 100644 --- a/src/Rules/BooleansInConditions/BooleanInElseIfConditionRule.php +++ b/src/Rules/BooleansInConditions/BooleanInElseIfConditionRule.php @@ -16,8 +16,7 @@ class BooleanInElseIfConditionRule implements Rule { - /** @var BooleanRuleHelper */ - private $helper; + private BooleanRuleHelper $helper; public function __construct(BooleanRuleHelper $helper) { @@ -40,7 +39,7 @@ public function processNode(Node $node, Scope $scope): array return [ RuleErrorBuilder::message(sprintf( 'Only booleans are allowed in an elseif condition, %s given.', - $conditionExpressionType->describe(VerbosityLevel::typeOnly()) + $conditionExpressionType->describe(VerbosityLevel::typeOnly()), ))->identifier('elseif.condNotBoolean')->build(), ]; } diff --git a/src/Rules/BooleansInConditions/BooleanInIfConditionRule.php b/src/Rules/BooleansInConditions/BooleanInIfConditionRule.php index 5adb10ed..5c08894b 100644 --- a/src/Rules/BooleansInConditions/BooleanInIfConditionRule.php +++ b/src/Rules/BooleansInConditions/BooleanInIfConditionRule.php @@ -16,8 +16,7 @@ class BooleanInIfConditionRule implements Rule { - /** @var BooleanRuleHelper */ - private $helper; + private BooleanRuleHelper $helper; public function __construct(BooleanRuleHelper $helper) { @@ -40,7 +39,7 @@ public function processNode(Node $node, Scope $scope): array return [ RuleErrorBuilder::message(sprintf( 'Only booleans are allowed in an if condition, %s given.', - $conditionExpressionType->describe(VerbosityLevel::typeOnly()) + $conditionExpressionType->describe(VerbosityLevel::typeOnly()), ))->identifier('if.condNotBoolean')->build(), ]; } diff --git a/src/Rules/BooleansInConditions/BooleanInTernaryOperatorRule.php b/src/Rules/BooleansInConditions/BooleanInTernaryOperatorRule.php index e1ac9ccb..4fe855a5 100644 --- a/src/Rules/BooleansInConditions/BooleanInTernaryOperatorRule.php +++ b/src/Rules/BooleansInConditions/BooleanInTernaryOperatorRule.php @@ -16,8 +16,7 @@ class BooleanInTernaryOperatorRule implements Rule { - /** @var BooleanRuleHelper */ - private $helper; + private BooleanRuleHelper $helper; public function __construct(BooleanRuleHelper $helper) { @@ -44,7 +43,7 @@ public function processNode(Node $node, Scope $scope): array return [ RuleErrorBuilder::message(sprintf( 'Only booleans are allowed in a ternary operator condition, %s given.', - $conditionExpressionType->describe(VerbosityLevel::typeOnly()) + $conditionExpressionType->describe(VerbosityLevel::typeOnly()), ))->identifier('ternary.condNotBoolean')->build(), ]; } diff --git a/src/Rules/BooleansInConditions/BooleanRuleHelper.php b/src/Rules/BooleansInConditions/BooleanRuleHelper.php index 1e307d63..4ecba329 100644 --- a/src/Rules/BooleansInConditions/BooleanRuleHelper.php +++ b/src/Rules/BooleansInConditions/BooleanRuleHelper.php @@ -12,8 +12,7 @@ class BooleanRuleHelper { - /** @var RuleLevelHelper */ - private $ruleLevelHelper; + private RuleLevelHelper $ruleLevelHelper; public function __construct(RuleLevelHelper $ruleLevelHelper) { @@ -30,9 +29,7 @@ public function passesAsBoolean(Scope $scope, Expr $expr): bool $scope, $expr, '', - static function (Type $type): bool { - return $type->isBoolean()->yes(); - } + static fn (Type $type): bool => $type->isBoolean()->yes(), ); $foundType = $typeToCheck->getType(); if ($foundType instanceof ErrorType) { diff --git a/src/Rules/Cast/UselessCastRule.php b/src/Rules/Cast/UselessCastRule.php index adc20e14..e2ea72b5 100644 --- a/src/Rules/Cast/UselessCastRule.php +++ b/src/Rules/Cast/UselessCastRule.php @@ -18,8 +18,7 @@ class UselessCastRule implements Rule { - /** @var bool */ - private $treatPhpDocTypesAsCertain; + private bool $treatPhpDocTypesAsCertain; public function __construct(bool $treatPhpDocTypesAsCertain) { @@ -61,7 +60,7 @@ public function processNode(Node $node, Scope $scope): array $addTip(RuleErrorBuilder::message(sprintf( 'Casting to %s something that\'s already %s.', $castType->describe(VerbosityLevel::typeOnly()), - $expressionType->describe(VerbosityLevel::typeOnly()) + $expressionType->describe(VerbosityLevel::typeOnly()), )))->identifier('cast.useless')->build(), ]; } diff --git a/src/Rules/Classes/RequireParentConstructCallRule.php b/src/Rules/Classes/RequireParentConstructCallRule.php index 76d3d16c..31b2faf5 100644 --- a/src/Rules/Classes/RequireParentConstructCallRule.php +++ b/src/Rules/Classes/RequireParentConstructCallRule.php @@ -59,7 +59,7 @@ public function processNode(Node $node, Scope $scope): array RuleErrorBuilder::message(sprintf( '%s::__construct() does not call parent constructor from %s.', $classReflection->getName(), - $parentClass->getName() + $parentClass->getName(), ))->identifier('constructor.missingParentCall')->build(), ]; } diff --git a/src/Rules/DisallowedConstructs/DisallowedLooseComparisonRule.php b/src/Rules/DisallowedConstructs/DisallowedLooseComparisonRule.php index 9b709be9..70b8514f 100644 --- a/src/Rules/DisallowedConstructs/DisallowedLooseComparisonRule.php +++ b/src/Rules/DisallowedConstructs/DisallowedLooseComparisonRule.php @@ -26,7 +26,7 @@ public function processNode(Node $node, Scope $scope): array if ($node instanceof Equal) { return [ RuleErrorBuilder::message( - 'Loose comparison via "==" is not allowed.' + 'Loose comparison via "==" is not allowed.', )->tip('Use strict comparison via "===" instead.') ->identifier('equal.notAllowed') ->build(), @@ -35,7 +35,7 @@ public function processNode(Node $node, Scope $scope): array if ($node instanceof NotEqual) { return [ RuleErrorBuilder::message( - 'Loose comparison via "!=" is not allowed.' + 'Loose comparison via "!=" is not allowed.', )->tip('Use strict comparison via "!==" instead.') ->identifier('notEqual.notAllowed') ->build(), diff --git a/src/Rules/Functions/ArrayFilterStrictRule.php b/src/Rules/Functions/ArrayFilterStrictRule.php index ff3bf631..65e1fada 100644 --- a/src/Rules/Functions/ArrayFilterStrictRule.php +++ b/src/Rules/Functions/ArrayFilterStrictRule.php @@ -23,14 +23,11 @@ class ArrayFilterStrictRule implements Rule { - /** @var ReflectionProvider */ - private $reflectionProvider; + private ReflectionProvider $reflectionProvider; - /** @var bool */ - private $treatPhpDocTypesAsCertain; + private bool $treatPhpDocTypesAsCertain; - /** @var bool */ - private $checkNullables; + private bool $checkNullables; public function __construct( ReflectionProvider $reflectionProvider, @@ -68,7 +65,7 @@ public function processNode(Node $node, Scope $scope): array $scope, $node->getArgs(), $functionReflection->getVariants(), - $functionReflection->getNamedArgumentsVariants() + $functionReflection->getNamedArgumentsVariants(), ); $normalizedFuncCall = ArgumentsNormalizer::reorderFuncArguments($parametersAcceptor, $node); @@ -132,7 +129,7 @@ public function processNode(Node $node, Scope $scope): array $message = 'Parameter #2 of array_filter() cannot be null to avoid loose comparison semantics (%s given).'; $errorBuilder = RuleErrorBuilder::message(sprintf( $message, - $callbackType->describe(VerbosityLevel::typeOnly()) + $callbackType->describe(VerbosityLevel::typeOnly()), ))->identifier('arrayFilter.strict'); if (!$this->isCallbackTypeNull($nativeCallbackType) && $this->treatPhpDocTypesAsCertain) { diff --git a/src/Rules/Methods/WrongCaseOfInheritedMethodRule.php b/src/Rules/Methods/WrongCaseOfInheritedMethodRule.php index 1cca26ed..5f800e50 100644 --- a/src/Rules/Methods/WrongCaseOfInheritedMethodRule.php +++ b/src/Rules/Methods/WrongCaseOfInheritedMethodRule.php @@ -35,7 +35,7 @@ public function processNode( $parentMessage = $this->findMethod( $declaringClass, $declaringClass->getParentClass(), - $methodReflection->getName() + $methodReflection->getName(), ); if ($parentMessage !== null) { $messages[] = $parentMessage; @@ -46,7 +46,7 @@ public function processNode( $interfaceMessage = $this->findMethod( $declaringClass, $interface, - $methodReflection->getName() + $methodReflection->getName(), ); if ($interfaceMessage === null) { continue; @@ -79,7 +79,7 @@ private function findMethod( $methodName, $classReflection->isInterface() ? 'interface' : 'parent', $classReflection->getDisplayName(), - $parentMethod->getName() + $parentMethod->getName(), ))->identifier('method.nameCase')->build(); } diff --git a/src/Rules/Operators/OperandInArithmeticIncrementOrDecrementRule.php b/src/Rules/Operators/OperandInArithmeticIncrementOrDecrementRule.php index af82a08c..4e87a885 100644 --- a/src/Rules/Operators/OperandInArithmeticIncrementOrDecrementRule.php +++ b/src/Rules/Operators/OperandInArithmeticIncrementOrDecrementRule.php @@ -20,8 +20,7 @@ abstract class OperandInArithmeticIncrementOrDecrementRule implements Rule { - /** @var OperatorRuleHelper */ - private $helper; + private OperatorRuleHelper $helper; public function __construct(OperatorRuleHelper $helper) { @@ -45,7 +44,7 @@ public function processNode(Node $node, Scope $scope): array $messages[] = RuleErrorBuilder::message(sprintf( 'Only numeric types are allowed in %s, %s given.', $this->describeOperation(), - $varType->describe(VerbosityLevel::typeOnly()) + $varType->describe(VerbosityLevel::typeOnly()), ))->identifier(sprintf('%s.nonNumeric', $this->getIdentifier()))->build(); } diff --git a/src/Rules/Operators/OperandsInArithmeticAdditionRule.php b/src/Rules/Operators/OperandsInArithmeticAdditionRule.php index 246b609d..fd4b119c 100644 --- a/src/Rules/Operators/OperandsInArithmeticAdditionRule.php +++ b/src/Rules/Operators/OperandsInArithmeticAdditionRule.php @@ -19,11 +19,9 @@ class OperandsInArithmeticAdditionRule implements Rule { - /** @var OperatorRuleHelper */ - private $helper; + private OperatorRuleHelper $helper; - /** @var bool */ - private $bleedingEdge; + private bool $bleedingEdge; public function __construct(OperatorRuleHelper $helper, bool $bleedingEdge) { @@ -58,13 +56,13 @@ public function processNode(Node $node, Scope $scope): array if (!$this->helper->isValidForArithmeticOperation($scope, $left)) { $messages[] = RuleErrorBuilder::message(sprintf( 'Only numeric types are allowed in +, %s given on the left side.', - $leftType->describe(VerbosityLevel::typeOnly()) + $leftType->describe(VerbosityLevel::typeOnly()), ))->identifier('plus.leftNonNumeric')->build(); } if (!$this->helper->isValidForArithmeticOperation($scope, $right)) { $messages[] = RuleErrorBuilder::message(sprintf( 'Only numeric types are allowed in +, %s given on the right side.', - $rightType->describe(VerbosityLevel::typeOnly()) + $rightType->describe(VerbosityLevel::typeOnly()), ))->identifier('plus.rightNonNumeric')->build(); } diff --git a/src/Rules/Operators/OperandsInArithmeticDivisionRule.php b/src/Rules/Operators/OperandsInArithmeticDivisionRule.php index 8a146ded..642d6e8e 100644 --- a/src/Rules/Operators/OperandsInArithmeticDivisionRule.php +++ b/src/Rules/Operators/OperandsInArithmeticDivisionRule.php @@ -18,11 +18,9 @@ class OperandsInArithmeticDivisionRule implements Rule { - /** @var OperatorRuleHelper */ - private $helper; + private OperatorRuleHelper $helper; - /** @var bool */ - private $bleedingEdge; + private bool $bleedingEdge; public function __construct(OperatorRuleHelper $helper, bool $bleedingEdge) { @@ -52,7 +50,7 @@ public function processNode(Node $node, Scope $scope): array if (!$this->helper->isValidForArithmeticOperation($scope, $left)) { $messages[] = RuleErrorBuilder::message(sprintf( 'Only numeric types are allowed in /, %s given on the left side.', - $leftType->describe(VerbosityLevel::typeOnly()) + $leftType->describe(VerbosityLevel::typeOnly()), ))->identifier('div.leftNonNumeric')->build(); } @@ -60,7 +58,7 @@ public function processNode(Node $node, Scope $scope): array if (!$this->helper->isValidForArithmeticOperation($scope, $right)) { $messages[] = RuleErrorBuilder::message(sprintf( 'Only numeric types are allowed in /, %s given on the right side.', - $rightType->describe(VerbosityLevel::typeOnly()) + $rightType->describe(VerbosityLevel::typeOnly()), ))->identifier('div.rightNonNumeric')->build(); } diff --git a/src/Rules/Operators/OperandsInArithmeticExponentiationRule.php b/src/Rules/Operators/OperandsInArithmeticExponentiationRule.php index fe809ef7..128194ce 100644 --- a/src/Rules/Operators/OperandsInArithmeticExponentiationRule.php +++ b/src/Rules/Operators/OperandsInArithmeticExponentiationRule.php @@ -18,11 +18,9 @@ class OperandsInArithmeticExponentiationRule implements Rule { - /** @var OperatorRuleHelper */ - private $helper; + private OperatorRuleHelper $helper; - /** @var bool */ - private $bleedingEdge; + private bool $bleedingEdge; public function __construct(OperatorRuleHelper $helper, bool $bleedingEdge) { @@ -52,7 +50,7 @@ public function processNode(Node $node, Scope $scope): array if (!$this->helper->isValidForArithmeticOperation($scope, $left)) { $messages[] = RuleErrorBuilder::message(sprintf( 'Only numeric types are allowed in **, %s given on the left side.', - $leftType->describe(VerbosityLevel::typeOnly()) + $leftType->describe(VerbosityLevel::typeOnly()), ))->identifier('pow.leftNonNumeric')->build(); } @@ -60,7 +58,7 @@ public function processNode(Node $node, Scope $scope): array if (!$this->helper->isValidForArithmeticOperation($scope, $right)) { $messages[] = RuleErrorBuilder::message(sprintf( 'Only numeric types are allowed in **, %s given on the right side.', - $rightType->describe(VerbosityLevel::typeOnly()) + $rightType->describe(VerbosityLevel::typeOnly()), ))->identifier('pow.rightNonNumeric')->build(); } diff --git a/src/Rules/Operators/OperandsInArithmeticModuloRule.php b/src/Rules/Operators/OperandsInArithmeticModuloRule.php index 4aad3661..a687c05e 100644 --- a/src/Rules/Operators/OperandsInArithmeticModuloRule.php +++ b/src/Rules/Operators/OperandsInArithmeticModuloRule.php @@ -18,11 +18,9 @@ class OperandsInArithmeticModuloRule implements Rule { - /** @var OperatorRuleHelper */ - private $helper; + private OperatorRuleHelper $helper; - /** @var bool */ - private $bleedingEdge; + private bool $bleedingEdge; public function __construct(OperatorRuleHelper $helper, bool $bleedingEdge) { @@ -52,7 +50,7 @@ public function processNode(Node $node, Scope $scope): array if (!$this->helper->isValidForArithmeticOperation($scope, $left)) { $messages[] = RuleErrorBuilder::message(sprintf( 'Only numeric types are allowed in %%, %s given on the left side.', - $leftType->describe(VerbosityLevel::typeOnly()) + $leftType->describe(VerbosityLevel::typeOnly()), ))->identifier('mod.leftNonNumeric')->build(); } @@ -60,7 +58,7 @@ public function processNode(Node $node, Scope $scope): array if (!$this->helper->isValidForArithmeticOperation($scope, $right)) { $messages[] = RuleErrorBuilder::message(sprintf( 'Only numeric types are allowed in %%, %s given on the right side.', - $rightType->describe(VerbosityLevel::typeOnly()) + $rightType->describe(VerbosityLevel::typeOnly()), ))->identifier('mod.rightNonNumeric')->build(); } diff --git a/src/Rules/Operators/OperandsInArithmeticMultiplicationRule.php b/src/Rules/Operators/OperandsInArithmeticMultiplicationRule.php index f662bdce..e7e055b9 100644 --- a/src/Rules/Operators/OperandsInArithmeticMultiplicationRule.php +++ b/src/Rules/Operators/OperandsInArithmeticMultiplicationRule.php @@ -18,11 +18,9 @@ class OperandsInArithmeticMultiplicationRule implements Rule { - /** @var OperatorRuleHelper */ - private $helper; + private OperatorRuleHelper $helper; - /** @var bool */ - private $bleedingEdge; + private bool $bleedingEdge; public function __construct(OperatorRuleHelper $helper, bool $bleedingEdge) { @@ -52,7 +50,7 @@ public function processNode(Node $node, Scope $scope): array if (!$this->helper->isValidForArithmeticOperation($scope, $left)) { $messages[] = RuleErrorBuilder::message(sprintf( 'Only numeric types are allowed in *, %s given on the left side.', - $leftType->describe(VerbosityLevel::typeOnly()) + $leftType->describe(VerbosityLevel::typeOnly()), ))->identifier('mul.leftNonNumeric')->build(); } @@ -60,7 +58,7 @@ public function processNode(Node $node, Scope $scope): array if (!$this->helper->isValidForArithmeticOperation($scope, $right)) { $messages[] = RuleErrorBuilder::message(sprintf( 'Only numeric types are allowed in *, %s given on the right side.', - $rightType->describe(VerbosityLevel::typeOnly()) + $rightType->describe(VerbosityLevel::typeOnly()), ))->identifier('mul.rightNonNumeric')->build(); } diff --git a/src/Rules/Operators/OperandsInArithmeticSubtractionRule.php b/src/Rules/Operators/OperandsInArithmeticSubtractionRule.php index 9bec287d..527f645b 100644 --- a/src/Rules/Operators/OperandsInArithmeticSubtractionRule.php +++ b/src/Rules/Operators/OperandsInArithmeticSubtractionRule.php @@ -18,11 +18,9 @@ class OperandsInArithmeticSubtractionRule implements Rule { - /** @var OperatorRuleHelper */ - private $helper; + private OperatorRuleHelper $helper; - /** @var bool */ - private $bleedingEdge; + private bool $bleedingEdge; public function __construct(OperatorRuleHelper $helper, bool $bleedingEdge) { @@ -52,7 +50,7 @@ public function processNode(Node $node, Scope $scope): array if (!$this->helper->isValidForArithmeticOperation($scope, $left)) { $messages[] = RuleErrorBuilder::message(sprintf( 'Only numeric types are allowed in -, %s given on the left side.', - $leftType->describe(VerbosityLevel::typeOnly()) + $leftType->describe(VerbosityLevel::typeOnly()), ))->identifier('minus.leftNonNumeric')->build(); } @@ -60,7 +58,7 @@ public function processNode(Node $node, Scope $scope): array if (!$this->helper->isValidForArithmeticOperation($scope, $right)) { $messages[] = RuleErrorBuilder::message(sprintf( 'Only numeric types are allowed in -, %s given on the right side.', - $rightType->describe(VerbosityLevel::typeOnly()) + $rightType->describe(VerbosityLevel::typeOnly()), ))->identifier('minus.rightNonNumeric')->build(); } diff --git a/src/Rules/Operators/OperatorRuleHelper.php b/src/Rules/Operators/OperatorRuleHelper.php index 28902857..6de54cab 100644 --- a/src/Rules/Operators/OperatorRuleHelper.php +++ b/src/Rules/Operators/OperatorRuleHelper.php @@ -19,8 +19,7 @@ class OperatorRuleHelper { - /** @var RuleLevelHelper */ - private $ruleLevelHelper; + private RuleLevelHelper $ruleLevelHelper; public function __construct(RuleLevelHelper $ruleLevelHelper) { @@ -75,9 +74,7 @@ private function isSubtypeOfNumber(Scope $scope, Expr $expr): bool $scope, $expr, '', - static function (Type $type) use ($acceptedType): bool { - return $acceptedType->isSuperTypeOf($type)->yes(); - } + static fn (Type $type): bool => $acceptedType->isSuperTypeOf($type)->yes(), )->getType(); if ($type instanceof ErrorType) { diff --git a/src/Rules/StrictCalls/DynamicCallOnStaticMethodsCallableRule.php b/src/Rules/StrictCalls/DynamicCallOnStaticMethodsCallableRule.php index d14b5678..492aa604 100644 --- a/src/Rules/StrictCalls/DynamicCallOnStaticMethodsCallableRule.php +++ b/src/Rules/StrictCalls/DynamicCallOnStaticMethodsCallableRule.php @@ -18,8 +18,7 @@ class DynamicCallOnStaticMethodsCallableRule implements Rule { - /** @var RuleLevelHelper */ - private $ruleLevelHelper; + private RuleLevelHelper $ruleLevelHelper; public function __construct(RuleLevelHelper $ruleLevelHelper) { @@ -42,9 +41,7 @@ public function processNode(Node $node, Scope $scope): array $scope, $node->getVar(), '', - static function (Type $type) use ($name): bool { - return $type->canCallMethods()->yes() && $type->hasMethod($name)->yes(); - } + static fn (Type $type): bool => $type->canCallMethods()->yes() && $type->hasMethod($name)->yes(), )->getType(); if ($type instanceof ErrorType || !$type->canCallMethods()->yes() || !$type->hasMethod($name)->yes()) { @@ -57,7 +54,7 @@ static function (Type $type) use ($name): bool { RuleErrorBuilder::message(sprintf( 'Dynamic call to static method %s::%s().', $methodReflection->getDeclaringClass()->getDisplayName(), - $methodReflection->getName() + $methodReflection->getName(), ))->identifier('staticMethod.dynamicCall')->build(), ]; } diff --git a/src/Rules/StrictCalls/DynamicCallOnStaticMethodsRule.php b/src/Rules/StrictCalls/DynamicCallOnStaticMethodsRule.php index 44b180c0..c0ae18b3 100644 --- a/src/Rules/StrictCalls/DynamicCallOnStaticMethodsRule.php +++ b/src/Rules/StrictCalls/DynamicCallOnStaticMethodsRule.php @@ -21,8 +21,7 @@ class DynamicCallOnStaticMethodsRule implements Rule { - /** @var RuleLevelHelper */ - private $ruleLevelHelper; + private RuleLevelHelper $ruleLevelHelper; public function __construct(RuleLevelHelper $ruleLevelHelper) { @@ -45,9 +44,7 @@ public function processNode(Node $node, Scope $scope): array $scope, $node->var, '', - static function (Type $type) use ($name): bool { - return $type->canCallMethods()->yes() && $type->hasMethod($name)->yes(); - } + static fn (Type $type): bool => $type->canCallMethods()->yes() && $type->hasMethod($name)->yes(), )->getType(); if ($type instanceof ErrorType || !$type->canCallMethods()->yes() || !$type->hasMethod($name)->yes()) { @@ -68,7 +65,7 @@ static function (Type $type) use ($name): bool { RuleErrorBuilder::message(sprintf( 'Dynamic call to static method %s::%s().', $methodReflection->getDeclaringClass()->getDisplayName(), - $methodReflection->getName() + $methodReflection->getName(), ))->identifier('staticMethod.dynamicCall')->build(), ]; } diff --git a/src/Rules/StrictCalls/StrictFunctionCallsRule.php b/src/Rules/StrictCalls/StrictFunctionCallsRule.php index 2ae134b3..f959fc91 100644 --- a/src/Rules/StrictCalls/StrictFunctionCallsRule.php +++ b/src/Rules/StrictCalls/StrictFunctionCallsRule.php @@ -23,15 +23,14 @@ class StrictFunctionCallsRule implements Rule { /** @var int[] */ - private $functionArguments = [ + private array $functionArguments = [ 'in_array' => 2, 'array_search' => 2, 'base64_decode' => 1, 'array_keys' => 2, ]; - /** @var ReflectionProvider */ - private $reflectionProvider; + private ReflectionProvider $reflectionProvider; public function __construct(ReflectionProvider $reflectionProvider) { @@ -74,7 +73,7 @@ public function processNode(Node $node, Scope $scope): array RuleErrorBuilder::message(sprintf( 'Call to function %s() requires parameter #%d to be set.', $functionName, - $argumentPosition + 1 + $argumentPosition + 1, ))->identifier('function.strict')->build(), ]; } @@ -86,7 +85,7 @@ public function processNode(Node $node, Scope $scope): array RuleErrorBuilder::message(sprintf( 'Call to function %s() requires parameter #%d to be true.', $functionName, - $argumentPosition + 1 + $argumentPosition + 1, ))->identifier('function.strict')->build(), ]; } diff --git a/src/Rules/SwitchConditions/MatchingTypeInSwitchCaseConditionRule.php b/src/Rules/SwitchConditions/MatchingTypeInSwitchCaseConditionRule.php index e52195a1..ded5d345 100644 --- a/src/Rules/SwitchConditions/MatchingTypeInSwitchCaseConditionRule.php +++ b/src/Rules/SwitchConditions/MatchingTypeInSwitchCaseConditionRule.php @@ -17,8 +17,7 @@ class MatchingTypeInSwitchCaseConditionRule implements Rule { - /** @var Standard */ - private $printer; + private Standard $printer; public function __construct(Standard $printer) { @@ -48,7 +47,7 @@ public function processNode(Node $node, Scope $scope): array 'Switch condition type (%s) does not match case condition %s (%s).', $conditionType->describe(VerbosityLevel::value()), $this->printer->prettyPrintExpr($case->cond), - $caseType->describe(VerbosityLevel::typeOnly()) + $caseType->describe(VerbosityLevel::typeOnly()), )) ->line($case->getLine()) ->identifier('switch.type') diff --git a/src/Rules/VariableVariables/VariableMethodCallRule.php b/src/Rules/VariableVariables/VariableMethodCallRule.php index f92f84c1..d55fc789 100644 --- a/src/Rules/VariableVariables/VariableMethodCallRule.php +++ b/src/Rules/VariableVariables/VariableMethodCallRule.php @@ -30,7 +30,7 @@ public function processNode(Node $node, Scope $scope): array return [ RuleErrorBuilder::message(sprintf( 'Variable method call on %s.', - $scope->getType($node->var)->describe(VerbosityLevel::typeOnly()) + $scope->getType($node->var)->describe(VerbosityLevel::typeOnly()), ))->identifier('method.dynamicName')->build(), ]; } diff --git a/src/Rules/VariableVariables/VariableMethodCallableRule.php b/src/Rules/VariableVariables/VariableMethodCallableRule.php index 6a5fd518..dd891a9e 100644 --- a/src/Rules/VariableVariables/VariableMethodCallableRule.php +++ b/src/Rules/VariableVariables/VariableMethodCallableRule.php @@ -30,7 +30,7 @@ public function processNode(Node $node, Scope $scope): array return [ RuleErrorBuilder::message(sprintf( 'Variable method call on %s.', - $scope->getType($node->getVar())->describe(VerbosityLevel::typeOnly()) + $scope->getType($node->getVar())->describe(VerbosityLevel::typeOnly()), ))->identifier('method.dynamicName')->build(), ]; } diff --git a/src/Rules/VariableVariables/VariablePropertyFetchRule.php b/src/Rules/VariableVariables/VariablePropertyFetchRule.php index 73ff0888..07c35f26 100644 --- a/src/Rules/VariableVariables/VariablePropertyFetchRule.php +++ b/src/Rules/VariableVariables/VariablePropertyFetchRule.php @@ -18,11 +18,10 @@ class VariablePropertyFetchRule implements Rule { - /** @var ReflectionProvider */ - private $reflectionProvider; + private ReflectionProvider $reflectionProvider; /** @var string[] */ - private $universalObjectCratesClasses; + private array $universalObjectCratesClasses; /** * @param string[] $universalObjectCratesClasses @@ -58,7 +57,7 @@ public function processNode(Node $node, Scope $scope): array return [ RuleErrorBuilder::message(sprintf( 'Variable property access on %s.', - $fetchedOnType->describe(VerbosityLevel::typeOnly()) + $fetchedOnType->describe(VerbosityLevel::typeOnly()), ))->identifier('property.dynamicName')->build(), ]; } diff --git a/src/Rules/VariableVariables/VariableStaticMethodCallRule.php b/src/Rules/VariableVariables/VariableStaticMethodCallRule.php index eb3a770c..963f01d0 100644 --- a/src/Rules/VariableVariables/VariableStaticMethodCallRule.php +++ b/src/Rules/VariableVariables/VariableStaticMethodCallRule.php @@ -36,7 +36,7 @@ public function processNode(Node $node, Scope $scope): array return [ RuleErrorBuilder::message(sprintf( 'Variable static method call on %s.', - $methodCalledOn + $methodCalledOn, ))->identifier('staticMethod.dynamicName')->build(), ]; } diff --git a/src/Rules/VariableVariables/VariableStaticMethodCallableRule.php b/src/Rules/VariableVariables/VariableStaticMethodCallableRule.php index f765da66..2cfebaca 100644 --- a/src/Rules/VariableVariables/VariableStaticMethodCallableRule.php +++ b/src/Rules/VariableVariables/VariableStaticMethodCallableRule.php @@ -36,7 +36,7 @@ public function processNode(Node $node, Scope $scope): array return [ RuleErrorBuilder::message(sprintf( 'Variable static method call on %s.', - $methodCalledOn + $methodCalledOn, ))->identifier('staticMethod.dynamicName')->build(), ]; } diff --git a/src/Rules/VariableVariables/VariableStaticPropertyFetchRule.php b/src/Rules/VariableVariables/VariableStaticPropertyFetchRule.php index f27c7792..bc475992 100644 --- a/src/Rules/VariableVariables/VariableStaticPropertyFetchRule.php +++ b/src/Rules/VariableVariables/VariableStaticPropertyFetchRule.php @@ -36,7 +36,7 @@ public function processNode(Node $node, Scope $scope): array return [ RuleErrorBuilder::message(sprintf( 'Variable static property access on %s.', - $propertyAccessedOn + $propertyAccessedOn, ))->identifier('staticProperty.dynamicName')->build(), ]; } diff --git a/tests/Rules/BooleansInConditions/BooleanInBooleanAndRuleTest.php b/tests/Rules/BooleansInConditions/BooleanInBooleanAndRuleTest.php index c0f448dd..08625e64 100644 --- a/tests/Rules/BooleansInConditions/BooleanInBooleanAndRuleTest.php +++ b/tests/Rules/BooleansInConditions/BooleanInBooleanAndRuleTest.php @@ -16,9 +16,9 @@ protected function getRule(): Rule { return new BooleanInBooleanAndRule( new BooleanRuleHelper( - self::getContainer()->getByType(RuleLevelHelper::class) + self::getContainer()->getByType(RuleLevelHelper::class), ), - true + true, ); } diff --git a/tests/Rules/BooleansInConditions/BooleanInBooleanNotRuleTest.php b/tests/Rules/BooleansInConditions/BooleanInBooleanNotRuleTest.php index 1d5e017d..ac30c927 100644 --- a/tests/Rules/BooleansInConditions/BooleanInBooleanNotRuleTest.php +++ b/tests/Rules/BooleansInConditions/BooleanInBooleanNotRuleTest.php @@ -16,8 +16,8 @@ protected function getRule(): Rule { return new BooleanInBooleanNotRule( new BooleanRuleHelper( - self::getContainer()->getByType(RuleLevelHelper::class) - ) + self::getContainer()->getByType(RuleLevelHelper::class), + ), ); } diff --git a/tests/Rules/BooleansInConditions/BooleanInBooleanOrRuleTest.php b/tests/Rules/BooleansInConditions/BooleanInBooleanOrRuleTest.php index c9d7ed45..feb8186a 100644 --- a/tests/Rules/BooleansInConditions/BooleanInBooleanOrRuleTest.php +++ b/tests/Rules/BooleansInConditions/BooleanInBooleanOrRuleTest.php @@ -16,9 +16,9 @@ protected function getRule(): Rule { return new BooleanInBooleanOrRule( new BooleanRuleHelper( - self::getContainer()->getByType(RuleLevelHelper::class) + self::getContainer()->getByType(RuleLevelHelper::class), ), - true + true, ); } diff --git a/tests/Rules/BooleansInConditions/BooleanInElseIfConditionRuleTest.php b/tests/Rules/BooleansInConditions/BooleanInElseIfConditionRuleTest.php index 43cd364b..58875e4d 100644 --- a/tests/Rules/BooleansInConditions/BooleanInElseIfConditionRuleTest.php +++ b/tests/Rules/BooleansInConditions/BooleanInElseIfConditionRuleTest.php @@ -16,8 +16,8 @@ protected function getRule(): Rule { return new BooleanInElseIfConditionRule( new BooleanRuleHelper( - self::getContainer()->getByType(RuleLevelHelper::class) - ) + self::getContainer()->getByType(RuleLevelHelper::class), + ), ); } diff --git a/tests/Rules/BooleansInConditions/BooleanInIfConditionRuleTest.php b/tests/Rules/BooleansInConditions/BooleanInIfConditionRuleTest.php index 59324856..d72fb6ff 100644 --- a/tests/Rules/BooleansInConditions/BooleanInIfConditionRuleTest.php +++ b/tests/Rules/BooleansInConditions/BooleanInIfConditionRuleTest.php @@ -16,8 +16,8 @@ protected function getRule(): Rule { return new BooleanInIfConditionRule( new BooleanRuleHelper( - self::getContainer()->getByType(RuleLevelHelper::class) - ) + self::getContainer()->getByType(RuleLevelHelper::class), + ), ); } diff --git a/tests/Rules/BooleansInConditions/BooleanInTernaryOperatorRuleTest.php b/tests/Rules/BooleansInConditions/BooleanInTernaryOperatorRuleTest.php index a7149e00..033c6346 100644 --- a/tests/Rules/BooleansInConditions/BooleanInTernaryOperatorRuleTest.php +++ b/tests/Rules/BooleansInConditions/BooleanInTernaryOperatorRuleTest.php @@ -16,8 +16,8 @@ protected function getRule(): Rule { return new BooleanInTernaryOperatorRule( new BooleanRuleHelper( - self::getContainer()->getByType(RuleLevelHelper::class) - ) + self::getContainer()->getByType(RuleLevelHelper::class), + ), ); } diff --git a/tests/Rules/Cast/UselessCastRuleTest.php b/tests/Rules/Cast/UselessCastRuleTest.php index c5a151ea..7ffefe2c 100644 --- a/tests/Rules/Cast/UselessCastRuleTest.php +++ b/tests/Rules/Cast/UselessCastRuleTest.php @@ -11,8 +11,7 @@ class UselessCastRuleTest extends RuleTestCase { - /** @var bool */ - private $treatPhpDocTypesAsCertain; + private bool $treatPhpDocTypesAsCertain; protected function getRule(): Rule { @@ -57,7 +56,7 @@ public function testUselessCast(): void 46, 'Because the type is coming from a PHPDoc, you can turn off this check by setting treatPhpDocTypesAsCertain: false in your %configurationFile%.', ], - ] + ], ); } diff --git a/tests/Rules/Functions/ArrayFilterStrictRuleTest.php b/tests/Rules/Functions/ArrayFilterStrictRuleTest.php index 45ac87a7..b2412193 100644 --- a/tests/Rules/Functions/ArrayFilterStrictRuleTest.php +++ b/tests/Rules/Functions/ArrayFilterStrictRuleTest.php @@ -11,11 +11,9 @@ class ArrayFilterStrictRuleTest extends RuleTestCase { - /** @var bool */ - private $treatPhpDocTypesAsCertain; + private bool $treatPhpDocTypesAsCertain; - /** @var bool */ - private $checkNullables; + private bool $checkNullables; protected function getRule(): Rule { diff --git a/tests/Rules/Operators/OperandInArithmeticIncrementOrDecrementRuleTestCase.php b/tests/Rules/Operators/OperandInArithmeticIncrementOrDecrementRuleTestCase.php index 0efa83a7..a1206dca 100644 --- a/tests/Rules/Operators/OperandInArithmeticIncrementOrDecrementRuleTestCase.php +++ b/tests/Rules/Operators/OperandInArithmeticIncrementOrDecrementRuleTestCase.php @@ -17,8 +17,8 @@ protected function getRule(): Rule { return $this->createRule( new OperatorRuleHelper( - self::getContainer()->getByType(RuleLevelHelper::class) - ) + self::getContainer()->getByType(RuleLevelHelper::class), + ), ); } diff --git a/tests/Rules/Operators/OperandsInArithmeticAdditionRuleTest.php b/tests/Rules/Operators/OperandsInArithmeticAdditionRuleTest.php index 0d25e12c..6d1383fe 100644 --- a/tests/Rules/Operators/OperandsInArithmeticAdditionRuleTest.php +++ b/tests/Rules/Operators/OperandsInArithmeticAdditionRuleTest.php @@ -18,9 +18,9 @@ protected function getRule(): Rule { return new OperandsInArithmeticAdditionRule( new OperatorRuleHelper( - self::getContainer()->getByType(RuleLevelHelper::class) + self::getContainer()->getByType(RuleLevelHelper::class), ), - true + true, ); } @@ -55,7 +55,7 @@ public function testRule(): void 'Only numeric types are allowed in +, null given on the right side.', 133, ], - ] + ], ); $this->analyse([__DIR__ . '/data/operators.php'], $messages); diff --git a/tests/Rules/Operators/OperandsInArithmeticDivisionRuleTest.php b/tests/Rules/Operators/OperandsInArithmeticDivisionRuleTest.php index 74e21357..6f059fcc 100644 --- a/tests/Rules/Operators/OperandsInArithmeticDivisionRuleTest.php +++ b/tests/Rules/Operators/OperandsInArithmeticDivisionRuleTest.php @@ -16,9 +16,9 @@ protected function getRule(): Rule { return new OperandsInArithmeticDivisionRule( new OperatorRuleHelper( - self::getContainer()->getByType(RuleLevelHelper::class) + self::getContainer()->getByType(RuleLevelHelper::class), ), - true + true, ); } diff --git a/tests/Rules/Operators/OperandsInArithmeticExponentiationRuleTest.php b/tests/Rules/Operators/OperandsInArithmeticExponentiationRuleTest.php index 2ae96a42..2d7681d0 100644 --- a/tests/Rules/Operators/OperandsInArithmeticExponentiationRuleTest.php +++ b/tests/Rules/Operators/OperandsInArithmeticExponentiationRuleTest.php @@ -16,9 +16,9 @@ protected function getRule(): Rule { return new OperandsInArithmeticExponentiationRule( new OperatorRuleHelper( - self::getContainer()->getByType(RuleLevelHelper::class) + self::getContainer()->getByType(RuleLevelHelper::class), ), - true + true, ); } diff --git a/tests/Rules/Operators/OperandsInArithmeticModuloRuleTest.php b/tests/Rules/Operators/OperandsInArithmeticModuloRuleTest.php index e58e489e..da766cab 100644 --- a/tests/Rules/Operators/OperandsInArithmeticModuloRuleTest.php +++ b/tests/Rules/Operators/OperandsInArithmeticModuloRuleTest.php @@ -16,9 +16,9 @@ protected function getRule(): Rule { return new OperandsInArithmeticModuloRule( new OperatorRuleHelper( - self::getContainer()->getByType(RuleLevelHelper::class) + self::getContainer()->getByType(RuleLevelHelper::class), ), - true + true, ); } diff --git a/tests/Rules/Operators/OperandsInArithmeticMultiplicationRuleTest.php b/tests/Rules/Operators/OperandsInArithmeticMultiplicationRuleTest.php index 51c6a8c3..7a1e62e4 100644 --- a/tests/Rules/Operators/OperandsInArithmeticMultiplicationRuleTest.php +++ b/tests/Rules/Operators/OperandsInArithmeticMultiplicationRuleTest.php @@ -16,9 +16,9 @@ protected function getRule(): Rule { return new OperandsInArithmeticMultiplicationRule( new OperatorRuleHelper( - self::getContainer()->getByType(RuleLevelHelper::class) + self::getContainer()->getByType(RuleLevelHelper::class), ), - true + true, ); } diff --git a/tests/Rules/Operators/OperandsInArithmeticSubtractionRuleTest.php b/tests/Rules/Operators/OperandsInArithmeticSubtractionRuleTest.php index 3b7cf00f..b6ea825c 100644 --- a/tests/Rules/Operators/OperandsInArithmeticSubtractionRuleTest.php +++ b/tests/Rules/Operators/OperandsInArithmeticSubtractionRuleTest.php @@ -16,9 +16,9 @@ protected function getRule(): Rule { return new OperandsInArithmeticSubtractionRule( new OperatorRuleHelper( - self::getContainer()->getByType(RuleLevelHelper::class) + self::getContainer()->getByType(RuleLevelHelper::class), ), - true + true, ); }