diff --git a/config/static-rules.neon b/config/static-rules.neon index b046d924..6b899a3f 100644 --- a/config/static-rules.neon +++ b/config/static-rules.neon @@ -34,7 +34,6 @@ rules: - Symplify\PHPStanRules\Rules\NarrowType\NoReturnFalseInNonBoolClassMethodRule - Symplify\PHPStanRules\Rules\Complexity\ForbiddenArrayMethodCallRule - - Symplify\PHPStanRules\Rules\ForbiddenSpreadOperatorRule - Symplify\PHPStanRules\Rules\CheckRequiredInterfaceInContractNamespaceRule - Symplify\PHPStanRules\Rules\NoEmptyClassRule diff --git a/phpstan.neon b/phpstan.neon index 8a498d9b..b444a4f7 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -8,7 +8,7 @@ parameters: - packages - packages-tests - reportUnmatchedIgnoredErrors: false + # reportUnmatchedIgnoredErrors: false excludePaths: # parallel @@ -36,9 +36,6 @@ parameters: - '#Class Symplify\\PHPStanRules\\(.*?)Rule implements generic interface PHPStan\\Rules\\Rule but does not specify its types\: TNodeType#' - '#Method (.*?)::getCollectors\(\) return type with generic interface PHPStan\\Collectors\\Collector does not specify its types\: TNodeType, TValue#' - # child type - - '#Parameter \#1 \$node of method Symplify\\PHPStanRules\\Rules\\ForbiddenSpreadOperatorRule\:\:hasVariadicParam\(\) expects PhpParser\\Node\\Expr\\ArrowFunction\|PhpParser\\Node\\Expr\\Closure\|PhpParser\\Node\\Stmt\\ClassMethod\|PhpParser\\Node\\Stmt\\Function_, PhpParser\\Node\\Expr\\ArrowFunction\|PhpParser\\Node\\Expr\\Closure\|\(PhpParser\\Node\\Expr\\FuncCall&PhpParser\\Node\\FunctionLike\)\|\(PhpParser\\Node\\Expr\\MethodCall&PhpParser\\Node\\FunctionLike\)\|\(PhpParser\\Node\\Expr\\StaticCall&PhpParser\\Node\\FunctionLike\)\|PhpParser\\Node\\Stmt\\ClassMethod\|PhpParser\\Node\\Stmt\\Function_ given#' - # invalid PHPStan type - it alwasy requires 2 types to traverse with callable - message: '#Callable callable\(PHPStan\\Type\\Type\)\: PHPStan\\Type\\Type invoked with 2 parameters, 1 required#' diff --git a/src/Rules/ForbiddenSpreadOperatorRule.php b/src/Rules/ForbiddenSpreadOperatorRule.php deleted file mode 100644 index 578d3f65..00000000 --- a/src/Rules/ForbiddenSpreadOperatorRule.php +++ /dev/null @@ -1,107 +0,0 @@ -> - */ - public function getNodeTypes(): array - { - return [ - Closure::class, - ArrowFunction::class, - ClassMethod::class, - Function_::class, - MethodCall::class, - StaticCall::class, - FuncCall::class, - ]; - } - - /** - * @param Closure|ArrowFunction|MethodCall|StaticCall|FuncCall|ClassMethod|Function_ $node - * @return string[] - */ - public function process(Node $node, Scope $scope): array - { - if ($node instanceof FunctionLike) { - if (! $this->hasVariadicParam($node)) { - return []; - } - - return [self::ERROR_MESSAGE]; - } - - foreach ($node->args as $key => $arg) { - if (! $arg instanceof Arg) { - continue; - } - - if (! $arg->unpack) { - continue; - } - - if ($key === 0) { - // unpack args on 1st position cannot be skipped - return []; - } - - return [self::ERROR_MESSAGE]; - } - - return []; - } - - public function getRuleDefinition(): RuleDefinition - { - return new RuleDefinition(self::ERROR_MESSAGE, [ - new CodeSample( - <<<'CODE_SAMPLE' -$args = [$firstValue, $secondValue]; -$message = sprintf('%s', ...$args); -CODE_SAMPLE - , - <<<'CODE_SAMPLE' -$message = sprintf('%s', $firstValue, $secondValue); -CODE_SAMPLE - ), - ]); - } - - private function hasVariadicParam(Closure | ArrowFunction | ClassMethod | Function_ $node): bool - { - foreach ($node->params as $param) { - if ($param->variadic) { - return true; - } - } - - return false; - } -} diff --git a/tests/Rules/ForbiddenSpreadOperatorRule/Fixture/SkipFirstVariadic.php b/tests/Rules/ForbiddenSpreadOperatorRule/Fixture/SkipFirstVariadic.php deleted file mode 100644 index 89226b1f..00000000 --- a/tests/Rules/ForbiddenSpreadOperatorRule/Fixture/SkipFirstVariadic.php +++ /dev/null @@ -1,18 +0,0 @@ -process(...$paths); - } -} diff --git a/tests/Rules/ForbiddenSpreadOperatorRule/Fixture/SkipNoSpreadOperator.php b/tests/Rules/ForbiddenSpreadOperatorRule/Fixture/SkipNoSpreadOperator.php deleted file mode 100644 index 5bfc7359..00000000 --- a/tests/Rules/ForbiddenSpreadOperatorRule/Fixture/SkipNoSpreadOperator.php +++ /dev/null @@ -1,13 +0,0 @@ -analyse([$filePath], $expectedErrorMessagesWithLines); - } - - public static function provideData(): Iterator - { - yield [__DIR__ . '/Fixture/SkipNoSpreadOperator.php', []]; - yield [__DIR__ . '/Fixture/SkipFirstVariadic.php', []]; - - yield [__DIR__ . '/Fixture/SpreadOperator.php', [[ForbiddenSpreadOperatorRule::ERROR_MESSAGE, 11]]]; - yield [__DIR__ . '/Fixture/SpreadOperatorAsMethodArg.php', [[ForbiddenSpreadOperatorRule::ERROR_MESSAGE, 9]]]; - yield [__DIR__ . '/Fixture/SpreadOperatorAsFunctionArg.php', [[ForbiddenSpreadOperatorRule::ERROR_MESSAGE, 7]]]; - } - - /** - * @return string[] - */ - public static function getAdditionalConfigFiles(): array - { - return [__DIR__ . '/config/configured_rule.neon']; - } - - protected function getRule(): Rule - { - return self::getContainer()->getByType(ForbiddenSpreadOperatorRule::class); - } -} diff --git a/tests/Rules/ForbiddenSpreadOperatorRule/Source/ClassMethodWithFirstArgumentVariadic.php b/tests/Rules/ForbiddenSpreadOperatorRule/Source/ClassMethodWithFirstArgumentVariadic.php deleted file mode 100644 index 48ed71c5..00000000 --- a/tests/Rules/ForbiddenSpreadOperatorRule/Source/ClassMethodWithFirstArgumentVariadic.php +++ /dev/null @@ -1,12 +0,0 @@ -