Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement ConfigBuilder #1002

Merged
merged 39 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
d75ecb2
research symfony/config configbuildergenerator
Oct 4, 2022
5a66193
add value as configurable
Oct 5, 2022
87fe145
change value config to variable and add private config
Oct 5, 2022
1e9f01c
add Collectors by their fqn
Oct 6, 2022
0020ea9
fix test
Oct 6, 2022
dd45d67
move configbuilder into nicer dir
Oct 10, 2022
57ac9d5
implement configbuilders
Oct 11, 2022
bba8a36
update configbuilder
Oct 12, 2022
a803b89
tmp
Oct 13, 2022
4b2b883
add emittertypes
Oct 13, 2022
e02d400
update defaults for bool flags
Oct 14, 2022
62473a0
add baseline parsing
Oct 14, 2022
607b2ed
only export values if set
Oct 14, 2022
d877a47
remove generated configbuilder
Oct 14, 2022
12fac0b
configure services
Oct 14, 2022
f0ff50e
add DocBlock to array
Oct 15, 2022
395ad0a
fix psalm stuff
Oct 15, 2022
edf5670
remove unused layers
Oct 15, 2022
cdce7ef
move config to contract namespace
Nov 1, 2022
668e657
move types to contract namespace
Nov 1, 2022
d43b6a1
fix typo
Nov 11, 2022
c12da13
wip
Nov 11, 2022
e96a100
implement graphviz fromatterconfig
Nov 18, 2022
34ec119
only set private if true
Nov 19, 2022
ea4b488
use deptrac.config.php as default make command
Nov 19, 2022
bab7b9b
implement codeclimateconfig
Nov 20, 2022
7165fe7
add all other CollectorConfigs
Nov 20, 2022
6cb4846
add excludeFiles
Nov 25, 2022
3746ec9
remove readonly
Nov 27, 2022
0f0dab0
cleanup collector creation
Nov 27, 2022
33a39e5
fix cs
Dec 6, 2022
81a79d5
fix deptrac.config.php
Dec 6, 2022
d6ec68a
comment in xdebughandler
Jan 20, 2023
322adfb
fix rebase
Jan 20, 2023
c5eeff3
add throws ParseException
Jan 20, 2023
789c7f3
fix deptrac.config.php
Jan 20, 2023
986a594
cleanup ServiceContainerBuilder
Jan 20, 2023
30d4d9f
remove duplicate method
Jan 20, 2023
94af79f
cleanup
gennadigennadigennadi Mar 31, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ phpstan:
$(PHPSTAN_BIN) analyse --memory-limit=256M

deptrac:
$(PHP_BIN) deptrac.php analyse --no-progress --ansi
$(PHP_BIN) deptrac.php --config-file=deptrac.config.php analyse --no-progress --ansi

psalm:
$(PSALM_BIN)
Expand Down
4 changes: 2 additions & 2 deletions config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use PhpParser\ParserFactory;
use Psr\EventDispatcher\EventDispatcherInterface;
use Qossmic\Deptrac\Contract\Analyser\EventHelper;
use Qossmic\Deptrac\Contract\Config\CollectorType;
use Qossmic\Deptrac\Contract\Config\EmitterType;
use Qossmic\Deptrac\Contract\Layer\LayerProvider;
use Qossmic\Deptrac\Core\Analyser\DependencyLayersAnalyser;
use Qossmic\Deptrac\Core\Analyser\EventHandler\AllowDependencyHandler;
Expand Down Expand Up @@ -55,7 +57,6 @@
use Qossmic\Deptrac\Core\Layer\Collector\CollectorProvider;
use Qossmic\Deptrac\Core\Layer\Collector\CollectorResolver;
use Qossmic\Deptrac\Core\Layer\Collector\CollectorResolverInterface;
use Qossmic\Deptrac\Core\Layer\Collector\CollectorType;
use Qossmic\Deptrac\Core\Layer\Collector\DirectoryCollector;
use Qossmic\Deptrac\Core\Layer\Collector\ExtendsCollector;
use Qossmic\Deptrac\Core\Layer\Collector\FunctionNameCollector;
Expand All @@ -81,7 +82,6 @@
use Qossmic\Deptrac\Supportive\Console\Command\DebugUnassignedCommand;
use Qossmic\Deptrac\Supportive\Console\Command\DebugUnassignedRunner;
use Qossmic\Deptrac\Supportive\Console\Command\InitCommand;
use Qossmic\Deptrac\Supportive\DependencyInjection\EmitterType;
use Qossmic\Deptrac\Supportive\File\Dumper;
use Qossmic\Deptrac\Supportive\File\YmlFileLoader;
use Qossmic\Deptrac\Supportive\OutputFormatter\BaselineOutputFormatter;
Expand Down
8 changes: 0 additions & 8 deletions deptrac.baseline.yaml

