Skip to content

Commit 9eff317

Browse files
committed
Remove RequireAssertConfigureValueObjectRectorRule as depends on context and common sense
1 parent a8b8200 commit 9eff317

40 files changed

+277
-415
lines changed

.github/workflows/code_analysis.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
# see https://github.com/shivammathur/setup-php
4545
- uses: shivammathur/setup-php@v2
4646
with:
47-
php-version: 8.1
47+
php-version: 8.2
4848
coverage: none
4949

5050
# composer install cache - https://github.com/ramsey/composer-install

.github/workflows/downgraded_release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
-
2121
uses: "shivammathur/setup-php@v2"
2222
with:
23-
php-version: 8.1
23+
php-version: 8.2
2424
coverage: none
2525

2626
# invoke patches

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"symplify/easy-coding-standard": "^12.5",
1717
"tomasvotruba/class-leak": "^1.2",
1818
"rector/rector": "^2.0",
19-
"phpstan/extension-installer": "^1.4"
19+
"phpstan/extension-installer": "^1.4",
20+
"symplify/phpstan-extensions": "^12.0"
2021
},
2122
"autoload": {
2223
"psr-4": {

config/rector-rules.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
rules:
22
- Symplify\PHPStanRules\Rules\Rector\PhpUpgradeDowngradeRegisteredInSetRule
33
- Symplify\PHPStanRules\Rules\Rector\PhpUpgradeImplementsMinPhpVersionInterfaceRule
4-
- Symplify\PHPStanRules\Rules\Rector\RequireAssertConfigureValueObjectRectorRule
54
- Symplify\PHPStanRules\Rules\Rector\NoInstanceOfStaticReflectionRule
65
- Symplify\PHPStanRules\Rules\Rector\NoLeadingBackslashInNameRule
76
- Symplify\PHPStanRules\Rules\Rector\NoClassReflectionStaticReflectionRule

phpstan.neon

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ includes:
44

55
parameters:
66
treatPhpDocTypesAsCertain: false
7+
errorFormat: symplify
78

89
level: 8
910

@@ -50,28 +51,13 @@ parameters:
5051
# overly detailed
5152
- '#Class Symplify\\PHPStanRules\\Collector\\(.*?) implements generic interface PHPStan\\Collectors\\Collector but does not specify its types\: TNodeType, TValue#'
5253

53-
# -
54-
# identifier: argument.type
55-
#
5654
# useful to have IDE know the types
5755
- identifier: phpstanApi.instanceofType
58-
#
59-
# -
60-
# identifier: return.type
6156

6257
-
6358
identifier: class.notFound
6459
path: tests/Rules/Rector/PhpUpgradeImplementsMinPhpVersionInterfaceRule/PhpUpgradeImplementsMinPhpVersionInterfaceRuleTest.php
6560

66-
# -
67-
# identifier: phpstanApi.runtimeReflection
68-
#
69-
# -
70-
# identifier: phpstanApi.instanceofAssumption
71-
#
72-
# -
73-
# identifier: method.childReturnType
74-
7561
# overly detailed
7662
-
7763
message: '#Parameter \#2 \$expectedErrors of method PHPStan\\Testing\\RuleTestCase<(.*?)>::analyse\(\) expects list<array\{0: string, 1: int, 2\?: string\|null\}>, (.*?) given#'
@@ -81,3 +67,6 @@ parameters:
8167
-
8268
message: '#Function is_a\(\) is a runtime reflection concept that might not work in PHPStan because it uses fully static reflection engine#'
8369
path: src/Rules/SeeAnnotationToTestRule.php
70+
71+
# handle next
72+
- '#Method Symplify\\PHPStanRules\\Rules\\AbstractSymplifyRule\:\:processNode\(\) should return list<PHPStan\\Rules\\IdentifierRuleError> but returns array<PHPStan\\Rules\\RuleError\|string>#'

src/Enum/ClassName.php

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/Enum/RuleIdentifier.php

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,124 @@ final class RuleIdentifier
5050
* @var string
5151
*/
5252
public const NO_RETURN_ARRAY_VARIABLE_LIST = 'symplify.noReturnArrayVariableList';
53+
54+
/**
55+
* @var string
56+
*/
57+
public const RECTOR_NO_INSTANCE_OF_STATIC_REFLECTION = 'rector.noInstanceOfStaticReflection';
58+
59+
/**
60+
* @var string
61+
*/
62+
public const RECTOR_NO_CLASS_REFLECTION_STATIC_REFLECTION = 'rector.noClassReflectionStaticReflection';
63+
64+
/**
65+
* @var string
66+
*/
67+
public const PARENT_METHOD_VISIBILITY_OVERRIDE = 'symplify.parentMethodVisibilityOverride';
68+
69+
/**
70+
* @var string
71+
*/
72+
public const CLASS_CONSTANT_REGEX = 'symplify.classConstantRegex';
73+
74+
/**
75+
* @var string
76+
*/
77+
public const NO_RETURN_SETTER_METHOD = 'symplify.noReturnSetterMethod';
78+
79+
/**
80+
* @var string
81+
*/
82+
public const FORBIDDEN_STATIC_CLASS_CONST_FETCH = 'symplify.forbiddenStaticClassConstFetch';
83+
84+
/**
85+
* @var string
86+
*/
87+
public const PREFERRED_CLASS = 'symplify.preferredClass';
88+
89+
/**
90+
* @var string
91+
*/
92+
public const NO_TEST_MOCKS = 'symplify.noTestMocks';
93+
94+
/**
95+
* @var string
96+
*/
97+
public const NO_GLOBAL_CONST = 'symplify.noGlobalConst';
98+
99+
/**
100+
* @var string
101+
*/
102+
public const NO_ENTITY_OUTSIDE_ENTITY_NAMESPACE = 'symplify.noEntityOutsideEntityNamespace';
103+
104+
/**
105+
* @var string
106+
*/
107+
public const FORBIDDEN_NODE = 'symplify.forbiddenNode';
108+
109+
/**
110+
* @var string
111+
*/
112+
public const MULTIPLE_CLASS_LIKE_IN_FILE = 'symplify.multipleClassLikeInFile';
113+
114+
/**
115+
* @var string
116+
*/
117+
public const FORBIDDEN_FUNC_CALL = 'symplify.forbiddenFuncCall';
118+
119+
/**
120+
* @var string
121+
*/
122+
public const REQUIRE_ATTRIBUTE_NAMESPACE = 'symplify.requireAttributeNamespace';
123+
124+
/**
125+
* @var string
126+
*/
127+
public const FORBIDDEN_ARRAY_METHOD_CALL = 'symplify.forbiddenArrayMethodCall';
128+
129+
/**
130+
* @var string
131+
*/
132+
public const REGEX_ANNOTATE_CLASS_CONST = 'symplify.regexAnnotateClassConst';
133+
134+
/**
135+
* @var string
136+
*/
137+
public const FORBIDDEN_EXTEND_OF_NON_ABSTRACT_CLASS = 'symplify.forbiddenExtendOfNonAbstractClass';
138+
139+
/**
140+
* @var string
141+
*/
142+
public const EXPLICIT_ABSTRACT_PREFIX_NAME = 'symplify.explicitAbstractPrefixName';
143+
144+
/**
145+
* @var string
146+
*/
147+
public const EXPLICIT_INTERFACE_SUFFIX_NAME = 'symplify.explicitInterfaceSuffixName';
148+
149+
/**
150+
* @var string
151+
*/
152+
public const EXPLICIT_TRAIT_SUFFIX_NAME = 'symplify.explicitTraitSuffixName';
153+
154+
/**
155+
* @var string
156+
*/
157+
public const REQUIRE_UNIQUE_ENUM_CONSTANT = 'symplify.requireUniqueEnumConstant';
158+
159+
/**
160+
* @var string
161+
*/
162+
public const REQUIRE_EXCEPTION_NAMESPACE = 'symplify.requireExceptionNamespace';
163+
164+
/**
165+
* @var string
166+
*/
167+
public const CLASS_NAME_RESPECTS_PARENT_SUFFIX = 'symplify.classNameRespectsParentSuffix';
168+
169+
/**
170+
* @var string
171+
*/
172+
public const REQUIRED_INTERFACE_CONTRACT_NAMESPACE = 'symplify.requiredInterfaceContractNamespace';
53173
}

src/Rules/AnnotateRegexClassConstWithRegexLinkRule.php

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use PHPStan\Analyser\Scope;
1313
use PHPStan\Rules\Rule;
1414
use PHPStan\Rules\RuleErrorBuilder;
15+
use Symplify\PHPStanRules\Enum\RuleIdentifier;
1516
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
1617
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
1718

@@ -66,29 +67,9 @@ public function processNode(Node $node, Scope $scope): array
6667
return [];
6768
}
6869

