Skip to content

Commit

Permalink
Merge pull request #853 from dbrumann/astrunner_unused_dependency
Browse files Browse the repository at this point in the history
Remove unused dependency from AstRunner and its dependencies.
  • Loading branch information
Denis Brumann authored Apr 10, 2022
2 parents 365d270 + 84df1d4 commit d17a2c2
Show file tree
Hide file tree
Showing 14 changed files with 17 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/Analyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __construct(

public function analyse(Configuration $configuration): Context
{
$astMap = $this->astRunner->createAstMapByFiles($this->fileResolver->resolve($configuration), $configuration->getAnalyser());
$astMap = $this->astRunner->createAstMapByFiles($this->fileResolver->resolve($configuration));
$dependencyResult = $this->resolver->resolve($astMap, $configuration->getAnalyser());
$classLikeLayerResolver = $this->classLikeLayerResolverFactory->create($configuration, $astMap);

Expand Down
3 changes: 1 addition & 2 deletions src/AstRunner/AstParser/AstParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
namespace Qossmic\Deptrac\AstRunner\AstParser;

use Qossmic\Deptrac\AstRunner\AstMap\AstFileReference;
use Qossmic\Deptrac\Configuration\ConfigurationAnalyser;

interface AstParser
{
public function parseFile(string $file, ConfigurationAnalyser $configuration): AstFileReference;
public function parseFile(string $file): AstFileReference;
}
3 changes: 1 addition & 2 deletions src/AstRunner/AstParser/NikicPhpParser/NikicPhpParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Qossmic\Deptrac\AstRunner\AstParser\Cache\AstFileReferenceCacheInterface;
use Qossmic\Deptrac\AstRunner\Resolver\DependencyResolver;
use Qossmic\Deptrac\AstRunner\Resolver\TypeResolver;
use Qossmic\Deptrac\Configuration\ConfigurationAnalyser;
use Qossmic\Deptrac\Exception\ShouldNotHappenException;
use Qossmic\Deptrac\File\FileReader;

Expand Down Expand Up @@ -57,7 +56,7 @@ public function __construct(
$this->traverser->addVisitor(new NameResolver());
}

public function parseFile(string $file, ConfigurationAnalyser $configuration): AstFileReference
public function parseFile(string $file): AstFileReference
{
if (null !== $fileReference = $this->cache->get($file)) {
return $fileReference;
Expand Down
5 changes: 2 additions & 3 deletions src/AstRunner/AstRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Qossmic\Deptrac\AstRunner\Event\AstFileSyntaxErrorEvent;
use Qossmic\Deptrac\AstRunner\Event\PostCreateAstMapEvent;
use Qossmic\Deptrac\AstRunner\Event\PreCreateAstMapEvent;
use Qossmic\Deptrac\Configuration\ConfigurationAnalyser;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

class AstRunner
Expand All @@ -27,15 +26,15 @@ public function __construct(EventDispatcherInterface $dispatcher, AstParser $ast
/**
* @param string[] $files
*/
public function createAstMapByFiles(array $files, ConfigurationAnalyser $configuration): AstMap
public function createAstMapByFiles(array $files): AstMap
{
$references = [];

$this->dispatcher->dispatch(new PreCreateAstMapEvent(count($files)));

foreach ($files as $file) {
try {
$references[] = $this->astParser->parseFile($file, $configuration);
$references[] = $this->astParser->parseFile($file);

$this->dispatcher->dispatch(new AstFileAnalysedEvent($file));
} catch (Error $e) {
Expand Down
2 changes: 1 addition & 1 deletion src/LayerAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct(
*/
public function analyse(Configuration $configuration, string $layer): array
{
$astMap = $this->astRunner->createAstMapByFiles($this->fileResolver->resolve($configuration), $configuration->getAnalyser());
$astMap = $this->astRunner->createAstMapByFiles($this->fileResolver->resolve($configuration));
$classLikeLayerResolver = $this->classLikeLayerResolverFactory->create($configuration, $astMap);

$tokenNames = [];
Expand Down
2 changes: 1 addition & 1 deletion src/TokenAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(
*/
public function analyse(Configuration $configuration, TokenName $tokenName): array
{
$astMap = $this->astRunner->createAstMapByFiles($this->fileResolver->resolve($configuration), $configuration->getAnalyser());
$astMap = $this->astRunner->createAstMapByFiles($this->fileResolver->resolve($configuration));

return $this->tokenLayerResolverFactory
->create($configuration, $astMap)
Expand Down
2 changes: 1 addition & 1 deletion src/UnassignedAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(
*/
public function analyse(Configuration $configuration): array
{
$astMap = $this->astRunner->createAstMapByFiles($this->fileResolver->resolve($configuration), $configuration->getAnalyser());
$astMap = $this->astRunner->createAstMapByFiles($this->fileResolver->resolve($configuration));
$tokenLayerResolver = $this->tokenLayerResolverFactory->create($configuration, $astMap);

/** @var string[] $tokenNames */
Expand Down
4 changes: 1 addition & 3 deletions tests/AstRunner/AstMapFlattenGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Qossmic\Deptrac\AstRunner\AstParser\NikicPhpParser\ParserFactory;
use Qossmic\Deptrac\AstRunner\AstRunner;
use Qossmic\Deptrac\AstRunner\Resolver\TypeResolver;
use Qossmic\Deptrac\Configuration\ConfigurationAnalyser;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Tests\Qossmic\Deptrac\AstRunner\Visitor\Fixtures\FixtureBasicInheritanceA;
use Tests\Qossmic\Deptrac\AstRunner\Visitor\Fixtures\FixtureBasicInheritanceB;
Expand Down Expand Up @@ -48,8 +47,7 @@ private function getAstMap(string $fixture): AstMap
)
);

return $astRunner->createAstMapByFiles([__DIR__.'/Fixtures/BasicInheritance/'.$fixture.'.php'], ConfigurationAnalyser::fromArray(
[]));
return $astRunner->createAstMapByFiles([__DIR__.'/Fixtures/BasicInheritance/'.$fixture.'.php']);
}

private function getInheritedInherits(string $class, AstMap $astMap): array
Expand Down
3 changes: 1 addition & 2 deletions tests/AstRunner/AstMapGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Qossmic\Deptrac\AstRunner\Resolver\AnonymousClassResolver;
use Qossmic\Deptrac\AstRunner\Resolver\ClassConstantResolver;
use Qossmic\Deptrac\AstRunner\Resolver\TypeResolver;
use Qossmic\Deptrac\Configuration\ConfigurationAnalyser;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Tests\Qossmic\Deptrac\AstRunner\Visitor\Fixtures\BasicDependency\BasicDependencyClassB;
use Tests\Qossmic\Deptrac\AstRunner\Visitor\Fixtures\BasicDependency\BasicDependencyClassC;
Expand Down Expand Up @@ -44,7 +43,7 @@ private function getAstMap(string $fixture): AstMap
)
);

return $astRunner->createAstMapByFiles([$fixture], ConfigurationAnalyser::fromArray([]));
return $astRunner->createAstMapByFiles([$fixture]);
}

public function testBasicDependencyClass(): void
Expand Down
24 changes: 3 additions & 21 deletions tests/AstRunner/AstParser/NikicPhpParser/NikicPhpParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
use Qossmic\Deptrac\AstRunner\AstParser\NikicPhpParser\NikicPhpParser;
use Qossmic\Deptrac\AstRunner\AstParser\NikicPhpParser\ParserFactory;
use Qossmic\Deptrac\AstRunner\Resolver\TypeResolver;
use Qossmic\Deptrac\Configuration\Configuration;
use Qossmic\Deptrac\Configuration\ConfigurationAnalyser;
use stdClass;
use TypeError;

Expand All @@ -31,7 +29,7 @@ protected function setUp(): void
public function testParseWithInvalidData(): void
{
$this->expectException(TypeError::class);
$this->parser->parseFile(new stdClass(), ConfigurationAnalyser::fromArray([]));
$this->parser->parseFile(new stdClass());
}

public function testParseDoesNotIgnoreUsesByDefault(): void
Expand All @@ -44,15 +42,7 @@ public function testParseDoesNotIgnoreUsesByDefault(): void
);

$filePath = __DIR__.'/Fixtures/CountingUseStatements.php';
$configuration = Configuration::fromArray(
[
'layers' => [],
'paths' => [],
'ruleset' => [],
'parameters' => [],
]
);
self::assertCount(1, $parser->parseFile($filePath, $configuration->getAnalyser())->getDependencies());
self::assertCount(1, $parser->parseFile($filePath)->getDependencies());
}

/**
Expand All @@ -68,15 +58,7 @@ public function testParseAttributes(): void
);

$filePath = __DIR__.'/Fixtures/Attributes.php';
$configuration = Configuration::fromArray(
[
'layers' => [],
'paths' => [],
'ruleset' => [],
'parameters' => [],
]
);
$astFileReference = $parser->parseFile($filePath, $configuration->getAnalyser());
$astFileReference = $parser->parseFile($filePath);
$astClassReferences = $astFileReference->getAstClassReferences();
self::assertCount(7, $astClassReferences[0]->getDependencies());
self::assertCount(2, $astClassReferences[1]->getDependencies());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Qossmic\Deptrac\AstRunner\AstParser\NikicPhpParser\ParserFactory;
use Qossmic\Deptrac\AstRunner\Resolver\AnnotationDependencyResolver;
use Qossmic\Deptrac\AstRunner\Resolver\TypeResolver;
use Qossmic\Deptrac\Configuration\ConfigurationAnalyser;

final class AnnotationDependencyResolverTest extends TestCase
{
Expand All @@ -25,7 +24,7 @@ public function testPropertyDependencyResolving(): void
);

$filePath = __DIR__.'/Fixtures/AnnotationDependency.php';
$astFileReference = $parser->parseFile($filePath, ConfigurationAnalyser::fromArray([]));
$astFileReference = $parser->parseFile($filePath);

$astClassReferences = $astFileReference->getAstClassReferences();
$annotationDependency = $astClassReferences[0]->getDependencies();
Expand Down
3 changes: 1 addition & 2 deletions tests/AstRunner/Resolver/AnonymousClassResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Qossmic\Deptrac\AstRunner\AstParser\NikicPhpParser\ParserFactory;
use Qossmic\Deptrac\AstRunner\Resolver\AnonymousClassResolver;
use Qossmic\Deptrac\AstRunner\Resolver\TypeResolver;
use Qossmic\Deptrac\Configuration\ConfigurationAnalyser;

final class AnonymousClassResolverTest extends TestCase
{
Expand All @@ -24,7 +23,7 @@ public function testPropertyDependencyResolving(): void
);

$filePath = __DIR__.'/Fixtures/AnonymousClass.php';
$astFileReference = $parser->parseFile($filePath, ConfigurationAnalyser::fromArray([]));
$astFileReference = $parser->parseFile($filePath);

$astClassReferences = $astFileReference->getAstClassReferences();

Expand Down
3 changes: 1 addition & 2 deletions tests/AstRunner/Resolver/ClassConstantResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Qossmic\Deptrac\AstRunner\AstParser\NikicPhpParser\ParserFactory;
use Qossmic\Deptrac\AstRunner\Resolver\ClassConstantResolver;
use Qossmic\Deptrac\AstRunner\Resolver\TypeResolver;
use Qossmic\Deptrac\Configuration\ConfigurationAnalyser;

final class ClassConstantResolverTest extends TestCase
{
Expand All @@ -24,7 +23,7 @@ public function testPropertyDependencyResolving(): void
);

$filePath = __DIR__.'/Fixtures/ClassConst.php';
$astFileReference = $parser->parseFile($filePath, ConfigurationAnalyser::fromArray([]));
$astFileReference = $parser->parseFile($filePath);

$astClassReferences = $astFileReference->getAstClassReferences();

Expand Down
4 changes: 1 addition & 3 deletions tests/DependencyEmitter/EmitterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Qossmic\Deptrac\AstRunner\AstRunner;
use Qossmic\Deptrac\AstRunner\Resolver\AnonymousClassResolver;
use Qossmic\Deptrac\AstRunner\Resolver\TypeResolver;
use Qossmic\Deptrac\Configuration\ConfigurationAnalyser;
use Qossmic\Deptrac\Dependency\DependencyInterface;
use Qossmic\Deptrac\Dependency\Result;
use Qossmic\Deptrac\DependencyEmitter\DependencyEmitterInterface;
Expand All @@ -31,8 +30,7 @@ public function getDeps(DependencyEmitterInterface $emitter, $files): array
new TypeResolver(),
new AnonymousClassResolver()
);
$astMap = (new AstRunner(new EventDispatcher(), $parser))->createAstMapByFiles($files, ConfigurationAnalyser::fromArray(
[]));
$astMap = (new AstRunner(new EventDispatcher(), $parser))->createAstMapByFiles($files);
$result = new Result();

$emitter->applyDependencies($astMap, $result);
Expand Down

0 comments on commit d17a2c2

Please sign in to comment.