This file was deleted.

89 changes: 89 additions & 0 deletions deptrac.config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

use Internal\Qossmic\Deptrac\IgnoreDependenciesOnContract;
use Qossmic\Deptrac\Contract\Analyser\ProcessEvent;
use Qossmic\Deptrac\Contract\Config\Collector\BoolConfig;
use Qossmic\Deptrac\Contract\Config\Collector\ClassNameConfig;
use Qossmic\Deptrac\Contract\Config\Collector\DirectoryConfig;
use Qossmic\Deptrac\Contract\Config\DeptracConfig;
use Qossmic\Deptrac\Contract\Config\EmitterType;
use Qossmic\Deptrac\Contract\Config\Formatter\GraphvizConfig;
use Qossmic\Deptrac\Contract\Config\Layer;
use Qossmic\Deptrac\Contract\Config\Ruleset;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (DeptracConfig $config, ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(IgnoreDependenciesOnContract::class)->tag('kernel.event_listener', ['event' => ProcessEvent::class]);

$config
->paths('src')
->analysers(
EmitterType::CLASS_TOKEN,
EmitterType::CLASS_SUPERGLOBAL_TOKEN,
EmitterType::FILE_TOKEN,
EmitterType::FUNCTION_TOKEN,
EmitterType::FUNCTION_SUPERGLOBAL_TOKEN,
EmitterType::FUNCTION_CALL,
)
->layers(
$analyser = Layer::withName('Analyser')->collectors(
DirectoryConfig::create('src/Core/Analyser/.*')
),
$ast = Layer::withName('Ast')->collectors(
DirectoryConfig::create('src/Core/Ast/.*'),
ClassNameConfig::create('^PHPStan\\PhpDocParser\\.*')->private(),
ClassNameConfig::create('^PhpParser\\.*')->private(),
ClassNameConfig::create('^phpDocumentor\\Reflection\\.*')->private(),
),
$console = Layer::withName('Console')->collectors(
DirectoryConfig::create('src/Supportive/Console/.*')
),
$dependency = Layer::withName('Dependency')->collectors(
DirectoryConfig::create('src/Core/Dependency/.*')
),
$dependencyInjection = Layer::withName('DependencyInjection')->collectors(
DirectoryConfig::create('src/Supportive/DependencyInjection/.*')
),
$contract = Layer::withName('Contract')->collectors(
DirectoryConfig::create('src/Contract/.*')
),
$inputCollector = Layer::withName('InputCollector')->collectors(
DirectoryConfig::create('src/Core/InputCollector/.*')
),
$layer = Layer::withName('Layer')->collectors(
DirectoryConfig::create('src/Core/Layer/.*')
),
$outputFormatter = Layer::withName('OutputFormatter')->collectors(
DirectoryConfig::create('src/Supportive/OutputFormatter/.*'),
ClassNameConfig::create('^phpDocumentor\\GraphViz\\.*')->private(),
),
$file = Layer::withName('File')->collectors(
DirectoryConfig::create('src/Supportive/File/.*')
),
$supportive = Layer::withName('Supportive')->collectors(
BoolConfig::create()
->mustNot(DirectoryConfig::create('src/Supportive/.*/.*'))
->must(DirectoryConfig::create('src/Supportive/.*'))
),
)
->rulesets(
Ruleset::forLayer($layer)->accesses($ast),
Ruleset::forLayer($console)->accesses($analyser, $outputFormatter, $dependencyInjection, $file),
Ruleset::forLayer($dependency)->accesses($ast),
Ruleset::forLayer($analyser)->accesses($layer, $dependency, $ast),
Ruleset::forLayer($outputFormatter)->accesses($console, $dependencyInjection),
Ruleset::forLayer($ast)->accesses($file, $inputCollector),
Ruleset::forLayer($inputCollector)->accesses($file),
Ruleset::forLayer($supportive)->accesses($file),
Ruleset::forLayer($contract),
)
->formatters(
GraphvizConfig::create()
->pointsToGroup(true)
->groups('Contract', $contract)
->groups('Supportive', $supportive, $file)
->groups('Symfony', $console, $dependencyInjection, $outputFormatter)
->groups('Core', $analyser, $ast, $dependency, $inputCollector, $layer)
);
};
9 changes: 0 additions & 9 deletions deptrac.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
imports:
- deptrac.baseline.yaml

