Skip to content

Commit be055de

Browse files
fain182claude
andcommitted
Remove ClassDescription::getInterfaces() — now dead code
Since Implement and NotImplement switched to pure reflection, getInterfaces() on ClassDescription was no longer read by any production expression. The data was collected but never used. - FileVisitor: replace addInterface() with addDependency() to preserve the dependency tracking (interfaces are still recorded as class dependencies, which is used by DependsOnlyOnTheseNamespaces etc.) - ClassDescriptionBuilder: remove addInterface() method and $interfaces field - ClassDescription: remove getInterfaces() method, $interfaces field, and the corresponding constructor parameter - Update tests that called addInterface() or getInterfaces() Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent dad181c commit be055de

File tree

6 files changed

+6
-35
lines changed

6 files changed

+6
-35
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 $interfaces;
18-
1916
/** @var list<FullyQualifiedClassName> */
2017
private array $extends;
2118

@@ -42,7 +39,6 @@ class ClassDescription
4239

4340
/**
4441
* @param list<ClassDependency> $dependencies
45-
* @param list<FullyQualifiedClassName> $interfaces
4642
* @param list<FullyQualifiedClassName> $extends
4743
* @param list<string> $docBlock
4844
* @param list<FullyQualifiedClassName> $attributes
@@ -51,7 +47,6 @@ class ClassDescription
5147
public function __construct(
5248
FullyQualifiedClassName $FQCN,
5349
array $dependencies,
54-
array $interfaces,
5550
array $extends,
5651
bool $final,
5752
bool $readonly,
@@ -67,7 +62,6 @@ public function __construct(
6762
$this->FQCN = $FQCN;
6863
$this->filePath = $filePath;
6964
$this->dependencies = $dependencies;
70-
$this->interfaces = $interfaces;
7165
$this->extends = $extends;
7266
$this->final = $final;
7367
$this->readonly = $readonly;
@@ -137,14 +131,6 @@ public function getDependencies(): array
137131
return $this->dependencies;
138132
}
139133

140-
/**
141-
* @return list<FullyQualifiedClassName>
142-
*/
143-
public function getInterfaces(): array
144-
{
145-
return $this->interfaces;
146-
}
147-
148134
/**
149135
* @return list<FullyQualifiedClassName>
150136
*/

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 $interfaces = [];
17-
1815
/** @var list<FullyQualifiedClassName> */
1916
private array $extends = [];
2017

@@ -45,7 +42,6 @@ public function clear(): void
4542
{
4643
$this->FQCN = null;
4744
$this->classDependencies = [];
48-
$this->interfaces = [];
4945
$this->extends = [];
5046
$this->final = false;
5147
$this->readonly = false;
@@ -72,14 +68,6 @@ public function setClassName(string $FQCN): self
7268
return $this;
7369
}
7470

75-
public function addInterface(string $FQCN, int $line): self
76-
{
77-
$this->addDependency(new ClassDependency($FQCN, $line));
78-
$this->interfaces[] = FullyQualifiedClassName::fromString($FQCN);
79-
80-
return $this;
81-
}
82-
8371
public function addDependency(ClassDependency $cd): self
8472
{
8573
if ($this->isPhpCoreClass($cd)) {
@@ -172,7 +160,6 @@ public function build(): ClassDescription
172160
return new ClassDescription(
173161
$this->FQCN,
174162
$this->classDependencies,
175-
$this->interfaces,
176163
$this->extends,
177164
$this->final,
178165
$this->readonly,

src/Analyzer/FileVisitor.php

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

130130
foreach ($node->implements as $interface) {
131131
$this->classDescriptionBuilder
132-
->addInterface($interface->toString(), $interface->getLine());
132+
->addDependency(new ClassDependency($interface->toString(), $interface->getLine()));
133133
}
134134

135135
if (null !== $node->extends) {
@@ -180,7 +180,7 @@ private function handleEnumNode(Node $node): void
180180

181181
foreach ($node->implements as $interface) {
182182
$this->classDescriptionBuilder
183-
->addInterface($interface->toString(), $interface->getLine());
183+
->addDependency(new ClassDependency($interface->toString(), $interface->getLine()));
184184
}
185185
}
186186

tests/Unit/Analyzer/ClassDescriptionBuilderTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@
1212

1313
class ClassDescriptionBuilderTest extends TestCase
1414
{
15-
public function test_it_should_create_builder_with_dependency_and_interface(): void
15+
public function test_it_should_create_builder_with_dependency(): void
1616
{
1717
$FQCN = 'HappyIsland';
1818

1919
$classDescription = (new ClassDescriptionBuilder())
2020
->setFilePath('src/Foo.php')
2121
->setClassName($FQCN)
2222
->addDependency(new ClassDependency('DepClass', 10))
23-
->addInterface('InterfaceClass', 10)
2423
->build();
2524

2625
self::assertInstanceOf(ClassDescription::class, $classDescription);

tests/Unit/Analyzer/FileParser/CanParseClassTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,9 +445,9 @@ class Test implements Order
445445
$cd = $this->parseCode($code, TargetPhpVersion::PHP_8_1);
446446
$cd = $cd[2]; // class Test
447447

448-
$interfaces = array_map(static fn ($i) => $i->toString(), $cd->getInterfaces());
449-
self::assertContains('Foo\Order', $interfaces);
450-
self::assertNotContains('Foo\OrderTwo', $interfaces);
448+
$deps = array_map(static fn ($d) => $d->getFQCN()->toString(), $cd->getDependencies());
449+
self::assertContains('Foo\Order', $deps);
450+
self::assertNotContains('Foo\OrderTwo', $deps);
451451
}
452452

453453
public function test_it_parse_interfaces(): void

tests/Unit/Expressions/ForClasses/IsATest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public function test_it_should_have_no_violation_when_it_implements(): void
2323
$classDescription = (new ClassDescriptionBuilder())
2424
->setFilePath('src/Foo.php')
2525
->setClassName(CavendishBanana::class)
26-
->addInterface($interface, 10)
2726
->build();
2827

2928
$violations = new Violations();

0 commit comments

Comments
 (0)