From 8615230f6d0d1dba56f479c4975994066436fe60 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sun, 20 Feb 2022 22:04:11 +0000 Subject: [PATCH] [PHPStanRules] Remove NoMaskWithoutSprintfRule, might be useful to use mask sometimes --- .../phpstan-rules/config/static-rules.neon | 4 - packages/phpstan-rules/docs/rules_overview.md | 87 +------------ .../src/Rules/NoMaskWithoutSprintfRule.php | 114 ------------------ .../Fixture/NoSprintf.php | 13 -- .../Fixture/SkipHerenowdoc.php | 9 -- .../Fixture/SkipIdentical.php | 13 -- .../Fixture/SkipOnConstant.php | 10 -- .../Fixture/SkipWithSprintf.php | 13 -- .../NoMaskWithoutSprintfRuleTest.php | 40 ------ .../config/configured_rule.neon | 7 -- 10 files changed, 1 insertion(+), 309 deletions(-) delete mode 100644 packages/phpstan-rules/src/Rules/NoMaskWithoutSprintfRule.php delete mode 100644 packages/phpstan-rules/tests/Rules/NoMaskWithoutSprintfRule/Fixture/NoSprintf.php delete mode 100644 packages/phpstan-rules/tests/Rules/NoMaskWithoutSprintfRule/Fixture/SkipHerenowdoc.php delete mode 100644 packages/phpstan-rules/tests/Rules/NoMaskWithoutSprintfRule/Fixture/SkipIdentical.php delete mode 100644 packages/phpstan-rules/tests/Rules/NoMaskWithoutSprintfRule/Fixture/SkipOnConstant.php delete mode 100644 packages/phpstan-rules/tests/Rules/NoMaskWithoutSprintfRule/Fixture/SkipWithSprintf.php delete mode 100644 packages/phpstan-rules/tests/Rules/NoMaskWithoutSprintfRule/NoMaskWithoutSprintfRuleTest.php delete mode 100644 packages/phpstan-rules/tests/Rules/NoMaskWithoutSprintfRule/config/configured_rule.neon diff --git a/packages/phpstan-rules/config/static-rules.neon b/packages/phpstan-rules/config/static-rules.neon index 4fc9f540da..5ec76b8350 100644 --- a/packages/phpstan-rules/config/static-rules.neon +++ b/packages/phpstan-rules/config/static-rules.neon @@ -120,10 +120,6 @@ services: class: Symplify\PHPStanRules\Rules\NoSuffixValueObjectClassRule tags: [phpstan.rules.rule] - - - class: Symplify\PHPStanRules\Rules\NoMaskWithoutSprintfRule - tags: [phpstan.rules.rule] - - class: Symplify\PHPStanRules\Rules\RequireThisOnParentMethodCallRule tags: [phpstan.rules.rule] diff --git a/packages/phpstan-rules/docs/rules_overview.md b/packages/phpstan-rules/docs/rules_overview.md index e717423260..09aebab6d3 100644 --- a/packages/phpstan-rules/docs/rules_overview.md +++ b/packages/phpstan-rules/docs/rules_overview.md @@ -1,4 +1,4 @@ -# 132 Rules Overview +# 130 Rules Overview ## AnnotateRegexClassConstWithRegexLinkRule @@ -1435,69 +1435,6 @@ final class SomeRector implements RectorInterface
-## ForbiddenPrivateMethodByTypeRule - -Private method in is not allowed here - it should only delegate to others. Decouple the private method to a new service class - -:wrench: **configure it!** - -- class: [`Symplify\PHPStanRules\Rules\ForbiddenPrivateMethodByTypeRule`](../src/Rules/ForbiddenPrivateMethodByTypeRule.php) - -```yaml -services: - - - class: Symplify\PHPStanRules\Rules\ForbiddenPrivateMethodByTypeRule - tags: [phpstan.rules.rule] - arguments: - forbiddenTypes: - - Command -``` - -↓ - -```php -class SomeCommand extends Command -{ - public function run() - { - $this->somePrivateMethod(); - } - - private function somePrivateMethod() - { - // ... - } -} -``` - -:x: - -
- -```php -class SomeCommand extends Command -{ - /** - * @var ExternalService - */ - private $externalService; - - public function __construct(ExternalService $externalService) - { - $this->externalService = $externalService; - } - - public function run() - { - $this->externalService->someMethod(); - } -} -``` - -:+1: - -
- ## ForbiddenProtectedPropertyRule Property with protected modifier is not allowed. Use interface contract method instead @@ -2694,28 +2631,6 @@ final class HelpfulName
-## NoMaskWithoutSprintfRule - -Missing `sprintf()` function for a mask - -- class: [`Symplify\PHPStanRules\Rules\NoMaskWithoutSprintfRule`](../src/Rules/NoMaskWithoutSprintfRule.php) - -```php -return 'Hey %s'; -``` - -:x: - -
- -```php -return sprintf('Hey %s', 'Matthias'); -``` - -:+1: - -
- ## NoMethodTagInClassDocblockRule Do not use `@method` tag in class docblock diff --git a/packages/phpstan-rules/src/Rules/NoMaskWithoutSprintfRule.php b/packages/phpstan-rules/src/Rules/NoMaskWithoutSprintfRule.php deleted file mode 100644 index a9f873cf63..0000000000 --- a/packages/phpstan-rules/src/Rules/NoMaskWithoutSprintfRule.php +++ /dev/null @@ -1,114 +0,0 @@ -> - */ - public function getNodeTypes(): array - { - return [String_::class]; - } - - /** - * @param String_ $node - * @return string[] - */ - public function process(Node $node, Scope $scope): array - { - $stringKind = $node->getAttribute(AttributeKey::KIND); - if (in_array($stringKind, [String_::KIND_NOWDOC, String_::KIND_HEREDOC], true)) { - return []; - } - - if (! str_contains($node->value, '%s')) { - return []; - } - - if ($node->value === '%s') { - return []; - } - - $parent = $node->getAttribute(AttributeKey::PARENT); - if ($parent === null) { - return []; - } - - if ($this->shouldSkipParentType($parent)) { - return []; - } - - if (! $parent instanceof Arg) { - return [self::ERROR_MESSAGE]; - } - - $parentParent = $parent->getAttribute(AttributeKey::PARENT); - if (! $parentParent instanceof FuncCall) { - return [self::ERROR_MESSAGE]; - } - - if ($this->simpleNameResolver->isName($parentParent, 'sprintf')) { - return []; - } - - return [self::ERROR_MESSAGE]; - } - - public function getRuleDefinition(): RuleDefinition - { - return new RuleDefinition(self::ERROR_MESSAGE, [ - new CodeSample( - <<<'CODE_SAMPLE' -return 'Hey %s'; -CODE_SAMPLE - , - <<<'CODE_SAMPLE' -return sprintf('Hey %s', 'Matthias'); -CODE_SAMPLE - ), - ]); - } - - private function shouldSkipParentType(Node $node): bool - { - if ($node instanceof Const_) { - return true; - } - - if ($node instanceof BinaryOp) { - return true; - } - - return $node instanceof ArrayItem; - } -} diff --git a/packages/phpstan-rules/tests/Rules/NoMaskWithoutSprintfRule/Fixture/NoSprintf.php b/packages/phpstan-rules/tests/Rules/NoMaskWithoutSprintfRule/Fixture/NoSprintf.php deleted file mode 100644 index e167faf32a..0000000000 --- a/packages/phpstan-rules/tests/Rules/NoMaskWithoutSprintfRule/Fixture/NoSprintf.php +++ /dev/null @@ -1,13 +0,0 @@ - - */ -final class NoMaskWithoutSprintfRuleTest extends AbstractServiceAwareRuleTestCase -{ - /** - * @dataProvider provideData() - * @param array $expectedErrorMessagesWithLines - */ - public function testRule(string $filePath, array $expectedErrorMessagesWithLines): void - { - $this->analyse([$filePath], $expectedErrorMessagesWithLines); - } - - public function provideData(): Iterator - { - yield [__DIR__ . '/Fixture/SkipWithSprintf.php', []]; - yield [__DIR__ . '/Fixture/SkipOnConstant.php', []]; - yield [__DIR__ . '/Fixture/SkipHerenowdoc.php', []]; - yield [__DIR__ . '/Fixture/SkipIdentical.php', []]; - - yield [__DIR__ . '/Fixture/NoSprintf.php', [[NoMaskWithoutSprintfRule::ERROR_MESSAGE, 11]]]; - } - - protected function getRule(): Rule - { - return $this->getRuleFromConfig(NoMaskWithoutSprintfRule::class, __DIR__ . '/config/configured_rule.neon'); - } -} diff --git a/packages/phpstan-rules/tests/Rules/NoMaskWithoutSprintfRule/config/configured_rule.neon b/packages/phpstan-rules/tests/Rules/NoMaskWithoutSprintfRule/config/configured_rule.neon deleted file mode 100644 index 9dba3b0380..0000000000 --- a/packages/phpstan-rules/tests/Rules/NoMaskWithoutSprintfRule/config/configured_rule.neon +++ /dev/null @@ -1,7 +0,0 @@ -includes: - - ../../../config/included_services.neon - -services: - - - class: Symplify\PHPStanRules\Rules\NoMaskWithoutSprintfRule - tags: [phpstan.rules.rule]