services:
- class: Internal\Qossmic\Deptrac\IgnoreDependenciesOnContract
tags:
Expand Down Expand Up @@ -113,19 +110,13 @@ deptrac:
- File
gennadigennadigennadi marked this conversation as resolved.
Show resolved Hide resolved
Dependency:
- Ast
Result:
- Dependency
Analyser:
- Result
- Layer
- Dependency
- Ast
OutputFormatter:
- Result
- Console
- DependencyInjection
Events:
- Result
Ast:
- File
- InputCollector
Expand Down
12 changes: 12 additions & 0 deletions src/Contract/Config/CodeclimateLevelEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Qossmic\Deptrac\Contract\Config;

enum CodeclimateLevelEnum: string
{
case INFO = 'info';
case MINOR = 'minor';
case MAJOR = 'major';
case CRITICAL = 'critical';
case BLOCKER = 'blocker';
}
11 changes: 11 additions & 0 deletions src/Contract/Config/Collector/AttributeConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Qossmic\Deptrac\Contract\Config\Collector;

use Qossmic\Deptrac\Contract\Config\CollectorType;
use Qossmic\Deptrac\Contract\Config\ConfigurableCollectorConfig;

final class AttributeConfig extends ConfigurableCollectorConfig
{
protected CollectorType $collectorType = CollectorType::TYPE_ATTRIBUTE;
}
73 changes: 73 additions & 0 deletions src/Contract/Config/Collector/BoolConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

namespace Qossmic\Deptrac\Contract\Config\Collector;

use Qossmic\Deptrac\Contract\Config\CollectorConfig;
use Qossmic\Deptrac\Contract\Config\CollectorType;

final class BoolConfig extends CollectorConfig
{
protected CollectorType $collectorType = CollectorType::TYPE_BOOL;

/** @var array<CollectorConfig> */
private array $mustNot = [];

/** @var array<CollectorConfig> */
private array $must = [];

private function __construct()
{
}

/**
* @param array<CollectorConfig> $must
* @param array<CollectorConfig> $mostNot
*/
public static function create(array $must = [], array $mostNot = []): self
{
return (new self())
->must(...$must)
->mustNot(...$mostNot);
}

public function private(): self
{
$this->private = true;

return $this;
}

public function mustNot(CollectorConfig ...$collectorConfigs): self
{
foreach ($collectorConfigs as $collectorConfig) {
$this->mustNot[] = $collectorConfig;
}

return $this;
}

public function must(CollectorConfig ...$collectorConfigs): self
{
foreach ($collectorConfigs as $collectorConfig) {
$this->must[] = $collectorConfig;
}

return $this;
}

/** @return array{
* must: array<array-key, array{private: bool, type: string}>|mixed,
* must_not: array<array-key, array{private: bool, type: string}>|mixed,
* private: bool,
* type: string}
*/
public function toArray(): array
{
return [
'must_not' => array_map(static fn (CollectorConfig $v) => $v->toArray(), $this->mustNot),
'must' => array_map(static fn (CollectorConfig $v) => $v->toArray(), $this->must),
'private' => $this->private,
'type' => $this->collectorType->value,
];
}
}
11 changes: 11 additions & 0 deletions src/Contract/Config/Collector/ClassConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Qossmic\Deptrac\Contract\Config\Collector;

use Qossmic\Deptrac\Contract\Config\CollectorType;
use Qossmic\Deptrac\Contract\Config\ConfigurableCollectorConfig;

final class ClassConfig extends ConfigurableCollectorConfig
{
protected CollectorType $collectorType = CollectorType::TYPE_CLASS;
}
11 changes: 11 additions & 0 deletions src/Contract/Config/Collector/ClassLikeConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Qossmic\Deptrac\Contract\Config\Collector;

use Qossmic\Deptrac\Contract\Config\CollectorType;
use Qossmic\Deptrac\Contract\Config\ConfigurableCollectorConfig;

