Skip to content

Commit a3fc86b

Browse files
fain182claude
andcommitted
Remove dead getExtends/addExtends from ClassDescription
Now that Extend/NotExtend/HaveTrait/NotHaveTrait/Implement/NotImplement resolve the full inheritance chain via reflection, the static extends list stored in ClassDescription is never consulted. Remove addExtends() from ClassDescriptionBuilder, getExtends() from ClassDescription, the corresponding wiring in FileVisitor, and update all call sites in tests. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent be055de commit a3fc86b

File tree

11 files changed

+6
-40
lines changed

11 files changed

+6
-40
lines changed

src/Analyzer/ClassDescription.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ class ClassDescription
1313
/** @var list<ClassDependency> */
1414
private array $dependencies;
1515

16-
/** @var list<FullyQualifiedClassName> */
17-
private array $extends;
18-
1916
/** @var list<string> */
2017
private array $docBlock;
2118

@@ -39,15 +36,13 @@ class ClassDescription
3936

4037
/**
4138
* @param list<ClassDependency> $dependencies
42-
* @param list<FullyQualifiedClassName> $extends
4339
* @param list<string> $docBlock
4440
* @param list<FullyQualifiedClassName> $attributes
4541
* @param list<FullyQualifiedClassName> $traits
4642
*/
4743
public function __construct(
4844
FullyQualifiedClassName $FQCN,
4945
array $dependencies,
50-
array $extends,
5146
bool $final,
5247
bool $readonly,
5348
bool $abstract,
@@ -62,7 +57,6 @@ public function __construct(
6257
$this->FQCN = $FQCN;
6358
$this->filePath = $filePath;
6459
$this->dependencies = $dependencies;
65-
$this->extends = $extends;
6660
$this->final = $final;
6761
$this->readonly = $readonly;
6862
$this->abstract = $abstract;
@@ -131,14 +125,6 @@ public function getDependencies(): array
131125
return $this->dependencies;
132126
}
133127

134-
/**
135-
* @return list<FullyQualifiedClassName>
136-
*/
137-
public function getExtends(): array
138-
{
139-
return $this->extends;
140-
}
141-
142128
public function isFinal(): bool
143129
{
144130
return $this->final;

src/Analyzer/ClassDescriptionBuilder.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ class ClassDescriptionBuilder
1212

1313
private ?FullyQualifiedClassName $FQCN = null;
1414

15-
/** @var list<FullyQualifiedClassName> */
16-
private array $extends = [];
17-
1815
private bool $final = false;
1916

2017
private bool $readonly = false;
@@ -42,7 +39,6 @@ public function clear(): void
4239
{
4340
$this->FQCN = null;
4441
$this->classDependencies = [];
45-
$this->extends = [];
4642
$this->final = false;
4743
$this->readonly = false;
4844
$this->abstract = false;
@@ -79,14 +75,6 @@ public function addDependency(ClassDependency $cd): self
7975
return $this;
8076
}
8177

82-
public function addExtends(string $FQCN, int $line): self
83-
{
84-
$this->addDependency(new ClassDependency($FQCN, $line));
85-
$this->extends[] = FullyQualifiedClassName::fromString($FQCN);
86-
87-
return $this;
88-
}
89-
9078
public function setFinal(bool $final): self
9179
{
9280
$this->final = $final;
@@ -160,7 +148,6 @@ public function build(): ClassDescription
160148
return new ClassDescription(
161149
$this->FQCN,
162150
$this->classDependencies,
163-
$this->extends,
164151
$this->final,
165152
$this->readonly,
166153
$this->abstract,

src/Analyzer/FileVisitor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ private function handleClassNode(Node $node): void
134134

135135
if (null !== $node->extends) {
136136
$this->classDescriptionBuilder
137-
->addExtends($node->extends->toString(), $node->getLine());
137+
->addDependency(new ClassDependency($node->extends->toString(), $node->getLine()));
138138
}
139139

140140
$this->classDescriptionBuilder->setFinal($node->isFinal());
@@ -293,7 +293,7 @@ private function handleInterfaceNode(Node $node): void
293293

294294
foreach ($node->extends as $interface) {
295295
$this->classDescriptionBuilder
296-
->addExtends($interface->toString(), $interface->getLine());
296+
->addDependency(new ClassDependency($interface->toString(), $interface->getLine()));
297297
}
298298
}
299299

tests/Unit/Analyzer/FileParser/CanParseClassTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ class Cat extends Animal
208208
$cd = $this->parseCode($code);
209209
$cd = $cd[1];
210210

211-
self::assertEquals('Root\Animals\Animal', $cd->getExtends()[0]->toString());
211+
self::assertEquals('Root\Animals\Animal', $cd->getDependencies()[0]->getFQCN()->toString());
212212
}
213213

214214
public function test_it_should_not_parse_extends_from_insider_anonymousclass(): void
@@ -234,7 +234,7 @@ public function methodWithAnonymous(): void
234234
$cd = $this->parseCode($code);
235235
$cd = $cd[1];
236236

237-
self::assertEquals('Root\Animals\Animal', $cd->getExtends()[0]->toString());
237+
self::assertEquals('Root\Animals\Animal', $cd->getDependencies()[0]->getFQCN()->toString());
238238
}
239239

240240
public function test_should_depends_on_these_namespaces(): void
@@ -500,8 +500,8 @@ public function foobar();
500500
$cd = $this->parseCode($code, TargetPhpVersion::PHP_8_1);
501501

502502
self::assertCount(3, $cd);
503-
self::assertEquals('MyProject\AppBundle\Application\FooAble', $cd[2]->getExtends()[0]->toString());
504-
self::assertEquals('MyProject\AppBundle\Application\BarAble', $cd[2]->getExtends()[1]->toString());
503+
self::assertEquals('MyProject\AppBundle\Application\FooAble', $cd[2]->getDependencies()[0]->getFQCN()->toString());
504+
self::assertEquals('MyProject\AppBundle\Application\BarAble', $cd[2]->getDependencies()[1]->getFQCN()->toString());
505505
}
506506