69-
return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()];
70-
}
71-
72-
public function getRuleDefinition(): RuleDefinition
73-
{
74-
return new RuleDefinition(self::ERROR_MESSAGE, [new CodeSample(
75-
<<<'CODE_SAMPLE'
76-
class SomeClass
77-
{
78-
private const COMPLICATED_REGEX = '#some_complicated_stu|ff#';
79-
}
80-
CODE_SAMPLE
81-
,
82-
<<<'CODE_SAMPLE'
83-
class SomeClass
84-
{
85-
/**
86-
* @see https://regex101.com/r/SZr0X5/12
87-
*/
88-
private const COMPLICATED_REGEX = '#some_complicated_stu|ff#';
89-
}
90-
CODE_SAMPLE
91-
)]);
70+
return [RuleErrorBuilder::message(self::ERROR_MESSAGE)
71+
->identifier(RuleIdentifier::REGEX_ANNOTATE_CLASS_CONST)
72+
->build()];
9273
}
9374

9475
private function isNonSingleCharRegexPattern(string $value): bool

src/Rules/CheckRequiredInterfaceInContractNamespaceRule.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use PHPStan\Analyser\Scope;
1111
use PHPStan\Rules\Rule;
1212
use PHPStan\Rules\RuleErrorBuilder;
13+
use Symplify\PHPStanRules\Enum\RuleIdentifier;
1314