final class ClassLikeConfig extends ConfigurableCollectorConfig
{
protected CollectorType $collectorType = CollectorType::TYPE_CLASSLIKE;
}
11 changes: 11 additions & 0 deletions src/Contract/Config/Collector/ClassNameConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Qossmic\Deptrac\Contract\Config\Collector;

use Qossmic\Deptrac\Contract\Config\CollectorType;
use Qossmic\Deptrac\Contract\Config\ConfigurableCollectorConfig;

final class ClassNameConfig extends ConfigurableCollectorConfig
{
protected CollectorType $collectorType = CollectorType::TYPE_CLASS_NAME;
}
11 changes: 11 additions & 0 deletions src/Contract/Config/Collector/DirectoryConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Qossmic\Deptrac\Contract\Config\Collector;

use Qossmic\Deptrac\Contract\Config\CollectorType;
use Qossmic\Deptrac\Contract\Config\ConfigurableCollectorConfig;

final class DirectoryConfig extends ConfigurableCollectorConfig
{
protected CollectorType $collectorType = CollectorType::TYPE_DIRECTORY;
}
11 changes: 11 additions & 0 deletions src/Contract/Config/Collector/ExtendsConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Qossmic\Deptrac\Contract\Config\Collector;

use Qossmic\Deptrac\Contract\Config\CollectorType;
use Qossmic\Deptrac\Contract\Config\ConfigurableCollectorConfig;

final class ExtendsConfig extends ConfigurableCollectorConfig
{
protected CollectorType $collectorType = CollectorType::TYPE_EXTENDS;
}
11 changes: 11 additions & 0 deletions src/Contract/Config/Collector/FunctionNameConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Qossmic\Deptrac\Contract\Config\Collector;

use Qossmic\Deptrac\Contract\Config\CollectorType;
use Qossmic\Deptrac\Contract\Config\ConfigurableCollectorConfig;

final class FunctionNameConfig extends ConfigurableCollectorConfig
{
protected CollectorType $collectorType = CollectorType::TYPE_FUNCTION_NAME;
}
11 changes: 11 additions & 0 deletions src/Contract/Config/Collector/GlobConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Qossmic\Deptrac\Contract\Config\Collector;

use Qossmic\Deptrac\Contract\Config\CollectorType;
use Qossmic\Deptrac\Contract\Config\ConfigurableCollectorConfig;

final class GlobConfig extends ConfigurableCollectorConfig
{
protected CollectorType $collectorType = CollectorType::TYPE_GLOB;
}
11 changes: 11 additions & 0 deletions src/Contract/Config/Collector/ImplementsConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Qossmic\Deptrac\Contract\Config\Collector;

use Qossmic\Deptrac\Contract\Config\CollectorType;
use Qossmic\Deptrac\Contract\Config\ConfigurableCollectorConfig;

final class ImplementsConfig extends ConfigurableCollectorConfig
{
protected CollectorType $collectorType = CollectorType::TYPE_IMPLEMENTS;
}
11 changes: 11 additions & 0 deletions src/Contract/Config/Collector/InheritsConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Qossmic\Deptrac\Contract\Config\Collector;

use Qossmic\Deptrac\Contract\Config\CollectorType;
use Qossmic\Deptrac\Contract\Config\ConfigurableCollectorConfig;

final class InheritsConfig extends ConfigurableCollectorConfig
{
protected CollectorType $collectorType = CollectorType::TYPE_INHERITS;
}
11 changes: 11 additions & 0 deletions src/Contract/Config/Collector/InterfaceConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Qossmic\Deptrac\Contract\Config\Collector;

use Qossmic\Deptrac\Contract\Config\CollectorType;
use Qossmic\Deptrac\Contract\Config\ConfigurableCollectorConfig;

final class InterfaceConfig extends ConfigurableCollectorConfig
{
protected CollectorType $collectorType = CollectorType::TYPE_INTERFACE;
}
11 changes: 11 additions & 0 deletions src/Contract/Config/Collector/LayerConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Qossmic\Deptrac\Contract\Config\Collector;

use Qossmic\Deptrac\Contract\Config\CollectorType;
use Qossmic\Deptrac\Contract\Config\ConfigurableCollectorConfig;

final class LayerConfig extends ConfigurableCollectorConfig
{
protected CollectorType $collectorType = CollectorType::TYPE_LAYER;
}
Loading