Skip to content

Commit

Permalink
Merge pull request #527 from qossmic/debug-commands
Browse files Browse the repository at this point in the history
adds debug commands for layer and class-likes
  • Loading branch information
Simon Mönch authored Apr 16, 2021
2 parents d0bc2bf + 1820815 commit aa9f42b
Show file tree
Hide file tree
Showing 27 changed files with 640 additions and 158 deletions.
8 changes: 4 additions & 4 deletions .phive/phars.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="php-cs-fixer" version="^2.16.3" installed="2.18.2" location="./tools/php-cs-fixer" copy="true"/>
<phar name="phpunit" version="^8.5.13" installed="8.5.14" location="./tools/phpunit.phar" copy="true"/>
<phar name="phpstan" version="^0.12.29" installed="0.12.79" location="./tools/phpstan" copy="true"/>
<phar name="psalm" version="^4.3.0" installed="4.5.1" location="./tools/psalm" copy="true"/>
<phar name="php-cs-fixer" version="^2.16.3" installed="2.18.5" location="./tools/php-cs-fixer" copy="true"/>
<phar name="phpunit" version="^8.5.13" installed="8.5.15" location="./tools/phpunit.phar" copy="true"/>
<phar name="phpstan" version="^0.12.29" installed="0.12.83" location="./tools/phpstan" copy="true"/>
<phar name="psalm" version="^4.3.0" installed="4.7.0" location="./tools/psalm" copy="true"/>
<phar name="box-project/box" version="^3.12.2" installed="3.12.2" location="./tools/box" copy="true"/>
<phar name="infection" version="^0.20.1" installed="0.21.0" location="./tools/infection" copy="true"/>
</phive>
35 changes: 18 additions & 17 deletions baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.x-dev@">
<file src="src/AstRunner/AstParser/AstFileReferenceFileCache.php">
<UnnecessaryVarAnnotation occurrences="1">
<code>array&lt;string, array{hash: string, reference: AstFileReference}&gt;</code>
</UnnecessaryVarAnnotation>
</file>
<file src="src/AstRunner/AstParser/NikicPhpParser/ClassReferenceVisitor.php">
<MixedArgument occurrences="1">
<code>$className</code>
Expand Down Expand Up @@ -31,11 +36,6 @@
<code>self::$classAstMap[$classLikeName] ?? null</code>
</MixedReturnStatement>
</file>
<file src="src/ClassNameLayerResolver.php">
<MixedArgumentTypeCoercion occurrences="1">
<code>$configuration</code>
</MixedArgumentTypeCoercion>
</file>
<file src="src/Collector/BoolCollector.php">
<MixedArgument occurrences="2">
<code>$v</code>
Expand Down Expand Up @@ -147,6 +147,10 @@
<PossiblyUndefinedMethod occurrences="1">
<code>children</code>
</PossiblyUndefinedMethod>
<UnusedVariable occurrences="2">
<code>$remove</code>
<code>$removeKeyItem</code>
</UnusedVariable>
</file>
<file src="src/Configuration/Loader.php">
<MixedArgument occurrences="3">
Expand All @@ -166,20 +170,9 @@
</MixedAssignment>
</file>
<file src="src/Configuration/ParameterResolver.php">
<MixedArgument occurrences="1">
<MixedArgumentTypeCoercion occurrences="1">
<code>$value</code>
</MixedArgument>
<MixedArgumentTypeCoercion occurrences="2">
<code>$keys</code>
<code>array_values($parameters)</code>
</MixedArgumentTypeCoercion>
<MixedAssignment occurrences="1">
<code>$value</code>
</MixedAssignment>
<MixedReturnTypeCoercion occurrences="2">
<code>$values</code>
<code>array&lt;array-key, string|array&gt;</code>
</MixedReturnTypeCoercion>
</file>
<file src="src/OutputFormatter/BaselineOutputFormatter.php">
<MixedArgument occurrences="2">
Expand Down Expand Up @@ -208,6 +201,9 @@
<code>$dumpHtmlPath</code>
<code>$dumpImagePath</code>
</MixedAssignment>
<UnusedVariable occurrences="1">
<code>$layerDependOnCount</code>
</UnusedVariable>
</file>
<file src="src/OutputFormatter/JUnitOutputFormatter.php">
<MixedArgument occurrences="2">
Expand All @@ -227,6 +223,11 @@
<code>$dumpXmlPath</code>
</MixedAssignment>
</file>
<file src="src/OutputFormatterFactory.php">
<UnusedParam occurrences="1">
<code>$formatter</code>
</UnusedParam>
</file>
<file src="src/PathNameFilterIterator.php">
<MixedArgument occurrences="2">
<code>$filename</code>
Expand Down
54 changes: 47 additions & 7 deletions config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use Qossmic\Deptrac\AstRunner\Resolver\ClassConstantResolver;
use Qossmic\Deptrac\AstRunner\Resolver\PropertyTypeResolver;
use Qossmic\Deptrac\AstRunner\Resolver\TypeResolver;
use Qossmic\Deptrac\ClassLikeAnalyser;
use Qossmic\Deptrac\ClassLikeLayerResolverFactory;
use Qossmic\Deptrac\Collector\BoolCollector;
use Qossmic\Deptrac\Collector\ClassNameCollector;
use Qossmic\Deptrac\Collector\ClassNameRegexCollector;
Expand All @@ -30,12 +32,15 @@
use Qossmic\Deptrac\Configuration\Loader\YmlFileLoader;
use Qossmic\Deptrac\Configuration\ParameterResolver;
use Qossmic\Deptrac\Console\Command\AnalyzeCommand;
use Qossmic\Deptrac\Console\Command\DebugClassLikeCommand;
use Qossmic\Deptrac\Console\Command\DebugLayerCommand;
use Qossmic\Deptrac\Console\Command\InitCommand;
use Qossmic\Deptrac\Dependency\InheritanceFlatter;
use Qossmic\Deptrac\Dependency\Resolver;
use Qossmic\Deptrac\DependencyEmitter\BasicDependencyEmitter;
use Qossmic\Deptrac\DependencyEmitter\InheritanceDependencyEmitter;
use Qossmic\Deptrac\FileResolver;
use Qossmic\Deptrac\LayerAnalyser;
use Qossmic\Deptrac\OutputFormatter\BaselineOutputFormatter;
use Qossmic\Deptrac\OutputFormatter\ConsoleOutputFormatter;
use Qossmic\Deptrac\OutputFormatter\GithubActionsOutputFormatter;
Expand All @@ -55,7 +60,7 @@
$services = $container->services();