1415
/**
1516
* @see \Symplify\PHPStanRules\Tests\Rules\CheckRequiredInterfaceInContractNamespaceRule\CheckRequiredInterfaceInContractNamespaceRuleTest
@@ -47,6 +48,8 @@ public function processNode(Node $node, Scope $scope): array
4748
return [];
4849
}
4950

50-
return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()];
51+
return [RuleErrorBuilder::message(self::ERROR_MESSAGE)
52+
->identifier(RuleIdentifier::REQUIRED_INTERFACE_CONTRACT_NAMESPACE)
53+
->build()];
5154
}
5255
}

src/Rules/ClassNameRespectsParentSuffixRule.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111
use PHPStan\Analyser\Scope;
1212
use PHPStan\Node\InClassNode;
1313
use PHPStan\Reflection\ClassReflection;
14+
use PHPStan\Rules\IdentifierRuleError;
1415
use PHPStan\Rules\Rule;
1516
use PHPStan\Rules\RuleError;
1617
use PHPStan\Rules\RuleErrorBuilder;
1718
use PHPUnit\Framework\TestCase;
1819
use Rector\Rector\AbstractRector;
1920
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
2021
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
22+
use Symplify\PHPStanRules\Enum\RuleIdentifier;
2123
use Symplify\PHPStanRules\Naming\ClassToSuffixResolver;
2224

2325
/**
@@ -89,7 +91,7 @@ public function processNode(Node $node, Scope $scope): array
8991
}
9092

9193
/**
92-
* @return list<RuleError>
94+
* @return list<IdentifierRuleError>
9395
*/
9496
private function processClassNameAndShort(ClassReflection $classReflection): array
9597
{
@@ -104,7 +106,9 @@ private function processClassNameAndShort(ClassReflection $classReflection): arr
104106
}
105107

106108
$errorMessage = sprintf(self::ERROR_MESSAGE, $expectedSuffix);
107-
return [RuleErrorBuilder::message($errorMessage)->build()];
109+
return [RuleErrorBuilder::message($errorMessage)
110+
->identifier(RuleIdentifier::CLASS_NAME_RESPECTS_PARENT_SUFFIX)
111+
->build()];
108112
}
109113

110114
return [];

0 commit comments

Comments
 (0)