507507
public function test_it_handles_return_types(): void

tests/Unit/Expressions/ForClasses/ExtendTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ public function test_it_should_detect_grandparent_via_reflection(): void
124124
$classDescription = (new ClassDescriptionBuilder())
125125
->setFilePath('src/Foo.php')
126126
->setClassName(ChildClass::class)
127-
->addExtends(MiddleClass::class, 10)
128127
->build();
129128

130129
$violations = new Violations();

tests/Unit/Expressions/ForClasses/HaveTraitTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ public function test_it_should_detect_trait_inherited_from_parent_via_reflection
166166
$classDescription = (new ClassDescriptionBuilder())
167167
->setFilePath('src/Foo.php')
168168
->setClassName(ChildInheritingSomeTrait::class)
169-
->addExtends(ClassUsingSomeTrait::class, 1)
170169
->build();
171170

172171
$violations = new Violations();

tests/Unit/Expressions/ForClasses/ImplementTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ public function test_it_should_detect_interface_inherited_from_parent_via_reflec
102102
$classDescription = (new ClassDescriptionBuilder())
103103
->setFilePath('src/Foo.php')
104104
->setClassName(DerivedClass::class)
105-
->addExtends(ConcreteClass::class, 1)
106105
->build();
107106

108107
$violations = new Violations();

tests/Unit/Expressions/ForClasses/IsATest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ public function test_it_should_have_no_violation_when_it_extends(): void
3838
$classDescription = (new ClassDescriptionBuilder())
3939
->setFilePath('src/Foo.php')
4040
->setClassName(DwarfCavendishBanana::class)
41-
->addExtends($class, 10)
4241
->build();
4342

4443
$violations = new Violations();

tests/Unit/Expressions/ForClasses/NotExtendTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ public function test_it_should_detect_grandparent_as_violation_via_reflection():
8383
$classDescription = (new ClassDescriptionBuilder())
8484
->setFilePath('src/Foo.php')
8585
->setClassName(ChildClass::class)
86-
->addExtends(MiddleClass::class, 1)
8786
->build();
8887

8988
$violations = new Violations();

tests/Unit/Expressions/ForClasses/NotHaveTraitTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ public function test_it_should_detect_trait_inherited_from_parent_as_violation_v
164164
$classDescription = (new ClassDescriptionBuilder())
165165
->setFilePath('src/Foo.php')
166166
->setClassName(ChildInheritingSomeTrait::class)
167-
->addExtends(ClassUsingSomeTrait::class, 1)
168167
->build();
169168

170169
$violations = new Violations();

0 commit comments

Comments
 (0)