Skip to content

Commit b71615e

Browse files
LTSCommerceclaude
andcommitted
fix(phpstan): simplify readonlyService and add Generated namespace exclusion
readonlyService: skip all classes that extend any parent class — the suffix-based exclusion list was too narrow and caused false positives on generated code, framework base classes, and other non-service parents. Skip-on-extends is the simplest correct heuristic. requireExplicitDIAttribute: exclude 'Generated' namespace so auto-generated SDK code under src/Sdk/Generated/ is not flagged for missing DI attributes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent c35aba7 commit b71615e

2 files changed

Lines changed: 2 additions & 37 deletions

File tree

src/PHPStan/Rules/RequireExplicitDIAttributeRule.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ final class RequireExplicitDIAttributeRule implements Rule
9595
'PHPStan',
9696
'Tests',
9797
'Migrations',
98+
'Generated',
9899
];
99100

100101
public function getNodeType(): string

src/PHPStan/Rules/RequireReadonlyServiceRule.php

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,6 @@ final class RequireReadonlyServiceRule implements Rule
8080
'Loader',
8181
];
8282

83-
/** @var list<string> */
84-
private const array EXCLUDED_PARENT_SUFFIXES = [
85-
'Constraint',
86-
'Controller',
87-
'Command',
88-
'TestCase',
89-
'Exception',
90-
];
91-
9283
/** @var list<string> */
9384
private const array EXCLUDED_INTERFACES = [
9485
'Psr\Log\LoggerAwareInterface',
@@ -136,7 +127,7 @@ public function processNode(Node $node, Scope $scope): array
136127
return [];
137128
}
138129

139-
if (null !== $node->extends && $this->isExcludedParent($node->extends->toString(), $scope)) {
130+
if (null !== $node->extends) {
140131
return [];
141132
}
142133

@@ -176,31 +167,4 @@ private function isDoctrineEntity(Class_ $node): bool
176167
return false;
177168
}
178169

179-
private function isExcludedParent(string $parentName, Scope $scope): bool
180-
{
181-
foreach (self::EXCLUDED_PARENT_SUFFIXES as $suffix) {
182-
if (str_ends_with($parentName, $suffix)) {
183-
return true;
184-
}
185-
}
186-
187-
$classReflection = $scope->getClassReflection();
188-
if (!$classReflection instanceof \PHPStan\Reflection\ClassReflection) {
189-
return false;
190-
}
191-
192-
$parentClass = $classReflection->getParentClass();
193-
if (!$parentClass instanceof \PHPStan\Reflection\ClassReflection) {
194-
return false;
195-
}
196-
197-
$parentFqcn = $parentClass->getName();
198-
foreach (self::EXCLUDED_PARENT_SUFFIXES as $suffix) {
199-
if (str_ends_with($parentFqcn, $suffix)) {
200-
return true;
201-
}
202-
}
203-
204-
return false;
205-
}
206170
}

0 commit comments

Comments
 (0)