$services->defaults()
->private();
->public();

$services->set(EventDispatcher::class);

Expand Down Expand Up @@ -94,15 +99,38 @@
->set(PropertyTypeResolver::class)
->args([service(TypeResolver::class)]);

$services
->set(ClassLikeLayerResolverFactory::class)
->args([
service(Registry::class),
service(ParameterResolver::class),
]);

$services
->set(Analyser::class)
->args([
service(AstRunner::class),
service(FileResolver::class),
service(Resolver::class),
service(Registry::class),
service(RulesetEngine::class),
service(ParameterResolver::class),
service(ClassLikeLayerResolverFactory::class),
]);

$services
->set(ClassLikeAnalyser::class)
->args([
service(AstRunner::class),
service(FileResolver::class),
service(ClassLikeLayerResolverFactory::class),
]);

$services
->set(LayerAnalyser::class)
->args([
service(AstRunner::class),
service(FileResolver::class),
service(Resolver::class),
service(ClassLikeLayerResolverFactory::class),
]);

$services->set(RulesetEngine::class);
Expand Down Expand Up @@ -200,8 +228,7 @@
/* Commands */
$services
->set(InitCommand::class)
->args([service(Dumper::class)])
->public();
->args([service(Dumper::class)]);

$services
->set(AnalyzeCommand::class)
Expand All @@ -210,6 +237,19 @@
service(Loader::class),
service(EventDispatcher::class),
service(OutputFormatterFactory::class),
])
->public();
]);

$services
->set(DebugClassLikeCommand::class)
->args([
service(ClassLikeAnalyser::class),
service(Loader::class),
]);

$services
->set(DebugLayerCommand::class)
->args([
service(LayerAnalyser::class),
service(Loader::class),
]);
};
22 changes: 5 additions & 17 deletions src/Analyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
namespace Qossmic\Deptrac;

use Qossmic\Deptrac\AstRunner\AstRunner;
use Qossmic\Deptrac\Collector\Registry;
use Qossmic\Deptrac\Configuration\Configuration;
use Qossmic\Deptrac\Configuration\ParameterResolver;
use Qossmic\Deptrac\Dependency\Resolver;
use Qossmic\Deptrac\RulesetEngine\Context;

