From 7fb4489615a73feb6207b022f1a24e77511ccb92 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sun, 2 Jun 2024 11:39:08 +0900 Subject: [PATCH] Remove NoNullableArrayPropertyRule as depends on use-case, cached etc (#134) --- config/static-rules.neon | 15 ++-- src/Rules/NoNullableArrayPropertyRule.php | 72 ------------------- .../Fixture/NullableArrayProperty.php | 11 --- .../Fixture/SkipClassNameProperty.php | 13 ---- .../Fixture/SkipNoType.php | 11 --- .../Fixture/SkipNotArray.php | 11 --- .../Fixture/SkipNotNullable.php | 11 --- .../NoNullableArrayPropertyRuleTest.php | 45 ------------ .../config/configured_rule.neon | 5 -- 9 files changed, 4 insertions(+), 190 deletions(-) delete mode 100644 src/Rules/NoNullableArrayPropertyRule.php delete mode 100644 tests/Rules/NoNullableArrayPropertyRule/Fixture/NullableArrayProperty.php delete mode 100644 tests/Rules/NoNullableArrayPropertyRule/Fixture/SkipClassNameProperty.php delete mode 100644 tests/Rules/NoNullableArrayPropertyRule/Fixture/SkipNoType.php delete mode 100644 tests/Rules/NoNullableArrayPropertyRule/Fixture/SkipNotArray.php delete mode 100644 tests/Rules/NoNullableArrayPropertyRule/Fixture/SkipNotNullable.php delete mode 100644 tests/Rules/NoNullableArrayPropertyRule/NoNullableArrayPropertyRuleTest.php delete mode 100644 tests/Rules/NoNullableArrayPropertyRule/config/configured_rule.neon diff --git a/config/static-rules.neon b/config/static-rules.neon index a6c8f4eb..3c33dfc0 100644 --- a/config/static-rules.neon +++ b/config/static-rules.neon @@ -5,20 +5,13 @@ rules: # domain - Symplify\PHPStanRules\Rules\Domain\RequireExceptionNamespaceRule - Symplify\PHPStanRules\Rules\Domain\RequireAttributeNamespaceRule + - Symplify\PHPStanRules\Rules\CheckRequiredInterfaceInContractNamespaceRule + - Symplify\PHPStanRules\Rules\RequireAttributeNameRule + - Symplify\PHPStanRules\Rules\Enum\RequireUniqueEnumConstantRule - Symplify\PHPStanRules\Rules\PreventParentMethodVisibilityOverrideRule - # paths - - Symplify\PHPStanRules\Rules\NoReferenceRule - - - Symplify\PHPStanRules\Rules\NoNullableArrayPropertyRule - - # explicit naming - Symplify\PHPStanRules\Rules\ForbiddenMultipleClassLikeInOneFileRule - + - Symplify\PHPStanRules\Rules\NoReferenceRule - Symplify\PHPStanRules\Rules\ForbiddenStaticClassConstFetchRule - Symplify\PHPStanRules\Rules\Complexity\ForbiddenArrayMethodCallRule - - Symplify\PHPStanRules\Rules\CheckRequiredInterfaceInContractNamespaceRule - - # naming - - Symplify\PHPStanRules\Rules\RequireAttributeNameRule diff --git a/src/Rules/NoNullableArrayPropertyRule.php b/src/Rules/NoNullableArrayPropertyRule.php deleted file mode 100644 index fbd4482d..00000000 --- a/src/Rules/NoNullableArrayPropertyRule.php +++ /dev/null @@ -1,72 +0,0 @@ - - */ - public function getNodeType(): string - { - return Property::class; - } - - /** - * @param Property $node - * @return string[] - */ - public function processNode(Node $node, Scope $scope): array - { - if (! $node->type instanceof NullableType) { - return []; - } - - $typeName = $node->type->type->toString(); - if ($typeName !== 'array') { - return []; - } - - return [self::ERROR_MESSAGE]; - } - - public function getRuleDefinition(): RuleDefinition - { - return new RuleDefinition(self::ERROR_MESSAGE, [ - new CodeSample( - <<<'CODE_SAMPLE' -final class SomeClass -{ - private ?array $property = null; -} -CODE_SAMPLE - , - <<<'CODE_SAMPLE' -final class SomeClass -{ - private array $property = []; -} -CODE_SAMPLE - ), - ]); - } -} diff --git a/tests/Rules/NoNullableArrayPropertyRule/Fixture/NullableArrayProperty.php b/tests/Rules/NoNullableArrayPropertyRule/Fixture/NullableArrayProperty.php deleted file mode 100644 index ccc484fc..00000000 --- a/tests/Rules/NoNullableArrayPropertyRule/Fixture/NullableArrayProperty.php +++ /dev/null @@ -1,11 +0,0 @@ -analyse([$filePath], $expectedErrorMessagesWithLines); - } - - public static function provideData(): Iterator - { - yield [__DIR__ . '/Fixture/SkipNoType.php', []]; - yield [__DIR__ . '/Fixture/SkipNotNullable.php', []]; - yield [__DIR__ . '/Fixture/SkipNotArray.php', []]; - yield [__DIR__ . '/Fixture/SkipClassNameProperty.php', []]; - yield [__DIR__ . '/Fixture/NullableArrayProperty.php', [[NoNullableArrayPropertyRule::ERROR_MESSAGE, 9]]]; - } - - /** - * @return string[] - */ - public static function getAdditionalConfigFiles(): array - { - return [__DIR__ . '/config/configured_rule.neon']; - } - - protected function getRule(): Rule - { - return self::getContainer()->getByType(NoNullableArrayPropertyRule::class); - } -} diff --git a/tests/Rules/NoNullableArrayPropertyRule/config/configured_rule.neon b/tests/Rules/NoNullableArrayPropertyRule/config/configured_rule.neon deleted file mode 100644 index f982c7bc..00000000 --- a/tests/Rules/NoNullableArrayPropertyRule/config/configured_rule.neon +++ /dev/null @@ -1,5 +0,0 @@ -includes: - - ../../../config/included_services.neon - -rules: - - Symplify\PHPStanRules\Rules\NoNullableArrayPropertyRule