Skip to content

Commit fafad34

Browse files
fain182claude
andcommitted
refactor: simplify parseCode helper method signature
Remove redundant filePath parameter since all tests use the same 'relativePathName' value. This further reduces boilerplate and makes the helper method calls more concise. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 2db7701 commit fafad34

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

tests/Unit/Analyzer/FileParser/CanParseClassTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Arkitect\Tests\Unit\Analyzer;
5+
namespace Arkitect\Tests\Unit\Analyzer\FileParser;
66

77
use Arkitect\Analyzer\ClassDependency;
88
use Arkitect\Analyzer\ClassDescription;
@@ -38,14 +38,14 @@ public function __construct(Request $request)
3838
}
3939
EOF;
4040

41-
$classDescriptions = $this->parseCode($code, 'path/to/class.php');
41+
$classDescriptions = $this->parseCode($code);
4242

4343
$dependsOnTheseNamespaces = new DependsOnlyOnTheseNamespaces(['Foo']);
4444
$violations = $this->evaluateRule($dependsOnTheseNamespaces, $classDescriptions[0], 'because');
4545

4646
self::assertCount(2, $violations);
47-
self::assertEquals('path/to/class.php', $violations->get(0)->getFilePath());
48-
self::assertEquals('path/to/class.php', $violations->get(1)->getFilePath());
47+
self::assertEquals('relativePathName', $violations->get(0)->getFilePath());
48+
self::assertEquals('relativePathName', $violations->get(1)->getFilePath());
4949
}
5050

5151
public function test_should_parse_instanceof(): void
@@ -443,7 +443,7 @@ class Test implements Order
443443

444444
EOF;
445445

446-
$cd = $this->parseCode($code, 'relativePathName', TargetPhpVersion::PHP_8_1);
446+
$cd = $this->parseCode($code, TargetPhpVersion::PHP_8_1);
447447
$cd = $cd[2]; // class Test
448448

449449
$implement = new Implement('Foo\Order');
@@ -467,7 +467,7 @@ public function getBookList(): QueryBuilder;
467467
}
468468
EOF;
469469

470-
$cd = $this->parseCode($code, 'relativePathName', TargetPhpVersion::PHP_8_1);
470+
$cd = $this->parseCode($code, TargetPhpVersion::PHP_8_1);
471471

472472
$dependsOnTheseNamespaces = new DependsOnlyOnTheseNamespaces(['MyProject\AppBundle\Application']);
473473
$violations = $this->evaluateRule($dependsOnTheseNamespaces, $cd[0], 'we want to add this rule for our software');
@@ -499,7 +499,7 @@ public function foobar();
499499
}
500500
EOF;
501501

502-
$cd = $this->parseCode($code, 'relativePathName', TargetPhpVersion::PHP_8_1);
502+
$cd = $this->parseCode($code, TargetPhpVersion::PHP_8_1);
503503

504504
self::assertCount(3, $cd);
505505
self::assertEquals('MyProject\AppBundle\Application\FooAble', $cd[2]->getExtends()[0]->toString());
@@ -551,7 +551,7 @@ public function __construct() {
551551
}
552552
EOF;
553553

554-
$cd = $this->parseCode($code, 'relativePathName', TargetPhpVersion::PHP_8_4);
554+
$cd = $this->parseCode($code, TargetPhpVersion::PHP_8_4);
555555
$isFinal = new IsFinal();
556556
$violations = $this->evaluateRule($isFinal, $cd[0], 'we want to add this rule for our software');
557557

@@ -573,7 +573,7 @@ abstract public function foo() {}
573573
}
574574
EOF;
575575

576-
$cd = $this->parseCode($code, 'relativePathName', TargetPhpVersion::PHP_8_4);
576+
$cd = $this->parseCode($code, TargetPhpVersion::PHP_8_4);
577577
$isAbstract = new IsAbstract();
578578
$violations = $this->evaluateRule($isAbstract, $cd[0], 'we want to add this rule for our software');
579579

@@ -593,17 +593,17 @@ public function __construct() {
593593
}
594594
EOF;
595595

596-
$cd = $this->parseCode($code, 'relativePathName', TargetPhpVersion::PHP_8_4);
596+
$cd = $this->parseCode($code, TargetPhpVersion::PHP_8_4);
597597
$isReadOnly = new IsReadonly();
598598
$violations = $this->evaluateRule($isReadOnly, $cd[0], 'we want to add this rule for our software');
599599

600600
self::assertCount(0, $violations);
601601
}
602602

603-
private function parseCode(string $code, string $filePath = 'relativePathName', ?string $version = null): array
603+
private function parseCode(string $code, ?string $version = null): array
604604
{
605605
$fp = FileParserFactory::forPhpVersion($version ?? TargetPhpVersion::PHP_7_4);
606-
$fp->parse($code, $filePath);
606+
$fp->parse($code, 'relativePathName');
607607

608608
return $fp->getClassDescriptions();
609609
}

0 commit comments

Comments
 (0)