Expand All @@ -14,39 +12,29 @@ class Analyser
private $astRunner;
private $fileResolver;
private $resolver;
private $collectorRegistry;
private $rulesetEngine;
private $parameterResolver;
private $classLikeLayerResolverFactory;

public function __construct(
AstRunner $astRunner,
FileResolver $fileResolver,
Resolver $resolver,
Registry $collectorRegistry,
RulesetEngine $rulesetEngine,
ParameterResolver $parameterResolver
ClassLikeLayerResolverFactory $classLikeLayerResolverFactory
) {
$this->astRunner = $astRunner;
$this->fileResolver = $fileResolver;
$this->resolver = $resolver;
$this->collectorRegistry = $collectorRegistry;
$this->rulesetEngine = $rulesetEngine;
$this->parameterResolver = $parameterResolver;
$this->classLikeLayerResolverFactory = $classLikeLayerResolverFactory;
}

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

$classNameLayerResolver = new ClassNameLayerResolverCacheDecorator(
new ClassNameLayerResolver($configuration, $astMap, $this->collectorRegistry, $this->parameterResolver)
);

return $this->rulesetEngine->process(
$dependencyResult,
$classNameLayerResolver,
$configuration
);
return $this->rulesetEngine->process($dependencyResult, $classLikeLayerResolver, $configuration);
}
}
38 changes: 38 additions & 0 deletions src/ClassLikeAnalyser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace Qossmic\Deptrac;

use Qossmic\Deptrac\AstRunner\AstMap\ClassLikeName;
use Qossmic\Deptrac\AstRunner\AstRunner;
use Qossmic\Deptrac\Configuration\Configuration;

class ClassLikeAnalyser
{
private $astRunner;
private $fileResolver;
private $classLikeLayerResolverFactory;

public function __construct(
AstRunner $astRunner,
FileResolver $fileResolver,
ClassLikeLayerResolverFactory $classLikeLayerResolverFactory
) {
$this->astRunner = $astRunner;
$this->fileResolver = $fileResolver;
$this->classLikeLayerResolverFactory = $classLikeLayerResolverFactory;
}

/**
* @return string[]
*/
public function analyse(Configuration $configuration, ClassLikeName $classLikeName): array
{
$astMap = $this->astRunner->createAstMapByFiles($this->fileResolver->resolve($configuration));

return $this->classLikeLayerResolverFactory
->create($configuration, $astMap)
->getLayersByClassLikeName($classLikeName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Qossmic\Deptrac\Configuration\Configuration;
use Qossmic\Deptrac\Configuration\ParameterResolver;

class ClassNameLayerResolver implements ClassNameLayerResolverInterface
class ClassLikeLayerResolver implements ClassLikeLayerResolverInterface
{
private $configuration;
private $astMap;
Expand All @@ -33,7 +33,7 @@ public function __construct(
/**
* @return string[]
*/
public function getLayersByClassName(ClassLikeName $className): array
public function getLayersByClassLikeName(ClassLikeName $className): array
{
/** @var array<string, bool> $layers */
$layers = [];
Expand Down
34 changes: 34 additions & 0 deletions src/ClassLikeLayerResolverFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace Qossmic\Deptrac;

use Qossmic\Deptrac\AstRunner\AstMap;
use Qossmic\Deptrac\Collector\Registry;
use Qossmic\Deptrac\Configuration\Configuration;
use Qossmic\Deptrac\Configuration\ParameterResolver;

class ClassLikeLayerResolverFactory
{
private $registry;
private $parameterResolver;

public function __construct(Registry $registry, ParameterResolver $parameterResolver)
{
$this->registry = $registry;
$this->parameterResolver = $parameterResolver;
}

public function create(Configuration $configuration, AstMap $astMap): ClassLikeLayerResolverInterface
{
return new MemoizedClassLikeLayerResolver(
new ClassLikeLayerResolver(
$configuration,
$astMap,
$this->registry,
$this->parameterResolver
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

use Qossmic\Deptrac\AstRunner\AstMap\ClassLikeName;

interface ClassNameLayerResolverInterface
interface ClassLikeLayerResolverInterface
{
/**
* @return string[]
*/
public function getLayersByClassName(ClassLikeName $className): array;
public function getLayersByClassLikeName(ClassLikeName $className): array;
}
32 changes: 0 additions & 32 deletions src/ClassNameLayerResolverCacheDecorator.php

This file was deleted.

Loading

0 comments on commit aa9f42b

Please sign in to comment.