From d75ecb2c2eca9f2daa263e361100a1ccd58c1ad7 Mon Sep 17 00:00:00 2001 From: Gennadi McKelvey Date: Tue, 4 Oct 2022 18:19:26 +0200 Subject: [PATCH 01/39] research symfony/config configbuildergenerator --- Symfony/Config/Deptrac/AnalyserConfig.php | 52 ++++ .../Formatters/Codeclimate/SeverityConfig.php | 98 +++++++ .../Deptrac/Formatters/CodeclimateConfig.php | 56 ++++ .../Deptrac/Formatters/GraphvizConfig.php | 97 +++++++ Symfony/Config/Deptrac/FormattersConfig.php | 91 +++++++ Symfony/Config/Deptrac/LayersConfig.php | 94 +++++++ .../Deptrac/LayersConfig/CollectorsConfig.php | 86 ++++++ Symfony/Config/DeptracConfig.php | 244 ++++++++++++++++++ deptrac.config.php | 27 ++ .../ServiceContainerBuilder.php | 6 +- 10 files changed, 850 insertions(+), 1 deletion(-) create mode 100644 Symfony/Config/Deptrac/AnalyserConfig.php create mode 100644 Symfony/Config/Deptrac/Formatters/Codeclimate/SeverityConfig.php create mode 100644 Symfony/Config/Deptrac/Formatters/CodeclimateConfig.php create mode 100644 Symfony/Config/Deptrac/Formatters/GraphvizConfig.php create mode 100644 Symfony/Config/Deptrac/FormattersConfig.php create mode 100644 Symfony/Config/Deptrac/LayersConfig.php create mode 100644 Symfony/Config/Deptrac/LayersConfig/CollectorsConfig.php create mode 100644 Symfony/Config/DeptracConfig.php create mode 100755 deptrac.config.php diff --git a/Symfony/Config/Deptrac/AnalyserConfig.php b/Symfony/Config/Deptrac/AnalyserConfig.php new file mode 100644 index 000000000..f46cc4f2e --- /dev/null +++ b/Symfony/Config/Deptrac/AnalyserConfig.php @@ -0,0 +1,52 @@ +_usedProperties['types'] = true; + $this->types = $value; + + return $this; + } + + public function __construct(array $value = []) + { + if (array_key_exists('types', $value)) { + $this->_usedProperties['types'] = true; + $this->types = $value['types']; + unset($value['types']); + } + + if ([] !== $value) { + throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); + } + } + + public function toArray(): array + { + $output = []; + if (isset($this->_usedProperties['types'])) { + $output['types'] = $this->types; + } + + return $output; + } + +} diff --git a/Symfony/Config/Deptrac/Formatters/Codeclimate/SeverityConfig.php b/Symfony/Config/Deptrac/Formatters/Codeclimate/SeverityConfig.php new file mode 100644 index 000000000..013c326f2 --- /dev/null +++ b/Symfony/Config/Deptrac/Formatters/Codeclimate/SeverityConfig.php @@ -0,0 +1,98 @@ +_usedProperties['failure'] = true; + $this->failure = $value; + + return $this; + } + + /** + * @default 'minor' + * @param ParamConfigurator|'info'|'minor'|'major'|'critical'|'blocker' $value + * @return $this + */ + public function skipped($value): static + { + $this->_usedProperties['skipped'] = true; + $this->skipped = $value; + + return $this; + } + + /** + * @default 'info' + * @param ParamConfigurator|'info'|'minor'|'major'|'critical'|'blocker' $value + * @return $this + */ + public function uncovered($value): static + { + $this->_usedProperties['uncovered'] = true; + $this->uncovered = $value; + + return $this; + } + + public function __construct(array $value = []) + { + if (array_key_exists('failure', $value)) { + $this->_usedProperties['failure'] = true; + $this->failure = $value['failure']; + unset($value['failure']); + } + + if (array_key_exists('skipped', $value)) { + $this->_usedProperties['skipped'] = true; + $this->skipped = $value['skipped']; + unset($value['skipped']); + } + + if (array_key_exists('uncovered', $value)) { + $this->_usedProperties['uncovered'] = true; + $this->uncovered = $value['uncovered']; + unset($value['uncovered']); + } + + if ([] !== $value) { + throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); + } + } + + public function toArray(): array + { + $output = []; + if (isset($this->_usedProperties['failure'])) { + $output['failure'] = $this->failure; + } + if (isset($this->_usedProperties['skipped'])) { + $output['skipped'] = $this->skipped; + } + if (isset($this->_usedProperties['uncovered'])) { + $output['uncovered'] = $this->uncovered; + } + + return $output; + } + +} diff --git a/Symfony/Config/Deptrac/Formatters/CodeclimateConfig.php b/Symfony/Config/Deptrac/Formatters/CodeclimateConfig.php new file mode 100644 index 000000000..9128e6cc0 --- /dev/null +++ b/Symfony/Config/Deptrac/Formatters/CodeclimateConfig.php @@ -0,0 +1,56 @@ +severity) { + $this->_usedProperties['severity'] = true; + $this->severity = new \Symfony\Config\Deptrac\Formatters\Codeclimate\SeverityConfig($value); + } elseif (0 < \func_num_args()) { + throw new InvalidConfigurationException('The node created by "severity()" has already been initialized. You cannot pass values the second time you call severity().'); + } + + return $this->severity; + } + + public function __construct(array $value = []) + { + if (array_key_exists('severity', $value)) { + $this->_usedProperties['severity'] = true; + $this->severity = new \Symfony\Config\Deptrac\Formatters\Codeclimate\SeverityConfig($value['severity']); + unset($value['severity']); + } + + if ([] !== $value) { + throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); + } + } + + public function toArray(): array + { + $output = []; + if (isset($this->_usedProperties['severity'])) { + $output['severity'] = $this->severity->toArray(); + } + + return $output; + } + +} diff --git a/Symfony/Config/Deptrac/Formatters/GraphvizConfig.php b/Symfony/Config/Deptrac/Formatters/GraphvizConfig.php new file mode 100644 index 000000000..a27ed1bf1 --- /dev/null +++ b/Symfony/Config/Deptrac/Formatters/GraphvizConfig.php @@ -0,0 +1,97 @@ + $value + * + * @return $this + */ + public function hiddenLayers(ParamConfigurator|array $value): static + { + $this->_usedProperties['hiddenLayers'] = true; + $this->hiddenLayers = $value; + + return $this; + } + + /** + * @return $this + */ + public function groups(string $name, ParamConfigurator|array $value): static + { + $this->_usedProperties['groups'] = true; + $this->groups[$name] = $value; + + return $this; + } + + /** + * When a layer is part of a group, should edges point towards the group or the layer? + * @default false + * @param ParamConfigurator|bool $value + * @return $this + */ + public function pointToGroups($value): static + { + $this->_usedProperties['pointToGroups'] = true; + $this->pointToGroups = $value; + + return $this; + } + + public function __construct(array $value = []) + { + if (array_key_exists('hidden_layers', $value)) { + $this->_usedProperties['hiddenLayers'] = true; + $this->hiddenLayers = $value['hidden_layers']; + unset($value['hidden_layers']); + } + + if (array_key_exists('groups', $value)) { + $this->_usedProperties['groups'] = true; + $this->groups = $value['groups']; + unset($value['groups']); + } + + if (array_key_exists('point_to_groups', $value)) { + $this->_usedProperties['pointToGroups'] = true; + $this->pointToGroups = $value['point_to_groups']; + unset($value['point_to_groups']); + } + + if ([] !== $value) { + throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); + } + } + + public function toArray(): array + { + $output = []; + if (isset($this->_usedProperties['hiddenLayers'])) { + $output['hidden_layers'] = $this->hiddenLayers; + } + if (isset($this->_usedProperties['groups'])) { + $output['groups'] = $this->groups; + } + if (isset($this->_usedProperties['pointToGroups'])) { + $output['point_to_groups'] = $this->pointToGroups; + } + + return $output; + } + +} diff --git a/Symfony/Config/Deptrac/FormattersConfig.php b/Symfony/Config/Deptrac/FormattersConfig.php new file mode 100644 index 000000000..5a4277375 --- /dev/null +++ b/Symfony/Config/Deptrac/FormattersConfig.php @@ -0,0 +1,91 @@ +_usedProperties['graphviz'] = true; + $this->graphviz = $value; + + return $this; + } + + if (!$this->graphviz instanceof \Symfony\Config\Deptrac\Formatters\GraphvizConfig) { + $this->_usedProperties['graphviz'] = true; + $this->graphviz = new \Symfony\Config\Deptrac\Formatters\GraphvizConfig($value); + } elseif (0 < \func_num_args()) { + throw new InvalidConfigurationException('The node created by "graphviz()" has already been initialized. You cannot pass values the second time you call graphviz().'); + } + + return $this->graphviz; + } + + /** + * Configure Codeclimate output formatters + * @default {"severity":{"failure":"major","skipped":"minor","uncovered":"info"}} + */ + public function codeclimate(array $value = []): \Symfony\Config\Deptrac\Formatters\CodeclimateConfig + { + if (null === $this->codeclimate) { + $this->_usedProperties['codeclimate'] = true; + $this->codeclimate = new \Symfony\Config\Deptrac\Formatters\CodeclimateConfig($value); + } elseif (0 < \func_num_args()) { + throw new InvalidConfigurationException('The node created by "codeclimate()" has already been initialized. You cannot pass values the second time you call codeclimate().'); + } + + return $this->codeclimate; + } + + public function __construct(array $value = []) + { + if (array_key_exists('graphviz', $value)) { + $this->_usedProperties['graphviz'] = true; + $this->graphviz = \is_array($value['graphviz']) ? new \Symfony\Config\Deptrac\Formatters\GraphvizConfig($value['graphviz']) : $value['graphviz']; + unset($value['graphviz']); + } + + if (array_key_exists('codeclimate', $value)) { + $this->_usedProperties['codeclimate'] = true; + $this->codeclimate = new \Symfony\Config\Deptrac\Formatters\CodeclimateConfig($value['codeclimate']); + unset($value['codeclimate']); + } + + if ([] !== $value) { + throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); + } + } + + public function toArray(): array + { + $output = []; + if (isset($this->_usedProperties['graphviz'])) { + $output['graphviz'] = $this->graphviz instanceof \Symfony\Config\Deptrac\Formatters\GraphvizConfig ? $this->graphviz->toArray() : $this->graphviz; + } + if (isset($this->_usedProperties['codeclimate'])) { + $output['codeclimate'] = $this->codeclimate->toArray(); + } + + return $output; + } + +} diff --git a/Symfony/Config/Deptrac/LayersConfig.php b/Symfony/Config/Deptrac/LayersConfig.php new file mode 100644 index 000000000..d88330c08 --- /dev/null +++ b/Symfony/Config/Deptrac/LayersConfig.php @@ -0,0 +1,94 @@ +_usedProperties['name'] = true; + $this->name = $value; + + return $this; + } + + public function collectors(array $value = []): \Symfony\Config\Deptrac\LayersConfig\CollectorsConfig + { + $this->_usedProperties['collectors'] = true; + + return $this->collectors[] = new \Symfony\Config\Deptrac\LayersConfig\CollectorsConfig($value); + } + + /** + * @param ParamConfigurator|list $value + * + * @return $this + */ + public function attributes(ParamConfigurator|array $value): static + { + $this->_usedProperties['attributes'] = true; + $this->attributes = $value; + + return $this; + } + + public function __construct(array $value = []) + { + if (array_key_exists('name', $value)) { + $this->_usedProperties['name'] = true; + $this->name = $value['name']; + unset($value['name']); + } + + if (array_key_exists('collectors', $value)) { + $this->_usedProperties['collectors'] = true; + $this->collectors = array_map(function ($v) { return new \Symfony\Config\Deptrac\LayersConfig\CollectorsConfig($v); }, $value['collectors']); + unset($value['collectors']); + } + + if (array_key_exists('attributes', $value)) { + $this->_usedProperties['attributes'] = true; + $this->attributes = $value['attributes']; + unset($value['attributes']); + } + + if ([] !== $value) { + throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); + } + } + + public function toArray(): array + { + $output = []; + if (isset($this->_usedProperties['name'])) { + $output['name'] = $this->name; + } + if (isset($this->_usedProperties['collectors'])) { + $output['collectors'] = array_map(function ($v) { return $v->toArray(); }, $this->collectors); + } + if (isset($this->_usedProperties['attributes'])) { + $output['attributes'] = $this->attributes; + } + + return $output; + } + +} diff --git a/Symfony/Config/Deptrac/LayersConfig/CollectorsConfig.php b/Symfony/Config/Deptrac/LayersConfig/CollectorsConfig.php new file mode 100644 index 000000000..9d5312e82 --- /dev/null +++ b/Symfony/Config/Deptrac/LayersConfig/CollectorsConfig.php @@ -0,0 +1,86 @@ +_usedProperties['type'] = true; + $this->type = $value; + + return $this; + } + + /** + * @param ParamConfigurator|list $value + * + * @return $this + */ + public function attributes(ParamConfigurator|array $value): static + { + $this->_usedProperties['attributes'] = true; + $this->attributes = $value; + + return $this; + } + + public function __construct(array $value = []) + { + if (array_key_exists('type', $value)) { + $this->_usedProperties['type'] = true; + $this->type = $value['type']; + unset($value['type']); + } + + if (array_key_exists('attributes', $value)) { + $this->_usedProperties['attributes'] = true; + $this->attributes = $value['attributes']; + unset($value['attributes']); + } + + $this->_extraKeys = $value; + + } + + public function toArray(): array + { + $output = []; + if (isset($this->_usedProperties['type'])) { + $output['type'] = $this->type; + } + if (isset($this->_usedProperties['attributes'])) { + $output['attributes'] = $this->attributes; + } + + return $output + $this->_extraKeys; + } + + /** + * @param ParamConfigurator|mixed $value + * + * @return $this + */ + public function set(string $key, mixed $value): static + { + $this->_extraKeys[$key] = $value; + + return $this; + } + +} diff --git a/Symfony/Config/DeptracConfig.php b/Symfony/Config/DeptracConfig.php new file mode 100644 index 000000000..9f2676a32 --- /dev/null +++ b/Symfony/Config/DeptracConfig.php @@ -0,0 +1,244 @@ + $value + * + * @return $this + */ + public function paths(ParamConfigurator|array $value): static + { + $this->_usedProperties['paths'] = true; + $this->paths = $value; + + return $this; + } + + /** + * @param ParamConfigurator|list $value + * + * @return $this + */ + public function excludeFiles(ParamConfigurator|array $value): static + { + $this->_usedProperties['excludeFiles'] = true; + $this->excludeFiles = $value; + + return $this; + } + + public function layers(string $name, array $value = []): \Symfony\Config\Deptrac\LayersConfig + { + if (!isset($this->layers[$name])) { + $this->_usedProperties['layers'] = true; + $this->layers[$name] = new \Symfony\Config\Deptrac\LayersConfig($value); + } elseif (1 < \func_num_args()) { + throw new InvalidConfigurationException('The node created by "layers()" has already been initialized. You cannot pass values the second time you call layers().'); + } + + return $this->layers[$name]; + } + + /** + * @return $this + */ + public function ruleset(string $name, ParamConfigurator|array $value): static + { + $this->_usedProperties['ruleset'] = true; + $this->ruleset[$name] = $value; + + return $this; + } + + /** + * @return $this + */ + public function skipViolation(string $name, ParamConfigurator|array $value): static + { + $this->_usedProperties['skipViolations'] = true; + $this->skipViolations[$name] = $value; + + return $this; + } + + /** + * @default {"graphviz":{"hidden_layers":[],"groups":[],"point_to_groups":false},"codeclimate":{"severity":{"failure":"major","skipped":"minor","uncovered":"info"}}} + */ + public function formatters(array $value = []): \Symfony\Config\Deptrac\FormattersConfig + { + if (null === $this->formatters) { + $this->_usedProperties['formatters'] = true; + $this->formatters = new \Symfony\Config\Deptrac\FormattersConfig($value); + } elseif (0 < \func_num_args()) { + throw new InvalidConfigurationException('The node created by "formatters()" has already been initialized. You cannot pass values the second time you call formatters().'); + } + + return $this->formatters; + } + + /** + * @default {"types":["class","use"]} + */ + public function analyser(array $value = []): \Symfony\Config\Deptrac\AnalyserConfig + { + if (null === $this->analyser) { + $this->_usedProperties['analyser'] = true; + $this->analyser = new \Symfony\Config\Deptrac\AnalyserConfig($value); + } elseif (0 < \func_num_args()) { + throw new InvalidConfigurationException('The node created by "analyser()" has already been initialized. You cannot pass values the second time you call analyser().'); + } + + return $this->analyser; + } + + /** + * @default true + * @param ParamConfigurator|bool $value + * @return $this + */ + public function ignoreUncoveredInternalClasses($value): static + { + $this->_usedProperties['ignoreUncoveredInternalClasses'] = true; + $this->ignoreUncoveredInternalClasses = $value; + + return $this; + } + + /** + * @default true + * @param ParamConfigurator|bool $value + * @return $this + */ + public function useRelativePathFromDepfile($value): static + { + $this->_usedProperties['useRelativePathFromDepfile'] = true; + $this->useRelativePathFromDepfile = $value; + + return $this; + } + + public function getExtensionAlias(): string + { + return 'deptrac'; + } + + public function __construct(array $value = []) + { + if (array_key_exists('paths', $value)) { + $this->_usedProperties['paths'] = true; + $this->paths = $value['paths']; + unset($value['paths']); + } + + if (array_key_exists('exclude_files', $value)) { + $this->_usedProperties['excludeFiles'] = true; + $this->excludeFiles = $value['exclude_files']; + unset($value['exclude_files']); + } + + if (array_key_exists('layers', $value)) { + $this->_usedProperties['layers'] = true; + $this->layers = array_map(function ($v) { return new \Symfony\Config\Deptrac\LayersConfig($v); }, $value['layers']); + unset($value['layers']); + } + + if (array_key_exists('ruleset', $value)) { + $this->_usedProperties['ruleset'] = true; + $this->ruleset = $value['ruleset']; + unset($value['ruleset']); + } + + if (array_key_exists('skip_violations', $value)) { + $this->_usedProperties['skipViolations'] = true; + $this->skipViolations = $value['skip_violations']; + unset($value['skip_violations']); + } + + if (array_key_exists('formatters', $value)) { + $this->_usedProperties['formatters'] = true; + $this->formatters = new \Symfony\Config\Deptrac\FormattersConfig($value['formatters']); + unset($value['formatters']); + } + + if (array_key_exists('analyser', $value)) { + $this->_usedProperties['analyser'] = true; + $this->analyser = new \Symfony\Config\Deptrac\AnalyserConfig($value['analyser']); + unset($value['analyser']); + } + + if (array_key_exists('ignore_uncovered_internal_classes', $value)) { + $this->_usedProperties['ignoreUncoveredInternalClasses'] = true; + $this->ignoreUncoveredInternalClasses = $value['ignore_uncovered_internal_classes']; + unset($value['ignore_uncovered_internal_classes']); + } + + if (array_key_exists('use_relative_path_from_depfile', $value)) { + $this->_usedProperties['useRelativePathFromDepfile'] = true; + $this->useRelativePathFromDepfile = $value['use_relative_path_from_depfile']; + unset($value['use_relative_path_from_depfile']); + } + + if ([] !== $value) { + throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); + } + } + + public function toArray(): array + { + $output = []; + if (isset($this->_usedProperties['paths'])) { + $output['paths'] = $this->paths; + } + if (isset($this->_usedProperties['excludeFiles'])) { + $output['exclude_files'] = $this->excludeFiles; + } + if (isset($this->_usedProperties['layers'])) { + $output['layers'] = array_map(function ($v) { return $v->toArray(); }, $this->layers); + } + if (isset($this->_usedProperties['ruleset'])) { + $output['ruleset'] = $this->ruleset; + } + if (isset($this->_usedProperties['skipViolations'])) { + $output['skip_violations'] = $this->skipViolations; + } + if (isset($this->_usedProperties['formatters'])) { + $output['formatters'] = $this->formatters->toArray(); + } + if (isset($this->_usedProperties['analyser'])) { + $output['analyser'] = $this->analyser->toArray(); + } + if (isset($this->_usedProperties['ignoreUncoveredInternalClasses'])) { + $output['ignore_uncovered_internal_classes'] = $this->ignoreUncoveredInternalClasses; + } + if (isset($this->_usedProperties['useRelativePathFromDepfile'])) { + $output['use_relative_path_from_depfile'] = $this->useRelativePathFromDepfile; + } + + return $output; + } + +} diff --git a/deptrac.config.php b/deptrac.config.php new file mode 100755 index 000000000..972df4b2a --- /dev/null +++ b/deptrac.config.php @@ -0,0 +1,27 @@ +paths(['./src']); + + $config + ->layers('analyser') + ->name('analyser') + ->collectors() + ->type(CollectorType::TYPE_DIRECTORY->value) + ->set('value', 'src/Core/Analyser/.*'); + + $config + ->layers('dependency') + ->name('dependency') + ->collectors() + ->type(CollectorType::TYPE_DIRECTORY->value) + ->set('value', 'src/Core/Dependency/.*'); + + + $config->ruleset('analyser', ['result', 'layer', 'dependency']); + $config->ruleset('dependency', ['ast']); + +}; diff --git a/src/Supportive/DependencyInjection/ServiceContainerBuilder.php b/src/Supportive/DependencyInjection/ServiceContainerBuilder.php index 7b908cc33..f3e6964e8 100644 --- a/src/Supportive/DependencyInjection/ServiceContainerBuilder.php +++ b/src/Supportive/DependencyInjection/ServiceContainerBuilder.php @@ -8,11 +8,14 @@ use Qossmic\Deptrac\Supportive\DependencyInjection\Exception\CacheFileException; use Qossmic\Deptrac\Supportive\DependencyInjection\Exception\CannotLoadConfiguration; use SplFileInfo; +use Symfony\Component\Config\Builder\ConfigBuilderGenerator; +use Symfony\Component\Config\Definition\ConfigurationInterface; use Symfony\Component\Config\FileLocator; use Symfony\Component\Config\Loader\DelegatingLoader; use Symfony\Component\Config\Loader\LoaderResolver; use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Extension\ConfigurationExtensionInterface; use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass; @@ -101,6 +104,7 @@ public function build(): ContainerBuilder self::loadConfiguration($container, $this->configFile); } + $container->compile(true); return $container; @@ -160,7 +164,7 @@ private static function loadConfiguration(ContainerBuilder $container, SplFileIn $loader = new DelegatingLoader(new LoaderResolver([ new YamlFileLoader($container, new FileLocator([$configPathInfo->getPathname()])), - new PhpFileLoader($container, new FileLocator([$configPathInfo->getPathname()])), + new PhpFileLoader($container, new FileLocator([$configPathInfo->getPathname()]), generator: new ConfigBuilderGenerator('.')), ])); try { From 5a66193a62df14bc1ddc6077504d1c9628723ec2 Mon Sep 17 00:00:00 2001 From: Gennadi McKelvey Date: Wed, 5 Oct 2022 22:29:35 +0200 Subject: [PATCH 02/39] add value as configurable --- .../Deptrac/LayersConfig/CollectorsConfig.php | 23 +++++++++++++++++++ deptrac.config.php | 7 ++---- .../DependencyInjection/Configuration.php | 4 ++-- .../ServiceContainerBuilder.php | 3 --- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/Symfony/Config/Deptrac/LayersConfig/CollectorsConfig.php b/Symfony/Config/Deptrac/LayersConfig/CollectorsConfig.php index 9d5312e82..1a4c2c183 100644 --- a/Symfony/Config/Deptrac/LayersConfig/CollectorsConfig.php +++ b/Symfony/Config/Deptrac/LayersConfig/CollectorsConfig.php @@ -10,6 +10,7 @@ class CollectorsConfig { private $type; + private $value; private $attributes; private $_usedProperties = []; private $_extraKeys; @@ -27,6 +28,19 @@ public function type($value): static return $this; } + /** + * @default null + * @param ParamConfigurator|mixed $value + * @return $this + */ + public function value($value): static + { + $this->_usedProperties['value'] = true; + $this->value = $value; + + return $this; + } + /** * @param ParamConfigurator|list $value * @@ -48,6 +62,12 @@ public function __construct(array $value = []) unset($value['type']); } + if (array_key_exists('value', $value)) { + $this->_usedProperties['value'] = true; + $this->value = $value['value']; + unset($value['value']); + } + if (array_key_exists('attributes', $value)) { $this->_usedProperties['attributes'] = true; $this->attributes = $value['attributes']; @@ -64,6 +84,9 @@ public function toArray(): array if (isset($this->_usedProperties['type'])) { $output['type'] = $this->type; } + if (isset($this->_usedProperties['value'])) { + $output['value'] = $this->value; + } if (isset($this->_usedProperties['attributes'])) { $output['attributes'] = $this->attributes; } diff --git a/deptrac.config.php b/deptrac.config.php index 972df4b2a..60374c1cb 100755 --- a/deptrac.config.php +++ b/deptrac.config.php @@ -4,22 +4,19 @@ use Qossmic\Deptrac\Core\Layer\Collector\DirectoryCollector; return static function (Symfony\Config\DeptracConfig $config): void { - $config->paths(['./src']); - $config ->layers('analyser') ->name('analyser') ->collectors() ->type(CollectorType::TYPE_DIRECTORY->value) - ->set('value', 'src/Core/Analyser/.*'); + ->value('src/Core/Analyser/.*'); $config ->layers('dependency') ->name('dependency') ->collectors() ->type(CollectorType::TYPE_DIRECTORY->value) - ->set('value', 'src/Core/Dependency/.*'); - + ->value('src/Core/Dependency/.*'); $config->ruleset('analyser', ['result', 'layer', 'dependency']); $config->ruleset('dependency', ['ast']); diff --git a/src/Supportive/DependencyInjection/Configuration.php b/src/Supportive/DependencyInjection/Configuration.php index c59f95ee5..37ebb20b8 100644 --- a/src/Supportive/DependencyInjection/Configuration.php +++ b/src/Supportive/DependencyInjection/Configuration.php @@ -91,8 +91,8 @@ private function appendLayers(ArrayNodeDefinition $node): void ->ignoreExtraKeys(false) ->children() ->scalarNode('type')->isRequired()->end() - ->arrayNode('attributes') - ->variablePrototype()->end() + ->scalarNode('value')->end() + ->arrayNode('attributes')->variablePrototype()->end() ->end() ->end() ->end() diff --git a/src/Supportive/DependencyInjection/ServiceContainerBuilder.php b/src/Supportive/DependencyInjection/ServiceContainerBuilder.php index f3e6964e8..42e5c4c0a 100644 --- a/src/Supportive/DependencyInjection/ServiceContainerBuilder.php +++ b/src/Supportive/DependencyInjection/ServiceContainerBuilder.php @@ -9,13 +9,11 @@ use Qossmic\Deptrac\Supportive\DependencyInjection\Exception\CannotLoadConfiguration; use SplFileInfo; use Symfony\Component\Config\Builder\ConfigBuilderGenerator; -use Symfony\Component\Config\Definition\ConfigurationInterface; use Symfony\Component\Config\FileLocator; use Symfony\Component\Config\Loader\DelegatingLoader; use Symfony\Component\Config\Loader\LoaderResolver; use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Extension\ConfigurationExtensionInterface; use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass; @@ -104,7 +102,6 @@ public function build(): ContainerBuilder self::loadConfiguration($container, $this->configFile); } - $container->compile(true); return $container; From 87fe145cf8198aa2765afff075a667bca8e63ff9 Mon Sep 17 00:00:00 2001 From: Gennadi McKelvey Date: Wed, 5 Oct 2022 22:41:13 +0200 Subject: [PATCH 03/39] change value config to variable and add private config --- .../Deptrac/LayersConfig/CollectorsConfig.php | 26 ++++++++++++++++++- .../DependencyInjection/Configuration.php | 3 ++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/Symfony/Config/Deptrac/LayersConfig/CollectorsConfig.php b/Symfony/Config/Deptrac/LayersConfig/CollectorsConfig.php index 1a4c2c183..b39b60816 100644 --- a/Symfony/Config/Deptrac/LayersConfig/CollectorsConfig.php +++ b/Symfony/Config/Deptrac/LayersConfig/CollectorsConfig.php @@ -11,6 +11,7 @@ class CollectorsConfig { private $type; private $value; + private $private; private $attributes; private $_usedProperties = []; private $_extraKeys; @@ -31,9 +32,10 @@ public function type($value): static /** * @default null * @param ParamConfigurator|mixed $value + * * @return $this */ - public function value($value): static + public function value(mixed $value): static { $this->_usedProperties['value'] = true; $this->value = $value; @@ -41,6 +43,19 @@ public function value($value): static return $this; } + /** + * @default false + * @param ParamConfigurator|bool $value + * @return $this + */ + public function private($value): static + { + $this->_usedProperties['private'] = true; + $this->private = $value; + + return $this; + } + /** * @param ParamConfigurator|list $value * @@ -68,6 +83,12 @@ public function __construct(array $value = []) unset($value['value']); } + if (array_key_exists('private', $value)) { + $this->_usedProperties['private'] = true; + $this->private = $value['private']; + unset($value['private']); + } + if (array_key_exists('attributes', $value)) { $this->_usedProperties['attributes'] = true; $this->attributes = $value['attributes']; @@ -87,6 +108,9 @@ public function toArray(): array if (isset($this->_usedProperties['value'])) { $output['value'] = $this->value; } + if (isset($this->_usedProperties['private'])) { + $output['private'] = $this->private; + } if (isset($this->_usedProperties['attributes'])) { $output['attributes'] = $this->attributes; } diff --git a/src/Supportive/DependencyInjection/Configuration.php b/src/Supportive/DependencyInjection/Configuration.php index 37ebb20b8..fc341c27d 100644 --- a/src/Supportive/DependencyInjection/Configuration.php +++ b/src/Supportive/DependencyInjection/Configuration.php @@ -91,7 +91,8 @@ private function appendLayers(ArrayNodeDefinition $node): void ->ignoreExtraKeys(false) ->children() ->scalarNode('type')->isRequired()->end() - ->scalarNode('value')->end() + ->variableNode('value')->end() + ->booleanNode('private')->defaultFalse()->end() ->arrayNode('attributes')->variablePrototype()->end() ->end() ->end() From 1e9f01cb40ec7aa6cdf80ad1aaa6629f5e5c9968 Mon Sep 17 00:00:00 2001 From: Gennadi McKelvey Date: Thu, 6 Oct 2022 17:22:30 +0200 Subject: [PATCH 04/39] add Collectors by their fqn --- Symfony/Config/DeptracConfig.php | 11 +--- config/services.php | 57 ++++++++++++------- deptrac.config.php | 8 +-- .../DependencyInjection/Configuration.php | 2 +- 4 files changed, 46 insertions(+), 32 deletions(-) diff --git a/Symfony/Config/DeptracConfig.php b/Symfony/Config/DeptracConfig.php index 9f2676a32..db78d6064 100644 --- a/Symfony/Config/DeptracConfig.php +++ b/Symfony/Config/DeptracConfig.php @@ -51,16 +51,11 @@ public function excludeFiles(ParamConfigurator|array $value): static return $this; } - public function layers(string $name, array $value = []): \Symfony\Config\Deptrac\LayersConfig + public function layers(array $value = []): \Symfony\Config\Deptrac\LayersConfig { - if (!isset($this->layers[$name])) { - $this->_usedProperties['layers'] = true; - $this->layers[$name] = new \Symfony\Config\Deptrac\LayersConfig($value); - } elseif (1 < \func_num_args()) { - throw new InvalidConfigurationException('The node created by "layers()" has already been initialized. You cannot pass values the second time you call layers().'); - } + $this->_usedProperties['layers'] = true; - return $this->layers[$name]; + return $this->layers[] = new \Symfony\Config\Deptrac\LayersConfig($value); } /** diff --git a/config/services.php b/config/services.php index 568aa3523..a20a5aba7 100644 --- a/config/services.php +++ b/config/services.php @@ -238,65 +238,84 @@ $services->alias(CollectorResolverInterface::class, CollectorResolver::class); $services ->set(AttributeCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_ATTRIBUTE->value]); + ->tag('collector', ['type' => CollectorType::TYPE_ATTRIBUTE->value]) + ->tag('collector', ['type' => AttributeCollector::class]); $services ->set(BoolCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_BOOL->value]); + ->tag('collector', ['type' => CollectorType::TYPE_BOOL->value]) + ->tag('collector', ['type' => BoolCollector::class]); $services ->set(ClassCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_CLASS->value]); + ->tag('collector', ['type' => CollectorType::TYPE_CLASS->value]) + ->tag('collector', ['type' => ClassCollector::class]); $services ->set(ClassLikeCollector::class) ->tag('collector', ['type' => CollectorType::TYPE_CLASSLIKE->value]) - ->tag('collector', ['type' => CollectorType::TYPE_CLASS_NAME->value]); + ->tag('collector', ['type' => CollectorType::TYPE_CLASS_NAME->value]) + ->tag('collector', ['type' => ClassLikeCollector::class]); $services ->set(ClassNameRegexCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_CLASS_NAME_REGEX->value]); + ->tag('collector', ['type' => CollectorType::TYPE_CLASS_NAME_REGEX->value]) + ->tag('collector', ['type' => ClassNameRegexCollector::class]); $services ->set(DirectoryCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_DIRECTORY->value]); + ->tag('collector', ['type' => CollectorType::TYPE_DIRECTORY->value]) + ->tag('collector', ['type' => DirectoryCollector::class]); $services ->set(ExtendsCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_EXTENDS->value]); + ->tag('collector', ['type' => CollectorType::TYPE_EXTENDS->value]) + ->tag('collector', ['type' => ExtendsCollector::class]); $services ->set(FunctionNameCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_FUNCTION_NAME->value]); + ->tag('collector', ['type' => CollectorType::TYPE_FUNCTION_NAME->value]) + ->tag('collector', ['type' => FunctionNameCollector::class]); $services ->set(GlobCollector::class) ->args([ '$basePath' => param('projectDirectory'), ]) - ->tag('collector', ['type' => CollectorType::TYPE_GLOB->value]); + ->tag('collector', ['type' => CollectorType::TYPE_GLOB->value]) + ->tag('collector', ['type' => GlobCollector::class]); $services ->set(ImplementsCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_IMPLEMENTS->value]); + ->tag('collector', ['type' => CollectorType::TYPE_IMPLEMENTS->value]) + ->tag('collector', ['type' => ImplementsCollector::class]); $services ->set(InheritanceLevelCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_INHERITANCE->value]); + ->tag('collector', ['type' => CollectorType::TYPE_INHERITANCE->value]) + ->tag('collector', ['type' => InheritanceLevelCollector::class]); $services ->set(InterfaceCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_INTERFACE->value]); + ->tag('collector', ['type' => CollectorType::TYPE_INTERFACE->value]) + ->tag('collector', ['type' => InterfaceCollector::class]); $services ->set(InheritsCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_INHERITS->value]); + ->tag('collector', ['type' => CollectorType::TYPE_INHERITS->value]) + ->tag('collector', ['type' => InheritsCollector::class]); $services ->set(LayerCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_LAYER->value]); + ->tag('collector', ['type' => CollectorType::TYPE_LAYER->value]) + ->tag('collector', ['type' => LayerCollector::class]); $services ->set(MethodCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_METHOD->value]); + ->tag('collector', ['type' => CollectorType::TYPE_METHOD->value]) + ->tag('collector', ['type' => MethodCollector::class]); $services ->set(SuperglobalCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_SUPERGLOBAL->value]); + ->tag('collector', ['type' => CollectorType::TYPE_SUPERGLOBAL->value]) + ->tag('collector', ['type' => SuperglobalCollector::class]); $services ->set(TraitCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_TRAIT->value]); + ->tag('collector', ['type' => CollectorType::TYPE_TRAIT->value]) + ->tag('collector', ['type' => TraitCollector::class]); $services ->set(UsesCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_USES->value]); + ->tag('collector', ['type' => CollectorType::TYPE_USES->value]) + ->tag('collector', ['type' => UsesCollector::class]); $services ->set(PhpInternalCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_PHP_INTERNAL->value]); + ->tag('collector', ['type' => CollectorType::TYPE_PHP_INTERNAL->value]) + ->tag('collector', ['type' => PhpInternalCollector::class]); /* * Analyser diff --git a/deptrac.config.php b/deptrac.config.php index 60374c1cb..355699218 100755 --- a/deptrac.config.php +++ b/deptrac.config.php @@ -5,17 +5,17 @@ return static function (Symfony\Config\DeptracConfig $config): void { $config - ->layers('analyser') + ->layers() ->name('analyser') ->collectors() - ->type(CollectorType::TYPE_DIRECTORY->value) + ->type(DirectoryCollector::class) ->value('src/Core/Analyser/.*'); $config - ->layers('dependency') + ->layers() ->name('dependency') ->collectors() - ->type(CollectorType::TYPE_DIRECTORY->value) + ->type(DirectoryCollector::class) ->value('src/Core/Dependency/.*'); $config->ruleset('analyser', ['result', 'layer', 'dependency']); diff --git a/src/Supportive/DependencyInjection/Configuration.php b/src/Supportive/DependencyInjection/Configuration.php index fc341c27d..4c8961f7a 100644 --- a/src/Supportive/DependencyInjection/Configuration.php +++ b/src/Supportive/DependencyInjection/Configuration.php @@ -77,7 +77,7 @@ private function appendLayers(ArrayNodeDefinition $node): void $node ->children() ->arrayNode('layers') - ->useAttributeAsKey('name', false) + // ->useAttributeAsKey('name', false) ->arrayPrototype() ->children() ->scalarNode('name') From 0020ea9d95c850d2e737fc7447a15946394f1960 Mon Sep 17 00:00:00 2001 From: Gennadi McKelvey Date: Thu, 6 Oct 2022 17:47:06 +0200 Subject: [PATCH 05/39] fix test --- src/Supportive/DependencyInjection/Configuration.php | 1 - tests/Supportive/DependencyInjection/DeptracExtensionTest.php | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Supportive/DependencyInjection/Configuration.php b/src/Supportive/DependencyInjection/Configuration.php index 4c8961f7a..80dae0b19 100644 --- a/src/Supportive/DependencyInjection/Configuration.php +++ b/src/Supportive/DependencyInjection/Configuration.php @@ -77,7 +77,6 @@ private function appendLayers(ArrayNodeDefinition $node): void $node ->children() ->arrayNode('layers') - // ->useAttributeAsKey('name', false) ->arrayPrototype() ->children() ->scalarNode('name') diff --git a/tests/Supportive/DependencyInjection/DeptracExtensionTest.php b/tests/Supportive/DependencyInjection/DeptracExtensionTest.php index 043c2759f..40635c4db 100644 --- a/tests/Supportive/DependencyInjection/DeptracExtensionTest.php +++ b/tests/Supportive/DependencyInjection/DeptracExtensionTest.php @@ -204,13 +204,14 @@ public function testLayers(): void self::assertSame( [ - 'test' => [ + 0 => [ 'name' => 'test', 'collectors' => [ [ 'type' => 'directory', 'value' => 'Repository', 'attributes' => [], + 'private' => false ], ], 'attributes' => [], From dd45d677e5234a3e23557cba33de1c1e8d43d94b Mon Sep 17 00:00:00 2001 From: Gennadi McKelvey Date: Mon, 10 Oct 2022 21:20:14 +0200 Subject: [PATCH 06/39] move configbuilder into nicer dir --- .../Config/Symfony}/Config/Deptrac/AnalyserConfig.php | 0 .../Config/Deptrac/Formatters/Codeclimate/SeverityConfig.php | 0 .../Symfony}/Config/Deptrac/Formatters/CodeclimateConfig.php | 0 .../Symfony}/Config/Deptrac/Formatters/GraphvizConfig.php | 0 .../Config/Symfony}/Config/Deptrac/FormattersConfig.php | 0 .../Supportive/Config/Symfony}/Config/Deptrac/LayersConfig.php | 0 .../Symfony}/Config/Deptrac/LayersConfig/CollectorsConfig.php | 0 .../Supportive/Config/Symfony}/Config/DeptracConfig.php | 0 src/Supportive/DependencyInjection/ServiceContainerBuilder.php | 2 +- tests/Supportive/DependencyInjection/DeptracExtensionTest.php | 2 +- 10 files changed, 2 insertions(+), 2 deletions(-) rename {Symfony => src/Supportive/Config/Symfony}/Config/Deptrac/AnalyserConfig.php (100%) rename {Symfony => src/Supportive/Config/Symfony}/Config/Deptrac/Formatters/Codeclimate/SeverityConfig.php (100%) rename {Symfony => src/Supportive/Config/Symfony}/Config/Deptrac/Formatters/CodeclimateConfig.php (100%) rename {Symfony => src/Supportive/Config/Symfony}/Config/Deptrac/Formatters/GraphvizConfig.php (100%) rename {Symfony => src/Supportive/Config/Symfony}/Config/Deptrac/FormattersConfig.php (100%) rename {Symfony => src/Supportive/Config/Symfony}/Config/Deptrac/LayersConfig.php (100%) rename {Symfony => src/Supportive/Config/Symfony}/Config/Deptrac/LayersConfig/CollectorsConfig.php (100%) rename {Symfony => src/Supportive/Config/Symfony}/Config/DeptracConfig.php (100%) diff --git a/Symfony/Config/Deptrac/AnalyserConfig.php b/src/Supportive/Config/Symfony/Config/Deptrac/AnalyserConfig.php similarity index 100% rename from Symfony/Config/Deptrac/AnalyserConfig.php rename to src/Supportive/Config/Symfony/Config/Deptrac/AnalyserConfig.php diff --git a/Symfony/Config/Deptrac/Formatters/Codeclimate/SeverityConfig.php b/src/Supportive/Config/Symfony/Config/Deptrac/Formatters/Codeclimate/SeverityConfig.php similarity index 100% rename from Symfony/Config/Deptrac/Formatters/Codeclimate/SeverityConfig.php rename to src/Supportive/Config/Symfony/Config/Deptrac/Formatters/Codeclimate/SeverityConfig.php diff --git a/Symfony/Config/Deptrac/Formatters/CodeclimateConfig.php b/src/Supportive/Config/Symfony/Config/Deptrac/Formatters/CodeclimateConfig.php similarity index 100% rename from Symfony/Config/Deptrac/Formatters/CodeclimateConfig.php rename to src/Supportive/Config/Symfony/Config/Deptrac/Formatters/CodeclimateConfig.php diff --git a/Symfony/Config/Deptrac/Formatters/GraphvizConfig.php b/src/Supportive/Config/Symfony/Config/Deptrac/Formatters/GraphvizConfig.php similarity index 100% rename from Symfony/Config/Deptrac/Formatters/GraphvizConfig.php rename to src/Supportive/Config/Symfony/Config/Deptrac/Formatters/GraphvizConfig.php diff --git a/Symfony/Config/Deptrac/FormattersConfig.php b/src/Supportive/Config/Symfony/Config/Deptrac/FormattersConfig.php similarity index 100% rename from Symfony/Config/Deptrac/FormattersConfig.php rename to src/Supportive/Config/Symfony/Config/Deptrac/FormattersConfig.php diff --git a/Symfony/Config/Deptrac/LayersConfig.php b/src/Supportive/Config/Symfony/Config/Deptrac/LayersConfig.php similarity index 100% rename from Symfony/Config/Deptrac/LayersConfig.php rename to src/Supportive/Config/Symfony/Config/Deptrac/LayersConfig.php diff --git a/Symfony/Config/Deptrac/LayersConfig/CollectorsConfig.php b/src/Supportive/Config/Symfony/Config/Deptrac/LayersConfig/CollectorsConfig.php similarity index 100% rename from Symfony/Config/Deptrac/LayersConfig/CollectorsConfig.php rename to src/Supportive/Config/Symfony/Config/Deptrac/LayersConfig/CollectorsConfig.php diff --git a/Symfony/Config/DeptracConfig.php b/src/Supportive/Config/Symfony/Config/DeptracConfig.php similarity index 100% rename from Symfony/Config/DeptracConfig.php rename to src/Supportive/Config/Symfony/Config/DeptracConfig.php diff --git a/src/Supportive/DependencyInjection/ServiceContainerBuilder.php b/src/Supportive/DependencyInjection/ServiceContainerBuilder.php index 42e5c4c0a..c1d066d43 100644 --- a/src/Supportive/DependencyInjection/ServiceContainerBuilder.php +++ b/src/Supportive/DependencyInjection/ServiceContainerBuilder.php @@ -161,7 +161,7 @@ private static function loadConfiguration(ContainerBuilder $container, SplFileIn $loader = new DelegatingLoader(new LoaderResolver([ new YamlFileLoader($container, new FileLocator([$configPathInfo->getPathname()])), - new PhpFileLoader($container, new FileLocator([$configPathInfo->getPathname()]), generator: new ConfigBuilderGenerator('.')), + new PhpFileLoader($container, new FileLocator([$configPathInfo->getPathname()]), generator: new ConfigBuilderGenerator('./src/Supportive/Config/')), ])); try { diff --git a/tests/Supportive/DependencyInjection/DeptracExtensionTest.php b/tests/Supportive/DependencyInjection/DeptracExtensionTest.php index 40635c4db..f84213659 100644 --- a/tests/Supportive/DependencyInjection/DeptracExtensionTest.php +++ b/tests/Supportive/DependencyInjection/DeptracExtensionTest.php @@ -211,7 +211,7 @@ public function testLayers(): void 'type' => 'directory', 'value' => 'Repository', 'attributes' => [], - 'private' => false + 'private' => false, ], ], 'attributes' => [], From 57ac9d500f34af56cf253f807859ce97f17500c0 Mon Sep 17 00:00:00 2001 From: Gennadi McKelvey Date: Tue, 11 Oct 2022 11:52:58 +0200 Subject: [PATCH 07/39] implement configbuilders --- src/Supportive/Config/DeptracConfig.php | 61 +++++++++++++++++++++++ src/Supportive/Config/FormatterConfig.php | 9 ++++ src/Supportive/Config/LayersConfig.php | 18 +++++++ src/Supportive/Config/RulesetConfig.php | 18 +++++++ 4 files changed, 106 insertions(+) create mode 100644 src/Supportive/Config/DeptracConfig.php create mode 100644 src/Supportive/Config/FormatterConfig.php create mode 100644 src/Supportive/Config/LayersConfig.php create mode 100644 src/Supportive/Config/RulesetConfig.php diff --git a/src/Supportive/Config/DeptracConfig.php b/src/Supportive/Config/DeptracConfig.php new file mode 100644 index 000000000..81791b30a --- /dev/null +++ b/src/Supportive/Config/DeptracConfig.php @@ -0,0 +1,61 @@ +baseline = $baseline; + + return $this; + } + + public function paths(array $paths): self + { + $this->paths = $paths; + + return $this; + } + + public function layers(string $name): LayersConfig + { + return $this->layers[$name] = new LayersConfig($name); + } + + public function rulesets(string $name): RulesetConfig + { + return $this->ruleset[$name] = new RulesetConfig($name); + } + + public function toArray(): array + { + return [ + 'paths' => $this->paths, + 'exclude_files' => [], + 'layers' => array_map(fn (LayersConfig $layerConfig)=> $layerConfig->toArray(), $this->layers), + 'ruleset' => array_map(fn (RulesetConfig $rulesetConfig) => $rulesetConfig(), $this->rulesets), + 'skip_violations' => [], + 'formatters' => [], + 'analyser' => $this->analysers, + 'ignore_uncovered_internal_classes' => $this->ignoreUncoveredInternalClasses, + 'use_relative_path_from_depfile' => $this->useRelativePathFromDepfile, + ]; + } + + public function getExtensionAlias(): string + { + return 'deptrac'; + } +} diff --git a/src/Supportive/Config/FormatterConfig.php b/src/Supportive/Config/FormatterConfig.php new file mode 100644 index 000000000..ed471b1d2 --- /dev/null +++ b/src/Supportive/Config/FormatterConfig.php @@ -0,0 +1,9 @@ + Date: Wed, 12 Oct 2022 10:59:23 +0200 Subject: [PATCH 08/39] update configbuilder --- deptrac.config.php | 33 ++++++++--------- src/Supportive/Config/CollectorConfig.php | 44 +++++++++++++++++++++++ src/Supportive/Config/DeptracConfig.php | 22 ++++++------ src/Supportive/Config/FormatterConfig.php | 10 ++++-- src/Supportive/Config/LayerConfig.php | 33 +++++++++++++++++ src/Supportive/Config/LayersConfig.php | 18 ---------- src/Supportive/Config/RulesetConfig.php | 22 ++++++++++-- 7 files changed, 134 insertions(+), 48 deletions(-) create mode 100644 src/Supportive/Config/CollectorConfig.php create mode 100644 src/Supportive/Config/LayerConfig.php delete mode 100644 src/Supportive/Config/LayersConfig.php diff --git a/deptrac.config.php b/deptrac.config.php index 355699218..0e4cfda52 100755 --- a/deptrac.config.php +++ b/deptrac.config.php @@ -1,24 +1,25 @@ layers() - ->name('analyser') - ->collectors() - ->type(DirectoryCollector::class) - ->value('src/Core/Analyser/.*'); +return static function (DeptracConfig $config): void { + $analyser = $config->layer('analyser'); + $analyser->collector(CollectorType::TYPE_DIRECTORY)->value('src/Core/Analyser/.*'); - $config - ->layers() - ->name('dependency') - ->collectors() - ->type(DirectoryCollector::class) - ->value('src/Core/Dependency/.*'); + $ast = $config->layer('ast'); + $ast->collector(CollectorType::TYPE_DIRECTORY)->value('src/Core/Analyser/.*'); + $ast->collector(CollectorType::TYPE_CLASS_NAME)->value('^PHPStan\\\\PhpDocParser\\\\.*')->private(); + $ast->collector(CollectorType::TYPE_CLASS_NAME)->value('^PhpParser\\\\.*')->private(); + $ast->collector(CollectorType::TYPE_CLASS_NAME)->value('^phpDocumentor\\\\Reflection\\\\.*')->private(); - $config->ruleset('analyser', ['result', 'layer', 'dependency']); - $config->ruleset('dependency', ['ast']); + $console = $config->layer('console'); + $console->collector(CollectorType::TYPE_DIRECTORY)->value('src/Supportive/Console/.*'); + $layer = $config->layer('layer'); + $layer->collector(CollectorType::TYPE_DIRECTORY)->value('src/Core/Layer.*'); + + $config->ruleset($analyser)->accessesLayer($ast, $layer); + $config->ruleset($layer)->accessesLayer($ast); + $config->ruleset($console)->accessesLayer($analyser); }; diff --git a/src/Supportive/Config/CollectorConfig.php b/src/Supportive/Config/CollectorConfig.php new file mode 100644 index 000000000..7f699d07f --- /dev/null +++ b/src/Supportive/Config/CollectorConfig.php @@ -0,0 +1,44 @@ +value = $value; + + return $this; + } + + public function private(): self + { + $this->private = true; + + return $this; + } + + public function toArray(): array + { + return ['type' => $this->collectorType->value, 'value' => $this->value]; + } +} diff --git a/src/Supportive/Config/DeptracConfig.php b/src/Supportive/Config/DeptracConfig.php index 81791b30a..c78dd0e80 100644 --- a/src/Supportive/Config/DeptracConfig.php +++ b/src/Supportive/Config/DeptracConfig.php @@ -8,12 +8,14 @@ final class DeptracConfig implements ConfigBuilderInterface { - private ?string $baseline = null; private bool $ignoreUncoveredInternalClasses = false; private bool $useRelativePathFromDepfile = false; - private array $paths = ['src'] ; + private array $paths = ['src']; + private array $layers = []; private array $formatters = []; + private array $rulesets = []; + private array $analyser = []; public function baseline(string $baseline): self { @@ -29,14 +31,14 @@ public function paths(array $paths): self return $this; } - public function layers(string $name): LayersConfig + public function layer(string $name): LayerConfig { - return $this->layers[$name] = new LayersConfig($name); + return $this->layers[$name] = new LayerConfig($name); } - public function rulesets(string $name): RulesetConfig + public function ruleset(LayerConfig $layerConfig): RulesetConfig { - return $this->ruleset[$name] = new RulesetConfig($name); + return $this->rulesets[] = new RulesetConfig($layerConfig); } public function toArray(): array @@ -44,11 +46,11 @@ public function toArray(): array return [ 'paths' => $this->paths, 'exclude_files' => [], - 'layers' => array_map(fn (LayersConfig $layerConfig)=> $layerConfig->toArray(), $this->layers), - 'ruleset' => array_map(fn (RulesetConfig $rulesetConfig) => $rulesetConfig(), $this->rulesets), + 'layers' => array_map(static fn (LayerConfig $layerConfig) => $layerConfig->toArray(), $this->layers), + 'ruleset' => array_map(static fn (RulesetConfig $rulesetConfig) => $rulesetConfig->toArray(), $this->rulesets), 'skip_violations' => [], - 'formatters' => [], - 'analyser' => $this->analysers, + 'formatters' => $this->formatters, + //'analyser' => $this->analyser, 'ignore_uncovered_internal_classes' => $this->ignoreUncoveredInternalClasses, 'use_relative_path_from_depfile' => $this->useRelativePathFromDepfile, ]; diff --git a/src/Supportive/Config/FormatterConfig.php b/src/Supportive/Config/FormatterConfig.php index ed471b1d2..a77e9c2d4 100644 --- a/src/Supportive/Config/FormatterConfig.php +++ b/src/Supportive/Config/FormatterConfig.php @@ -4,6 +4,12 @@ namespace Qossmic\Deptrac\Supportive\Config; -class LayerConfig { - +use Stringable; + +final class FormatterConfig implements Stringable +{ + public function __toString(): string + { + return 'formatter'; + } } diff --git a/src/Supportive/Config/LayerConfig.php b/src/Supportive/Config/LayerConfig.php new file mode 100644 index 000000000..4f8eac735 --- /dev/null +++ b/src/Supportive/Config/LayerConfig.php @@ -0,0 +1,33 @@ +colloctors[] = CollectorConfig::fromType($collectorType); + } + + public function toArray(): array + { + return ['name' => $this->name, 'collectors' => array_map(static fn (CollectorConfig $config) => $config->toArray(), $this->colloctors)]; + } + + public function __toString(): string + { + return $this->name; + } +} diff --git a/src/Supportive/Config/LayersConfig.php b/src/Supportive/Config/LayersConfig.php deleted file mode 100644 index e6acd6e4d..000000000 --- a/src/Supportive/Config/LayersConfig.php +++ /dev/null @@ -1,18 +0,0 @@ -accessableLayers[] = $layerConfig; + } + + return $this; + } + public function toArray(): array { - return []; + $data = ['name' => $this->layersConfig->__toString()]; + + foreach ($this->accessableLayers as $accessesLayer) { + $data[] = $accessesLayer->__toString() ; + } + + return $data; } } From a803b89eb4c9e71bb79a828952c0df8cd75d72c7 Mon Sep 17 00:00:00 2001 From: Gennadi McKelvey Date: Thu, 13 Oct 2022 17:08:39 +0200 Subject: [PATCH 09/39] tmp --- deptrac.config.php | 37 ++++++++++++++++++++--- src/Supportive/Config/CollectorConfig.php | 20 +++++++++++- src/Supportive/Config/RulesetConfig.php | 9 ++---- 3 files changed, 54 insertions(+), 12 deletions(-) diff --git a/deptrac.config.php b/deptrac.config.php index 0e4cfda52..4d0774edb 100755 --- a/deptrac.config.php +++ b/deptrac.config.php @@ -8,7 +8,7 @@ $analyser->collector(CollectorType::TYPE_DIRECTORY)->value('src/Core/Analyser/.*'); $ast = $config->layer('ast'); - $ast->collector(CollectorType::TYPE_DIRECTORY)->value('src/Core/Analyser/.*'); + $ast->collector(CollectorType::TYPE_DIRECTORY)->value('src/Core/Ast/.*'); $ast->collector(CollectorType::TYPE_CLASS_NAME)->value('^PHPStan\\\\PhpDocParser\\\\.*')->private(); $ast->collector(CollectorType::TYPE_CLASS_NAME)->value('^PhpParser\\\\.*')->private(); $ast->collector(CollectorType::TYPE_CLASS_NAME)->value('^phpDocumentor\\\\Reflection\\\\.*')->private(); @@ -16,10 +16,39 @@ $console = $config->layer('console'); $console->collector(CollectorType::TYPE_DIRECTORY)->value('src/Supportive/Console/.*'); + $dependency = $config->layer('dependency'); + $dependency->collector(CollectorType::TYPE_DIRECTORY)->value('src/Core/Dependency/.*'); + + $dependencyInjection = $config->layer('dependency_injection'); + $dependencyInjection->collector(CollectorType::TYPE_DIRECTORY)->value('src/Supportive/DependencyInjection/.*'); + + $contract = $config->layer('contract'); + $contract->collector(CollectorType::TYPE_DIRECTORY)->value('src/Contract/.*'); + + $inputCollector = $config->layer('input_collector'); + $inputCollector->collector(CollectorType::TYPE_DIRECTORY)->value('src/Core/InputCollector/.*'); + $layer = $config->layer('layer'); - $layer->collector(CollectorType::TYPE_DIRECTORY)->value('src/Core/Layer.*'); + $layer->collector(CollectorType::TYPE_DIRECTORY)->value('src/Core/Layer/.*'); + + $outputFormatter = $config->layer('output_formatter'); + $outputFormatter->collector(CollectorType::TYPE_DIRECTORY)->value('src/Core/OutputFormatter/.*'); + $outputFormatter->collector(CollectorType::TYPE_CLASS_NAME)->value('^phpDocumentor\\\\GraphViz\\\\.*')->private(); + + $file = $config->layer('file'); + $file->collector(CollectorType::TYPE_DIRECTORY)->value('src/Supportive/File/.*'); + + $supportive = $config->layer('supportive'); + $supportiveCollector = $supportive->collector(CollectorType::TYPE_BOOL); + $supportiveCollector->mustNot(CollectorType::TYPE_DIRECTORY)->value('src/Supportive/.*/.*'); + $supportiveCollector->must(CollectorType::TYPE_DIRECTORY)->value('src/Supportive/.*/.*'); - $config->ruleset($analyser)->accessesLayer($ast, $layer); + // ruleset $config->ruleset($layer)->accessesLayer($ast); - $config->ruleset($console)->accessesLayer($analyser); + $config->ruleset($console)->accessesLayer($analyser, $outputFormatter, $dependencyInjection, $file); + $config->ruleset($dependency)->accessesLayer($ast); + $config->ruleset($analyser)->accessesLayer($layer, $dependency, $ast); + $config->ruleset($outputFormatter)->accessesLayer($console, $dependencyInjection); + $config->ruleset($ast)->accessesLayer($file, $inputCollector); + $config->ruleset($inputCollector)->accessesLayer($file); }; diff --git a/src/Supportive/Config/CollectorConfig.php b/src/Supportive/Config/CollectorConfig.php index 7f699d07f..5de02a8e6 100644 --- a/src/Supportive/Config/CollectorConfig.php +++ b/src/Supportive/Config/CollectorConfig.php @@ -10,6 +10,8 @@ final class CollectorConfig { private ?string $value = null; private bool $private = false; + private array $mustNot = []; + private array $must = []; private function __construct( private readonly CollectorType $collectorType @@ -30,6 +32,16 @@ public function value(string $value): self return $this; } + public function mustNot(CollectorType $collectorType): CollectorConfig + { + return $this->mustNot[] = CollectorConfig::fromType($collectorType); + } + + public function must(CollectorType $collectorType): CollectorConfig + { + return $this->must[] = CollectorConfig::fromType($collectorType); + } + public function private(): self { $this->private = true; @@ -39,6 +51,12 @@ public function private(): self public function toArray(): array { - return ['type' => $this->collectorType->value, 'value' => $this->value]; + return [ + 'type' => $this->collectorType->value, + 'value' => $this->value, + 'private' => $this->private, + 'must' => array_map(static fn (CollectorConfig $v) => $v->toArray(), $this->must), + 'must_not' => array_map(static fn (CollectorConfig $v) => $v->toArray(), $this->mustNot), + ]; } } diff --git a/src/Supportive/Config/RulesetConfig.php b/src/Supportive/Config/RulesetConfig.php index 61e7cbeb9..9a5ef1af4 100644 --- a/src/Supportive/Config/RulesetConfig.php +++ b/src/Supportive/Config/RulesetConfig.php @@ -15,7 +15,6 @@ public function __construct( public function accessesLayer(LayerConfig ...$layersConfig): self { - foreach ($layersConfig as $layerConfig) { $this->accessableLayers[] = $layerConfig; } @@ -25,12 +24,8 @@ public function accessesLayer(LayerConfig ...$layersConfig): self public function toArray(): array { - $data = ['name' => $this->layersConfig->__toString()]; - - foreach ($this->accessableLayers as $accessesLayer) { - $data[] = $accessesLayer->__toString() ; - } + $data = array_map(static fn (LayerConfig $layerConfig) => $layerConfig->__toString(), $this->accessableLayers); - return $data; + return $data + ['name' => $this->layersConfig->__toString()]; } } From 4b2b883bc58fd1a47f8b41368c8e89b861ea770d Mon Sep 17 00:00:00 2001 From: Gennadi McKelvey Date: Thu, 13 Oct 2022 17:49:43 +0200 Subject: [PATCH 10/39] add emittertypes --- deptrac.config.php | 13 +++++++++++++ src/Supportive/Config/DeptracConfig.php | 12 +++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/deptrac.config.php b/deptrac.config.php index 4d0774edb..a935c2b9f 100755 --- a/deptrac.config.php +++ b/deptrac.config.php @@ -1,9 +1,22 @@ analyser( + EmitterType::CLASS_TOKEN, + EmitterType::CLASS_SUPERGLOBAL_TOKEN, + EmitterType::FILE_TOKEN, + EmitterType::FUNCTION_TOKEN, + EmitterType::FUNCTION_SUPERGLOBAL_TOKEN, + EmitterType::FUNCTION_CALL, + ); + + // layer $analyser = $config->layer('analyser'); $analyser->collector(CollectorType::TYPE_DIRECTORY)->value('src/Core/Analyser/.*'); diff --git a/src/Supportive/Config/DeptracConfig.php b/src/Supportive/Config/DeptracConfig.php index c78dd0e80..35bb34887 100644 --- a/src/Supportive/Config/DeptracConfig.php +++ b/src/Supportive/Config/DeptracConfig.php @@ -4,6 +4,7 @@ namespace Qossmic\Deptrac\Supportive\Config; +use Qossmic\Deptrac\Supportive\DependencyInjection\EmitterType; use Symfony\Component\Config\Builder\ConfigBuilderInterface; final class DeptracConfig implements ConfigBuilderInterface @@ -17,6 +18,15 @@ final class DeptracConfig implements ConfigBuilderInterface private array $rulesets = []; private array $analyser = []; + public function analyser(EmitterType ...$types): self + { + foreach ($types as $type) { + $this->analyser[] = $type->value; + } + + return $this; + } + public function baseline(string $baseline): self { $this->baseline = $baseline; @@ -50,7 +60,7 @@ public function toArray(): array 'ruleset' => array_map(static fn (RulesetConfig $rulesetConfig) => $rulesetConfig->toArray(), $this->rulesets), 'skip_violations' => [], 'formatters' => $this->formatters, - //'analyser' => $this->analyser, + 'analyser' => ['types' => $this->analyser], 'ignore_uncovered_internal_classes' => $this->ignoreUncoveredInternalClasses, 'use_relative_path_from_depfile' => $this->useRelativePathFromDepfile, ]; From e02d4009b11683c0b1c0f676fc202b26bde9df54 Mon Sep 17 00:00:00 2001 From: Gennadi McKelvey Date: Fri, 14 Oct 2022 12:48:36 +0200 Subject: [PATCH 11/39] update defaults for bool flags --- deptrac.config.php | 27 +++++++++++++------------ src/Supportive/Config/DeptracConfig.php | 4 ++-- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/deptrac.config.php b/deptrac.config.php index a935c2b9f..2535f898d 100755 --- a/deptrac.config.php +++ b/deptrac.config.php @@ -6,6 +6,7 @@ use Qossmic\Deptrac\Supportive\DependencyInjection\EmitterType; return static function (DeptracConfig $config): void { + $config->paths(['./src']); // analyser $config->analyser( EmitterType::CLASS_TOKEN, @@ -17,44 +18,44 @@ ); // layer - $analyser = $config->layer('analyser'); + $analyser = $config->layer('Analyser'); $analyser->collector(CollectorType::TYPE_DIRECTORY)->value('src/Core/Analyser/.*'); - $ast = $config->layer('ast'); + $ast = $config->layer('Ast'); $ast->collector(CollectorType::TYPE_DIRECTORY)->value('src/Core/Ast/.*'); $ast->collector(CollectorType::TYPE_CLASS_NAME)->value('^PHPStan\\\\PhpDocParser\\\\.*')->private(); $ast->collector(CollectorType::TYPE_CLASS_NAME)->value('^PhpParser\\\\.*')->private(); $ast->collector(CollectorType::TYPE_CLASS_NAME)->value('^phpDocumentor\\\\Reflection\\\\.*')->private(); - $console = $config->layer('console'); + $console = $config->layer('Console'); $console->collector(CollectorType::TYPE_DIRECTORY)->value('src/Supportive/Console/.*'); - $dependency = $config->layer('dependency'); + $dependency = $config->layer('Dependency'); $dependency->collector(CollectorType::TYPE_DIRECTORY)->value('src/Core/Dependency/.*'); - $dependencyInjection = $config->layer('dependency_injection'); + $dependencyInjection = $config->layer('DependencyInjection'); $dependencyInjection->collector(CollectorType::TYPE_DIRECTORY)->value('src/Supportive/DependencyInjection/.*'); - $contract = $config->layer('contract'); + $contract = $config->layer('Contract'); $contract->collector(CollectorType::TYPE_DIRECTORY)->value('src/Contract/.*'); - $inputCollector = $config->layer('input_collector'); + $inputCollector = $config->layer('InputCollector'); $inputCollector->collector(CollectorType::TYPE_DIRECTORY)->value('src/Core/InputCollector/.*'); - $layer = $config->layer('layer'); + $layer = $config->layer('Layer'); $layer->collector(CollectorType::TYPE_DIRECTORY)->value('src/Core/Layer/.*'); - $outputFormatter = $config->layer('output_formatter'); - $outputFormatter->collector(CollectorType::TYPE_DIRECTORY)->value('src/Core/OutputFormatter/.*'); + $outputFormatter = $config->layer('OutputFormatter'); + $outputFormatter->collector(CollectorType::TYPE_DIRECTORY)->value('src/Supportive/OutputFormatter/.*'); $outputFormatter->collector(CollectorType::TYPE_CLASS_NAME)->value('^phpDocumentor\\\\GraphViz\\\\.*')->private(); - $file = $config->layer('file'); + $file = $config->layer('File'); $file->collector(CollectorType::TYPE_DIRECTORY)->value('src/Supportive/File/.*'); - $supportive = $config->layer('supportive'); + $supportive = $config->layer('Supportive'); $supportiveCollector = $supportive->collector(CollectorType::TYPE_BOOL); $supportiveCollector->mustNot(CollectorType::TYPE_DIRECTORY)->value('src/Supportive/.*/.*'); - $supportiveCollector->must(CollectorType::TYPE_DIRECTORY)->value('src/Supportive/.*/.*'); + $supportiveCollector->must(CollectorType::TYPE_DIRECTORY)->value('src/Supportive/.*'); // ruleset $config->ruleset($layer)->accessesLayer($ast); diff --git a/src/Supportive/Config/DeptracConfig.php b/src/Supportive/Config/DeptracConfig.php index 35bb34887..e819fe89a 100644 --- a/src/Supportive/Config/DeptracConfig.php +++ b/src/Supportive/Config/DeptracConfig.php @@ -9,8 +9,8 @@ final class DeptracConfig implements ConfigBuilderInterface { - private bool $ignoreUncoveredInternalClasses = false; - private bool $useRelativePathFromDepfile = false; + private bool $ignoreUncoveredInternalClasses = true; + private bool $useRelativePathFromDepfile = true; private array $paths = ['src']; private array $layers = []; From 62473a0b3856cd8ff1c657c48d2c52b12d7ccf63 Mon Sep 17 00:00:00 2001 From: Gennadi McKelvey Date: Fri, 14 Oct 2022 15:32:27 +0200 Subject: [PATCH 12/39] add baseline parsing --- deptrac.config.php | 2 +- src/Supportive/Config/DeptracConfig.php | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/deptrac.config.php b/deptrac.config.php index 2535f898d..b9c8bd402 100755 --- a/deptrac.config.php +++ b/deptrac.config.php @@ -1,12 +1,12 @@ paths(['./src']); + $config->baseline('./deptrac.baseline.yaml'); // analyser $config->analyser( EmitterType::CLASS_TOKEN, diff --git a/src/Supportive/Config/DeptracConfig.php b/src/Supportive/Config/DeptracConfig.php index e819fe89a..02e92594d 100644 --- a/src/Supportive/Config/DeptracConfig.php +++ b/src/Supportive/Config/DeptracConfig.php @@ -6,6 +6,7 @@ use Qossmic\Deptrac\Supportive\DependencyInjection\EmitterType; use Symfony\Component\Config\Builder\ConfigBuilderInterface; +use Symfony\Component\Yaml\Yaml; final class DeptracConfig implements ConfigBuilderInterface { @@ -16,12 +17,13 @@ final class DeptracConfig implements ConfigBuilderInterface private array $layers = []; private array $formatters = []; private array $rulesets = []; - private array $analyser = []; + private array $analyser = [EmitterType::CLASS_TOKEN, EmitterType::USE_TOKEN]; + private array $skipViolations = []; public function analyser(EmitterType ...$types): self { foreach ($types as $type) { - $this->analyser[] = $type->value; + $this->analyser[$type->value] = $type; } return $this; @@ -29,7 +31,11 @@ public function analyser(EmitterType ...$types): self public function baseline(string $baseline): self { - $this->baseline = $baseline; + $baseline = Yaml::parseFile($baseline); + + foreach ($baseline['deptrac']['skip_violations'] ?? [] as $class => $skipViolations) { + $this->skipViolations[$class] = $skipViolations; + } return $this; } @@ -58,9 +64,9 @@ public function toArray(): array 'exclude_files' => [], 'layers' => array_map(static fn (LayerConfig $layerConfig) => $layerConfig->toArray(), $this->layers), 'ruleset' => array_map(static fn (RulesetConfig $rulesetConfig) => $rulesetConfig->toArray(), $this->rulesets), - 'skip_violations' => [], + 'skip_violations' => $this->skipViolations, 'formatters' => $this->formatters, - 'analyser' => ['types' => $this->analyser], + 'analyser' => ['types' => array_map(static fn (EmitterType $emitterType) => $emitterType->value, $this->analyser)], 'ignore_uncovered_internal_classes' => $this->ignoreUncoveredInternalClasses, 'use_relative_path_from_depfile' => $this->useRelativePathFromDepfile, ]; From 607b2ed9d5d16021547dba26c8f6a756612622e9 Mon Sep 17 00:00:00 2001 From: Gennadi McKelvey Date: Fri, 14 Oct 2022 16:17:53 +0200 Subject: [PATCH 13/39] only export values if set --- src/Supportive/Config/DeptracConfig.php | 50 ++++++++++++++++++------- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/src/Supportive/Config/DeptracConfig.php b/src/Supportive/Config/DeptracConfig.php index 02e92594d..5df5b391c 100644 --- a/src/Supportive/Config/DeptracConfig.php +++ b/src/Supportive/Config/DeptracConfig.php @@ -12,13 +12,14 @@ final class DeptracConfig implements ConfigBuilderInterface { private bool $ignoreUncoveredInternalClasses = true; private bool $useRelativePathFromDepfile = true; - private array $paths = ['src']; + private array $paths = []; private array $layers = []; private array $formatters = []; private array $rulesets = []; - private array $analyser = [EmitterType::CLASS_TOKEN, EmitterType::USE_TOKEN]; + private array $analyser = []; private array $skipViolations = []; + private array $excludeFiles = []; public function analyser(EmitterType ...$types): self { @@ -59,17 +60,40 @@ public function ruleset(LayerConfig $layerConfig): RulesetConfig public function toArray(): array { - return [ - 'paths' => $this->paths, - 'exclude_files' => [], - 'layers' => array_map(static fn (LayerConfig $layerConfig) => $layerConfig->toArray(), $this->layers), - 'ruleset' => array_map(static fn (RulesetConfig $rulesetConfig) => $rulesetConfig->toArray(), $this->rulesets), - 'skip_violations' => $this->skipViolations, - 'formatters' => $this->formatters, - 'analyser' => ['types' => array_map(static fn (EmitterType $emitterType) => $emitterType->value, $this->analyser)], - 'ignore_uncovered_internal_classes' => $this->ignoreUncoveredInternalClasses, - 'use_relative_path_from_depfile' => $this->useRelativePathFromDepfile, - ]; + $config = []; + + if ([] !== $this->paths) { + $config['paths'] = $this->paths; + } + + if ([] !== $this->excludeFiles) { + $config['exclude_files'] = $this->excludeFiles; + } + + if ([] !== $this->layers) { + $config['layers'] = array_map(static fn (LayerConfig $layerConfig) => $layerConfig->toArray(), $this->layers); + } + + if ([] !== $this->rulesets) { + $config['ruleset'] = array_map(static fn (RulesetConfig $rulesetConfig) => $rulesetConfig->toArray(), $this->rulesets); + } + + if ([] !== $this->skipViolations) { + $config['skip_violations'] = $this->skipViolations; + } + + if ([] !== $this->formatters) { + $config['formatters'] = $this->formatters; + } + + if ([] !== $this->skipViolations) { + $config['analyser']['types'] = array_map(static fn (EmitterType $emitterType) => $emitterType->value, $this->analyser); + } + + $config['ignore_uncovered_internal_classes'] = $this->ignoreUncoveredInternalClasses; + $config['use_relative_path_from_depfile'] = $this->useRelativePathFromDepfile; + + return $config; } public function getExtensionAlias(): string From d877a478668a4eb390cc7835103f7fdb7f63a031 Mon Sep 17 00:00:00 2001 From: Gennadi McKelvey Date: Fri, 14 Oct 2022 16:19:09 +0200 Subject: [PATCH 14/39] remove generated configbuilder --- .../Symfony/Config/Deptrac/AnalyserConfig.php | 52 ---- .../Formatters/Codeclimate/SeverityConfig.php | 98 ------- .../Deptrac/Formatters/CodeclimateConfig.php | 56 ---- .../Deptrac/Formatters/GraphvizConfig.php | 97 ------- .../Config/Deptrac/FormattersConfig.php | 91 ------- .../Symfony/Config/Deptrac/LayersConfig.php | 94 ------- .../Deptrac/LayersConfig/CollectorsConfig.php | 133 ---------- .../Config/Symfony/Config/DeptracConfig.php | 239 ------------------ 8 files changed, 860 deletions(-) delete mode 100644 src/Supportive/Config/Symfony/Config/Deptrac/AnalyserConfig.php delete mode 100644 src/Supportive/Config/Symfony/Config/Deptrac/Formatters/Codeclimate/SeverityConfig.php delete mode 100644 src/Supportive/Config/Symfony/Config/Deptrac/Formatters/CodeclimateConfig.php delete mode 100644 src/Supportive/Config/Symfony/Config/Deptrac/Formatters/GraphvizConfig.php delete mode 100644 src/Supportive/Config/Symfony/Config/Deptrac/FormattersConfig.php delete mode 100644 src/Supportive/Config/Symfony/Config/Deptrac/LayersConfig.php delete mode 100644 src/Supportive/Config/Symfony/Config/Deptrac/LayersConfig/CollectorsConfig.php delete mode 100644 src/Supportive/Config/Symfony/Config/DeptracConfig.php diff --git a/src/Supportive/Config/Symfony/Config/Deptrac/AnalyserConfig.php b/src/Supportive/Config/Symfony/Config/Deptrac/AnalyserConfig.php deleted file mode 100644 index f46cc4f2e..000000000 --- a/src/Supportive/Config/Symfony/Config/Deptrac/AnalyserConfig.php +++ /dev/null @@ -1,52 +0,0 @@ -_usedProperties['types'] = true; - $this->types = $value; - - return $this; - } - - public function __construct(array $value = []) - { - if (array_key_exists('types', $value)) { - $this->_usedProperties['types'] = true; - $this->types = $value['types']; - unset($value['types']); - } - - if ([] !== $value) { - throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); - } - } - - public function toArray(): array - { - $output = []; - if (isset($this->_usedProperties['types'])) { - $output['types'] = $this->types; - } - - return $output; - } - -} diff --git a/src/Supportive/Config/Symfony/Config/Deptrac/Formatters/Codeclimate/SeverityConfig.php b/src/Supportive/Config/Symfony/Config/Deptrac/Formatters/Codeclimate/SeverityConfig.php deleted file mode 100644 index 013c326f2..000000000 --- a/src/Supportive/Config/Symfony/Config/Deptrac/Formatters/Codeclimate/SeverityConfig.php +++ /dev/null @@ -1,98 +0,0 @@ -_usedProperties['failure'] = true; - $this->failure = $value; - - return $this; - } - - /** - * @default 'minor' - * @param ParamConfigurator|'info'|'minor'|'major'|'critical'|'blocker' $value - * @return $this - */ - public function skipped($value): static - { - $this->_usedProperties['skipped'] = true; - $this->skipped = $value; - - return $this; - } - - /** - * @default 'info' - * @param ParamConfigurator|'info'|'minor'|'major'|'critical'|'blocker' $value - * @return $this - */ - public function uncovered($value): static - { - $this->_usedProperties['uncovered'] = true; - $this->uncovered = $value; - - return $this; - } - - public function __construct(array $value = []) - { - if (array_key_exists('failure', $value)) { - $this->_usedProperties['failure'] = true; - $this->failure = $value['failure']; - unset($value['failure']); - } - - if (array_key_exists('skipped', $value)) { - $this->_usedProperties['skipped'] = true; - $this->skipped = $value['skipped']; - unset($value['skipped']); - } - - if (array_key_exists('uncovered', $value)) { - $this->_usedProperties['uncovered'] = true; - $this->uncovered = $value['uncovered']; - unset($value['uncovered']); - } - - if ([] !== $value) { - throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); - } - } - - public function toArray(): array - { - $output = []; - if (isset($this->_usedProperties['failure'])) { - $output['failure'] = $this->failure; - } - if (isset($this->_usedProperties['skipped'])) { - $output['skipped'] = $this->skipped; - } - if (isset($this->_usedProperties['uncovered'])) { - $output['uncovered'] = $this->uncovered; - } - - return $output; - } - -} diff --git a/src/Supportive/Config/Symfony/Config/Deptrac/Formatters/CodeclimateConfig.php b/src/Supportive/Config/Symfony/Config/Deptrac/Formatters/CodeclimateConfig.php deleted file mode 100644 index 9128e6cc0..000000000 --- a/src/Supportive/Config/Symfony/Config/Deptrac/Formatters/CodeclimateConfig.php +++ /dev/null @@ -1,56 +0,0 @@ -severity) { - $this->_usedProperties['severity'] = true; - $this->severity = new \Symfony\Config\Deptrac\Formatters\Codeclimate\SeverityConfig($value); - } elseif (0 < \func_num_args()) { - throw new InvalidConfigurationException('The node created by "severity()" has already been initialized. You cannot pass values the second time you call severity().'); - } - - return $this->severity; - } - - public function __construct(array $value = []) - { - if (array_key_exists('severity', $value)) { - $this->_usedProperties['severity'] = true; - $this->severity = new \Symfony\Config\Deptrac\Formatters\Codeclimate\SeverityConfig($value['severity']); - unset($value['severity']); - } - - if ([] !== $value) { - throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); - } - } - - public function toArray(): array - { - $output = []; - if (isset($this->_usedProperties['severity'])) { - $output['severity'] = $this->severity->toArray(); - } - - return $output; - } - -} diff --git a/src/Supportive/Config/Symfony/Config/Deptrac/Formatters/GraphvizConfig.php b/src/Supportive/Config/Symfony/Config/Deptrac/Formatters/GraphvizConfig.php deleted file mode 100644 index a27ed1bf1..000000000 --- a/src/Supportive/Config/Symfony/Config/Deptrac/Formatters/GraphvizConfig.php +++ /dev/null @@ -1,97 +0,0 @@ - $value - * - * @return $this - */ - public function hiddenLayers(ParamConfigurator|array $value): static - { - $this->_usedProperties['hiddenLayers'] = true; - $this->hiddenLayers = $value; - - return $this; - } - - /** - * @return $this - */ - public function groups(string $name, ParamConfigurator|array $value): static - { - $this->_usedProperties['groups'] = true; - $this->groups[$name] = $value; - - return $this; - } - - /** - * When a layer is part of a group, should edges point towards the group or the layer? - * @default false - * @param ParamConfigurator|bool $value - * @return $this - */ - public function pointToGroups($value): static - { - $this->_usedProperties['pointToGroups'] = true; - $this->pointToGroups = $value; - - return $this; - } - - public function __construct(array $value = []) - { - if (array_key_exists('hidden_layers', $value)) { - $this->_usedProperties['hiddenLayers'] = true; - $this->hiddenLayers = $value['hidden_layers']; - unset($value['hidden_layers']); - } - - if (array_key_exists('groups', $value)) { - $this->_usedProperties['groups'] = true; - $this->groups = $value['groups']; - unset($value['groups']); - } - - if (array_key_exists('point_to_groups', $value)) { - $this->_usedProperties['pointToGroups'] = true; - $this->pointToGroups = $value['point_to_groups']; - unset($value['point_to_groups']); - } - - if ([] !== $value) { - throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); - } - } - - public function toArray(): array - { - $output = []; - if (isset($this->_usedProperties['hiddenLayers'])) { - $output['hidden_layers'] = $this->hiddenLayers; - } - if (isset($this->_usedProperties['groups'])) { - $output['groups'] = $this->groups; - } - if (isset($this->_usedProperties['pointToGroups'])) { - $output['point_to_groups'] = $this->pointToGroups; - } - - return $output; - } - -} diff --git a/src/Supportive/Config/Symfony/Config/Deptrac/FormattersConfig.php b/src/Supportive/Config/Symfony/Config/Deptrac/FormattersConfig.php deleted file mode 100644 index 5a4277375..000000000 --- a/src/Supportive/Config/Symfony/Config/Deptrac/FormattersConfig.php +++ /dev/null @@ -1,91 +0,0 @@ -_usedProperties['graphviz'] = true; - $this->graphviz = $value; - - return $this; - } - - if (!$this->graphviz instanceof \Symfony\Config\Deptrac\Formatters\GraphvizConfig) { - $this->_usedProperties['graphviz'] = true; - $this->graphviz = new \Symfony\Config\Deptrac\Formatters\GraphvizConfig($value); - } elseif (0 < \func_num_args()) { - throw new InvalidConfigurationException('The node created by "graphviz()" has already been initialized. You cannot pass values the second time you call graphviz().'); - } - - return $this->graphviz; - } - - /** - * Configure Codeclimate output formatters - * @default {"severity":{"failure":"major","skipped":"minor","uncovered":"info"}} - */ - public function codeclimate(array $value = []): \Symfony\Config\Deptrac\Formatters\CodeclimateConfig - { - if (null === $this->codeclimate) { - $this->_usedProperties['codeclimate'] = true; - $this->codeclimate = new \Symfony\Config\Deptrac\Formatters\CodeclimateConfig($value); - } elseif (0 < \func_num_args()) { - throw new InvalidConfigurationException('The node created by "codeclimate()" has already been initialized. You cannot pass values the second time you call codeclimate().'); - } - - return $this->codeclimate; - } - - public function __construct(array $value = []) - { - if (array_key_exists('graphviz', $value)) { - $this->_usedProperties['graphviz'] = true; - $this->graphviz = \is_array($value['graphviz']) ? new \Symfony\Config\Deptrac\Formatters\GraphvizConfig($value['graphviz']) : $value['graphviz']; - unset($value['graphviz']); - } - - if (array_key_exists('codeclimate', $value)) { - $this->_usedProperties['codeclimate'] = true; - $this->codeclimate = new \Symfony\Config\Deptrac\Formatters\CodeclimateConfig($value['codeclimate']); - unset($value['codeclimate']); - } - - if ([] !== $value) { - throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); - } - } - - public function toArray(): array - { - $output = []; - if (isset($this->_usedProperties['graphviz'])) { - $output['graphviz'] = $this->graphviz instanceof \Symfony\Config\Deptrac\Formatters\GraphvizConfig ? $this->graphviz->toArray() : $this->graphviz; - } - if (isset($this->_usedProperties['codeclimate'])) { - $output['codeclimate'] = $this->codeclimate->toArray(); - } - - return $output; - } - -} diff --git a/src/Supportive/Config/Symfony/Config/Deptrac/LayersConfig.php b/src/Supportive/Config/Symfony/Config/Deptrac/LayersConfig.php deleted file mode 100644 index d88330c08..000000000 --- a/src/Supportive/Config/Symfony/Config/Deptrac/LayersConfig.php +++ /dev/null @@ -1,94 +0,0 @@ -_usedProperties['name'] = true; - $this->name = $value; - - return $this; - } - - public function collectors(array $value = []): \Symfony\Config\Deptrac\LayersConfig\CollectorsConfig - { - $this->_usedProperties['collectors'] = true; - - return $this->collectors[] = new \Symfony\Config\Deptrac\LayersConfig\CollectorsConfig($value); - } - - /** - * @param ParamConfigurator|list $value - * - * @return $this - */ - public function attributes(ParamConfigurator|array $value): static - { - $this->_usedProperties['attributes'] = true; - $this->attributes = $value; - - return $this; - } - - public function __construct(array $value = []) - { - if (array_key_exists('name', $value)) { - $this->_usedProperties['name'] = true; - $this->name = $value['name']; - unset($value['name']); - } - - if (array_key_exists('collectors', $value)) { - $this->_usedProperties['collectors'] = true; - $this->collectors = array_map(function ($v) { return new \Symfony\Config\Deptrac\LayersConfig\CollectorsConfig($v); }, $value['collectors']); - unset($value['collectors']); - } - - if (array_key_exists('attributes', $value)) { - $this->_usedProperties['attributes'] = true; - $this->attributes = $value['attributes']; - unset($value['attributes']); - } - - if ([] !== $value) { - throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); - } - } - - public function toArray(): array - { - $output = []; - if (isset($this->_usedProperties['name'])) { - $output['name'] = $this->name; - } - if (isset($this->_usedProperties['collectors'])) { - $output['collectors'] = array_map(function ($v) { return $v->toArray(); }, $this->collectors); - } - if (isset($this->_usedProperties['attributes'])) { - $output['attributes'] = $this->attributes; - } - - return $output; - } - -} diff --git a/src/Supportive/Config/Symfony/Config/Deptrac/LayersConfig/CollectorsConfig.php b/src/Supportive/Config/Symfony/Config/Deptrac/LayersConfig/CollectorsConfig.php deleted file mode 100644 index b39b60816..000000000 --- a/src/Supportive/Config/Symfony/Config/Deptrac/LayersConfig/CollectorsConfig.php +++ /dev/null @@ -1,133 +0,0 @@ -_usedProperties['type'] = true; - $this->type = $value; - - return $this; - } - - /** - * @default null - * @param ParamConfigurator|mixed $value - * - * @return $this - */ - public function value(mixed $value): static - { - $this->_usedProperties['value'] = true; - $this->value = $value; - - return $this; - } - - /** - * @default false - * @param ParamConfigurator|bool $value - * @return $this - */ - public function private($value): static - { - $this->_usedProperties['private'] = true; - $this->private = $value; - - return $this; - } - - /** - * @param ParamConfigurator|list $value - * - * @return $this - */ - public function attributes(ParamConfigurator|array $value): static - { - $this->_usedProperties['attributes'] = true; - $this->attributes = $value; - - return $this; - } - - public function __construct(array $value = []) - { - if (array_key_exists('type', $value)) { - $this->_usedProperties['type'] = true; - $this->type = $value['type']; - unset($value['type']); - } - - if (array_key_exists('value', $value)) { - $this->_usedProperties['value'] = true; - $this->value = $value['value']; - unset($value['value']); - } - - if (array_key_exists('private', $value)) { - $this->_usedProperties['private'] = true; - $this->private = $value['private']; - unset($value['private']); - } - - if (array_key_exists('attributes', $value)) { - $this->_usedProperties['attributes'] = true; - $this->attributes = $value['attributes']; - unset($value['attributes']); - } - - $this->_extraKeys = $value; - - } - - public function toArray(): array - { - $output = []; - if (isset($this->_usedProperties['type'])) { - $output['type'] = $this->type; - } - if (isset($this->_usedProperties['value'])) { - $output['value'] = $this->value; - } - if (isset($this->_usedProperties['private'])) { - $output['private'] = $this->private; - } - if (isset($this->_usedProperties['attributes'])) { - $output['attributes'] = $this->attributes; - } - - return $output + $this->_extraKeys; - } - - /** - * @param ParamConfigurator|mixed $value - * - * @return $this - */ - public function set(string $key, mixed $value): static - { - $this->_extraKeys[$key] = $value; - - return $this; - } - -} diff --git a/src/Supportive/Config/Symfony/Config/DeptracConfig.php b/src/Supportive/Config/Symfony/Config/DeptracConfig.php deleted file mode 100644 index db78d6064..000000000 --- a/src/Supportive/Config/Symfony/Config/DeptracConfig.php +++ /dev/null @@ -1,239 +0,0 @@ - $value - * - * @return $this - */ - public function paths(ParamConfigurator|array $value): static - { - $this->_usedProperties['paths'] = true; - $this->paths = $value; - - return $this; - } - - /** - * @param ParamConfigurator|list $value - * - * @return $this - */ - public function excludeFiles(ParamConfigurator|array $value): static - { - $this->_usedProperties['excludeFiles'] = true; - $this->excludeFiles = $value; - - return $this; - } - - public function layers(array $value = []): \Symfony\Config\Deptrac\LayersConfig - { - $this->_usedProperties['layers'] = true; - - return $this->layers[] = new \Symfony\Config\Deptrac\LayersConfig($value); - } - - /** - * @return $this - */ - public function ruleset(string $name, ParamConfigurator|array $value): static - { - $this->_usedProperties['ruleset'] = true; - $this->ruleset[$name] = $value; - - return $this; - } - - /** - * @return $this - */ - public function skipViolation(string $name, ParamConfigurator|array $value): static - { - $this->_usedProperties['skipViolations'] = true; - $this->skipViolations[$name] = $value; - - return $this; - } - - /** - * @default {"graphviz":{"hidden_layers":[],"groups":[],"point_to_groups":false},"codeclimate":{"severity":{"failure":"major","skipped":"minor","uncovered":"info"}}} - */ - public function formatters(array $value = []): \Symfony\Config\Deptrac\FormattersConfig - { - if (null === $this->formatters) { - $this->_usedProperties['formatters'] = true; - $this->formatters = new \Symfony\Config\Deptrac\FormattersConfig($value); - } elseif (0 < \func_num_args()) { - throw new InvalidConfigurationException('The node created by "formatters()" has already been initialized. You cannot pass values the second time you call formatters().'); - } - - return $this->formatters; - } - - /** - * @default {"types":["class","use"]} - */ - public function analyser(array $value = []): \Symfony\Config\Deptrac\AnalyserConfig - { - if (null === $this->analyser) { - $this->_usedProperties['analyser'] = true; - $this->analyser = new \Symfony\Config\Deptrac\AnalyserConfig($value); - } elseif (0 < \func_num_args()) { - throw new InvalidConfigurationException('The node created by "analyser()" has already been initialized. You cannot pass values the second time you call analyser().'); - } - - return $this->analyser; - } - - /** - * @default true - * @param ParamConfigurator|bool $value - * @return $this - */ - public function ignoreUncoveredInternalClasses($value): static - { - $this->_usedProperties['ignoreUncoveredInternalClasses'] = true; - $this->ignoreUncoveredInternalClasses = $value; - - return $this; - } - - /** - * @default true - * @param ParamConfigurator|bool $value - * @return $this - */ - public function useRelativePathFromDepfile($value): static - { - $this->_usedProperties['useRelativePathFromDepfile'] = true; - $this->useRelativePathFromDepfile = $value; - - return $this; - } - - public function getExtensionAlias(): string - { - return 'deptrac'; - } - - public function __construct(array $value = []) - { - if (array_key_exists('paths', $value)) { - $this->_usedProperties['paths'] = true; - $this->paths = $value['paths']; - unset($value['paths']); - } - - if (array_key_exists('exclude_files', $value)) { - $this->_usedProperties['excludeFiles'] = true; - $this->excludeFiles = $value['exclude_files']; - unset($value['exclude_files']); - } - - if (array_key_exists('layers', $value)) { - $this->_usedProperties['layers'] = true; - $this->layers = array_map(function ($v) { return new \Symfony\Config\Deptrac\LayersConfig($v); }, $value['layers']); - unset($value['layers']); - } - - if (array_key_exists('ruleset', $value)) { - $this->_usedProperties['ruleset'] = true; - $this->ruleset = $value['ruleset']; - unset($value['ruleset']); - } - - if (array_key_exists('skip_violations', $value)) { - $this->_usedProperties['skipViolations'] = true; - $this->skipViolations = $value['skip_violations']; - unset($value['skip_violations']); - } - - if (array_key_exists('formatters', $value)) { - $this->_usedProperties['formatters'] = true; - $this->formatters = new \Symfony\Config\Deptrac\FormattersConfig($value['formatters']); - unset($value['formatters']); - } - - if (array_key_exists('analyser', $value)) { - $this->_usedProperties['analyser'] = true; - $this->analyser = new \Symfony\Config\Deptrac\AnalyserConfig($value['analyser']); - unset($value['analyser']); - } - - if (array_key_exists('ignore_uncovered_internal_classes', $value)) { - $this->_usedProperties['ignoreUncoveredInternalClasses'] = true; - $this->ignoreUncoveredInternalClasses = $value['ignore_uncovered_internal_classes']; - unset($value['ignore_uncovered_internal_classes']); - } - - if (array_key_exists('use_relative_path_from_depfile', $value)) { - $this->_usedProperties['useRelativePathFromDepfile'] = true; - $this->useRelativePathFromDepfile = $value['use_relative_path_from_depfile']; - unset($value['use_relative_path_from_depfile']); - } - - if ([] !== $value) { - throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); - } - } - - public function toArray(): array - { - $output = []; - if (isset($this->_usedProperties['paths'])) { - $output['paths'] = $this->paths; - } - if (isset($this->_usedProperties['excludeFiles'])) { - $output['exclude_files'] = $this->excludeFiles; - } - if (isset($this->_usedProperties['layers'])) { - $output['layers'] = array_map(function ($v) { return $v->toArray(); }, $this->layers); - } - if (isset($this->_usedProperties['ruleset'])) { - $output['ruleset'] = $this->ruleset; - } - if (isset($this->_usedProperties['skipViolations'])) { - $output['skip_violations'] = $this->skipViolations; - } - if (isset($this->_usedProperties['formatters'])) { - $output['formatters'] = $this->formatters->toArray(); - } - if (isset($this->_usedProperties['analyser'])) { - $output['analyser'] = $this->analyser->toArray(); - } - if (isset($this->_usedProperties['ignoreUncoveredInternalClasses'])) { - $output['ignore_uncovered_internal_classes'] = $this->ignoreUncoveredInternalClasses; - } - if (isset($this->_usedProperties['useRelativePathFromDepfile'])) { - $output['use_relative_path_from_depfile'] = $this->useRelativePathFromDepfile; - } - - return $output; - } - -} From 12fac0b85d66b181308a45c50b2122da4be6728b Mon Sep 17 00:00:00 2001 From: Gennadi McKelvey Date: Fri, 14 Oct 2022 21:49:56 +0200 Subject: [PATCH 15/39] configure services --- deptrac.config.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/deptrac.config.php b/deptrac.config.php index b9c8bd402..40350ca25 100755 --- a/deptrac.config.php +++ b/deptrac.config.php @@ -1,10 +1,18 @@ services(); + $services->set(IgnoreDependenciesOnContract::class)->tag('kernel.event_listener', ['event' => ProcessEvent::class]); + $services->set(IgnoreDependenciesOnShouldNotHappenException::class)->tag('kernel.event_listener', ['event' => ProcessEvent::class]); -return static function (DeptracConfig $config): void { $config->paths(['./src']); $config->baseline('./deptrac.baseline.yaml'); // analyser From f0ff50e673cca102b6b8e3b38f3214c3a8af9251 Mon Sep 17 00:00:00 2001 From: Gennadi McKelvey Date: Sat, 15 Oct 2022 17:29:51 +0200 Subject: [PATCH 16/39] add DocBlock to array --- src/Supportive/Config/CollectorConfig.php | 3 +++ src/Supportive/Config/DeptracConfig.php | 21 ++++++++++++++++----- src/Supportive/Config/LayerConfig.php | 2 ++ src/Supportive/Config/RulesetConfig.php | 2 ++ 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/Supportive/Config/CollectorConfig.php b/src/Supportive/Config/CollectorConfig.php index 5de02a8e6..dda95f7cc 100644 --- a/src/Supportive/Config/CollectorConfig.php +++ b/src/Supportive/Config/CollectorConfig.php @@ -10,7 +10,9 @@ final class CollectorConfig { private ?string $value = null; private bool $private = false; + /** @var array */ private array $mustNot = []; + /** @var array */ private array $must = []; private function __construct( @@ -49,6 +51,7 @@ public function private(): self return $this; } + /** @return array */ public function toArray(): array { return [ diff --git a/src/Supportive/Config/DeptracConfig.php b/src/Supportive/Config/DeptracConfig.php index 5df5b391c..76628a3a6 100644 --- a/src/Supportive/Config/DeptracConfig.php +++ b/src/Supportive/Config/DeptracConfig.php @@ -13,12 +13,19 @@ final class DeptracConfig implements ConfigBuilderInterface private bool $ignoreUncoveredInternalClasses = true; private bool $useRelativePathFromDepfile = true; + /** @var array */ private array $paths = []; + /** @var array */ private array $layers = []; + /** @var array */ private array $formatters = []; + /** @var array */ private array $rulesets = []; + /** @var array */ private array $analyser = []; + /** @var array> */ private array $skipViolations = []; + /** @var array */ private array $excludeFiles = []; public function analyser(EmitterType ...$types): self @@ -32,16 +39,19 @@ public function analyser(EmitterType ...$types): self public function baseline(string $baseline): self { - $baseline = Yaml::parseFile($baseline); + /** @var array>> $baselineAsArray */ + $baselineAsArray = Yaml::parseFile($baseline); + /** @var array */ + $skipViolations = $baselineAsArray['deptrac']['skip_violations'] ?? []; - foreach ($baseline['deptrac']['skip_violations'] ?? [] as $class => $skipViolations) { - $this->skipViolations[$class] = $skipViolations; + foreach ($skipViolations as $class => $skipViolation) { + $this->skipViolations[$class][] = $skipViolation; } return $this; } - public function paths(array $paths): self + public function paths(string ...$paths): self { $this->paths = $paths; @@ -58,6 +68,7 @@ public function ruleset(LayerConfig $layerConfig): RulesetConfig return $this->rulesets[] = new RulesetConfig($layerConfig); } + /** @return array */ public function toArray(): array { $config = []; @@ -83,7 +94,7 @@ public function toArray(): array } if ([] !== $this->formatters) { - $config['formatters'] = $this->formatters; + $config['formatters'] = array_map(static fn (FormatterConfig $formatterConfig) => $formatterConfig->__toString(), $this->formatters); } if ([] !== $this->skipViolations) { diff --git a/src/Supportive/Config/LayerConfig.php b/src/Supportive/Config/LayerConfig.php index 4f8eac735..61bd7b2e9 100644 --- a/src/Supportive/Config/LayerConfig.php +++ b/src/Supportive/Config/LayerConfig.php @@ -9,6 +9,7 @@ final class LayerConfig implements Stringable { + /** @var array */ private array $colloctors; public function __construct( @@ -21,6 +22,7 @@ public function collector(CollectorType $collectorType): CollectorConfig return $this->colloctors[] = CollectorConfig::fromType($collectorType); } + /** @return array */ public function toArray(): array { return ['name' => $this->name, 'collectors' => array_map(static fn (CollectorConfig $config) => $config->toArray(), $this->colloctors)]; diff --git a/src/Supportive/Config/RulesetConfig.php b/src/Supportive/Config/RulesetConfig.php index 9a5ef1af4..0ff3bc225 100644 --- a/src/Supportive/Config/RulesetConfig.php +++ b/src/Supportive/Config/RulesetConfig.php @@ -6,6 +6,7 @@ final class RulesetConfig { + /** @var array */ private array $accessableLayers = []; public function __construct( @@ -22,6 +23,7 @@ public function accessesLayer(LayerConfig ...$layersConfig): self return $this; } + /** @return array */ public function toArray(): array { $data = array_map(static fn (LayerConfig $layerConfig) => $layerConfig->__toString(), $this->accessableLayers); From 395ad0a4f734b6521c204daee4d61c33bf9fca4b Mon Sep 17 00:00:00 2001 From: Gennadi McKelvey Date: Sat, 15 Oct 2022 17:36:53 +0200 Subject: [PATCH 17/39] fix psalm stuff --- src/Supportive/Config/LayerConfig.php | 2 +- src/Supportive/Config/RulesetConfig.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Supportive/Config/LayerConfig.php b/src/Supportive/Config/LayerConfig.php index 61bd7b2e9..495ede6c8 100644 --- a/src/Supportive/Config/LayerConfig.php +++ b/src/Supportive/Config/LayerConfig.php @@ -10,7 +10,7 @@ final class LayerConfig implements Stringable { /** @var array */ - private array $colloctors; + private array $colloctors = []; public function __construct( public readonly string $name diff --git a/src/Supportive/Config/RulesetConfig.php b/src/Supportive/Config/RulesetConfig.php index 0ff3bc225..4f1fda65f 100644 --- a/src/Supportive/Config/RulesetConfig.php +++ b/src/Supportive/Config/RulesetConfig.php @@ -26,6 +26,7 @@ public function accessesLayer(LayerConfig ...$layersConfig): self /** @return array */ public function toArray(): array { + /** @var array */ $data = array_map(static fn (LayerConfig $layerConfig) => $layerConfig->__toString(), $this->accessableLayers); return $data + ['name' => $this->layersConfig->__toString()]; From edf5670869b7c714748f619ef44b3b06a7c3316d Mon Sep 17 00:00:00 2001 From: Gennadi McKelvey Date: Sat, 15 Oct 2022 17:47:39 +0200 Subject: [PATCH 18/39] remove unused layers --- deptrac.config.php | 5 +++-- deptrac.yaml | 12 ++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/deptrac.config.php b/deptrac.config.php index 40350ca25..d919cefb1 100755 --- a/deptrac.config.php +++ b/deptrac.config.php @@ -1,7 +1,7 @@ set(IgnoreDependenciesOnContract::class)->tag('kernel.event_listener', ['event' => ProcessEvent::class]); $services->set(IgnoreDependenciesOnShouldNotHappenException::class)->tag('kernel.event_listener', ['event' => ProcessEvent::class]); - $config->paths(['./src']); + $config->paths('./src'); $config->baseline('./deptrac.baseline.yaml'); + // analyser $config->analyser( EmitterType::CLASS_TOKEN, diff --git a/deptrac.yaml b/deptrac.yaml index 794694002..99691e1f9 100644 --- a/deptrac.yaml +++ b/deptrac.yaml @@ -113,19 +113,19 @@ deptrac: - File Dependency: - Ast - Result: - - Dependency +# Result: +# - Dependency Analyser: - - Result +# - Result - Layer - Dependency - Ast OutputFormatter: - - Result +# - Result - Console - DependencyInjection - Events: - - Result +# Events: +# - Result Ast: - File - InputCollector From cdce7efa3d5223bf201493487d1921e77614ed18 Mon Sep 17 00:00:00 2001 From: Gennadi McKelvey Date: Tue, 1 Nov 2022 19:28:16 +0100 Subject: [PATCH 19/39] move config to contract namespace --- deptrac.config.php | 4 ++-- deptrac.yaml => deptrac.config.yaml | 0 src/{Supportive => Contract}/Config/CollectorConfig.php | 2 +- src/{Supportive => Contract}/Config/DeptracConfig.php | 2 +- src/{Supportive => Contract}/Config/FormatterConfig.php | 2 +- src/{Supportive => Contract}/Config/LayerConfig.php | 2 +- src/{Supportive => Contract}/Config/RulesetConfig.php | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) rename deptrac.yaml => deptrac.config.yaml (100%) rename src/{Supportive => Contract}/Config/CollectorConfig.php (97%) rename src/{Supportive => Contract}/Config/DeptracConfig.php (98%) rename src/{Supportive => Contract}/Config/FormatterConfig.php (80%) rename src/{Supportive => Contract}/Config/LayerConfig.php (94%) rename src/{Supportive => Contract}/Config/RulesetConfig.php (94%) diff --git a/deptrac.config.php b/deptrac.config.php index d919cefb1..8af3cf14a 100755 --- a/deptrac.config.php +++ b/deptrac.config.php @@ -1,10 +1,10 @@ Date: Tue, 1 Nov 2022 19:48:35 +0100 Subject: [PATCH 20/39] move types to contract namespace --- config/services.php | 4 ++-- deptrac.config.php | 10 +++++----- src/Contract/Config/CollectorConfig.php | 2 -- .../Collector => Contract/Config}/CollectorType.php | 2 +- src/Contract/Config/DeptracConfig.php | 5 ++--- .../Config}/EmitterType.php | 2 +- src/Contract/Config/LayerConfig.php | 1 - src/Core/Analyser/TokenInLayerAnalyser.php | 1 - src/Core/Analyser/TokenType.php | 2 +- src/Core/Analyser/UnassignedTokenAnalyser.php | 1 - src/Supportive/DependencyInjection/Configuration.php | 1 + .../DependencyInjection/DeptracExtension.php | 1 + tests/Core/Dependency/DependencyResolverTest.php | 2 +- .../DependencyInjection/DeptracExtensionTest.php | 2 +- 14 files changed, 16 insertions(+), 20 deletions(-) rename src/{Core/Layer/Collector => Contract/Config}/CollectorType.php (95%) rename src/{Supportive/DependencyInjection => Contract/Config}/EmitterType.php (90%) diff --git a/config/services.php b/config/services.php index a20a5aba7..53315b884 100644 --- a/config/services.php +++ b/config/services.php @@ -8,6 +8,8 @@ use Psr\EventDispatcher\EventDispatcherInterface; use Qossmic\Deptrac\Contract\Analyser\EventHelper; use Qossmic\Deptrac\Contract\Layer\LayerProvider; +use Qossmic\Deptrac\Contract\Config\CollectorType; +use Qossmic\Deptrac\Contract\Config\EmitterType; use Qossmic\Deptrac\Core\Analyser\DependencyLayersAnalyser; use Qossmic\Deptrac\Core\Analyser\EventHandler\AllowDependencyHandler; use Qossmic\Deptrac\Core\Analyser\EventHandler\DependsOnDisallowedLayer; @@ -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; @@ -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; diff --git a/deptrac.config.php b/deptrac.config.php index 8af3cf14a..a808db659 100755 --- a/deptrac.config.php +++ b/deptrac.config.php @@ -4,17 +4,17 @@ use Internal\Qossmic\Deptrac\IgnoreDependenciesOnShouldNotHappenException; use Qossmic\Deptrac\Contract\Analyser\ProcessEvent; use Qossmic\Deptrac\Contract\Config\DeptracConfig; -use Qossmic\Deptrac\Core\Layer\Collector\CollectorType; -use Qossmic\Deptrac\Supportive\DependencyInjection\EmitterType; +use Qossmic\Deptrac\Contract\Config\CollectorType; +use Qossmic\Deptrac\Contract\Config\EmitterType; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; -return static function (DeptracConfig $config, ContainerConfigurator $containerConfigurator): void { +return static function (DeptracConfig $config, ContainerConfigurator $containerConfigurator): void { $services = $containerConfigurator->services(); $services->set(IgnoreDependenciesOnContract::class)->tag('kernel.event_listener', ['event' => ProcessEvent::class]); $services->set(IgnoreDependenciesOnShouldNotHappenException::class)->tag('kernel.event_listener', ['event' => ProcessEvent::class]); - $config->paths('./src'); - $config->baseline('./deptrac.baseline.yaml'); + $config->paths('src'); + //$config->baseline('deptrac.baseline.yaml'); // analyser $config->analyser( diff --git a/src/Contract/Config/CollectorConfig.php b/src/Contract/Config/CollectorConfig.php index 9d2932968..082ffa001 100644 --- a/src/Contract/Config/CollectorConfig.php +++ b/src/Contract/Config/CollectorConfig.php @@ -4,8 +4,6 @@ namespace Qossmic\Deptrac\Contract\Config; -use Qossmic\Deptrac\Core\Layer\Collector\CollectorType; - final class CollectorConfig { private ?string $value = null; diff --git a/src/Core/Layer/Collector/CollectorType.php b/src/Contract/Config/CollectorType.php similarity index 95% rename from src/Core/Layer/Collector/CollectorType.php rename to src/Contract/Config/CollectorType.php index 8243654d2..bef4db00c 100644 --- a/src/Core/Layer/Collector/CollectorType.php +++ b/src/Contract/Config/CollectorType.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Qossmic\Deptrac\Core\Layer\Collector; +namespace Qossmic\Deptrac\Contract\Config; enum CollectorType: string { diff --git a/src/Contract/Config/DeptracConfig.php b/src/Contract/Config/DeptracConfig.php index 62877401c..2025759ae 100644 --- a/src/Contract/Config/DeptracConfig.php +++ b/src/Contract/Config/DeptracConfig.php @@ -4,7 +4,6 @@ namespace Qossmic\Deptrac\Contract\Config; -use Qossmic\Deptrac\Supportive\DependencyInjection\EmitterType; use Symfony\Component\Config\Builder\ConfigBuilderInterface; use Symfony\Component\Yaml\Yaml; @@ -21,7 +20,7 @@ final class DeptracConfig implements ConfigBuilderInterface private array $formatters = []; /** @var array */ private array $rulesets = []; - /** @var array */ + /** @var array */ private array $analyser = []; /** @var array> */ private array $skipViolations = []; @@ -45,7 +44,7 @@ public function baseline(string $baseline): self $skipViolations = $baselineAsArray['deptrac']['skip_violations'] ?? []; foreach ($skipViolations as $class => $skipViolation) { - $this->skipViolations[$class][] = $skipViolation; + $this->skipViolations[$class] = $skipViolation; } return $this; diff --git a/src/Supportive/DependencyInjection/EmitterType.php b/src/Contract/Config/EmitterType.php similarity index 90% rename from src/Supportive/DependencyInjection/EmitterType.php rename to src/Contract/Config/EmitterType.php index a86efa6e3..df6634b4a 100644 --- a/src/Supportive/DependencyInjection/EmitterType.php +++ b/src/Contract/Config/EmitterType.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Qossmic\Deptrac\Supportive\DependencyInjection; +namespace Qossmic\Deptrac\Contract\Config; enum EmitterType: string { diff --git a/src/Contract/Config/LayerConfig.php b/src/Contract/Config/LayerConfig.php index 5494743a8..1b86417ac 100644 --- a/src/Contract/Config/LayerConfig.php +++ b/src/Contract/Config/LayerConfig.php @@ -4,7 +4,6 @@ namespace Qossmic\Deptrac\Contract\Config; -use Qossmic\Deptrac\Core\Layer\Collector\CollectorType; use Stringable; final class LayerConfig implements Stringable diff --git a/src/Core/Analyser/TokenInLayerAnalyser.php b/src/Core/Analyser/TokenInLayerAnalyser.php index f40150fdd..b8cd45f56 100644 --- a/src/Core/Analyser/TokenInLayerAnalyser.php +++ b/src/Core/Analyser/TokenInLayerAnalyser.php @@ -12,7 +12,6 @@ use Qossmic\Deptrac\Core\Dependency\TokenResolver; use Qossmic\Deptrac\Core\Dependency\UnrecognizedTokenException; use Qossmic\Deptrac\Core\Layer\LayerResolverInterface; -use Qossmic\Deptrac\Supportive\DependencyInjection\EmitterType; use function array_values; use function in_array; diff --git a/src/Core/Analyser/TokenType.php b/src/Core/Analyser/TokenType.php index 9449ccbe5..3355c0edd 100644 --- a/src/Core/Analyser/TokenType.php +++ b/src/Core/Analyser/TokenType.php @@ -4,7 +4,7 @@ namespace Qossmic\Deptrac\Core\Analyser; -use Qossmic\Deptrac\Supportive\DependencyInjection\EmitterType; +use Qossmic\Deptrac\Contract\Config\EmitterType; enum TokenType: string { diff --git a/src/Core/Analyser/UnassignedTokenAnalyser.php b/src/Core/Analyser/UnassignedTokenAnalyser.php index 6439002d7..05c6a33c5 100644 --- a/src/Core/Analyser/UnassignedTokenAnalyser.php +++ b/src/Core/Analyser/UnassignedTokenAnalyser.php @@ -12,7 +12,6 @@ use Qossmic\Deptrac\Core\Dependency\TokenResolver; use Qossmic\Deptrac\Core\Dependency\UnrecognizedTokenException; use Qossmic\Deptrac\Core\Layer\LayerResolverInterface; -use Qossmic\Deptrac\Supportive\DependencyInjection\EmitterType; use function array_values; use function natcasesort; diff --git a/src/Supportive/DependencyInjection/Configuration.php b/src/Supportive/DependencyInjection/Configuration.php index 80dae0b19..d376c7464 100644 --- a/src/Supportive/DependencyInjection/Configuration.php +++ b/src/Supportive/DependencyInjection/Configuration.php @@ -6,6 +6,7 @@ use InvalidArgumentException; use RuntimeException; +use Qossmic\Deptrac\Contract\Config\EmitterType; use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\ConfigurationInterface; diff --git a/src/Supportive/DependencyInjection/DeptracExtension.php b/src/Supportive/DependencyInjection/DeptracExtension.php index c52123dd8..0d8be46a9 100644 --- a/src/Supportive/DependencyInjection/DeptracExtension.php +++ b/src/Supportive/DependencyInjection/DeptracExtension.php @@ -4,6 +4,7 @@ namespace Qossmic\Deptrac\Supportive\DependencyInjection; +use Qossmic\Deptrac\Contract\Config\EmitterType; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\Extension; use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; diff --git a/tests/Core/Dependency/DependencyResolverTest.php b/tests/Core/Dependency/DependencyResolverTest.php index 599d4ce62..d2987f754 100644 --- a/tests/Core/Dependency/DependencyResolverTest.php +++ b/tests/Core/Dependency/DependencyResolverTest.php @@ -6,6 +6,7 @@ use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; +use Qossmic\Deptrac\Contract\Config\EmitterType; use Qossmic\Deptrac\Contract\Dependency\PostEmitEvent; use Qossmic\Deptrac\Contract\Dependency\PostFlattenEvent; use Qossmic\Deptrac\Contract\Dependency\PreEmitEvent; @@ -20,7 +21,6 @@ use Qossmic\Deptrac\Core\Dependency\Emitter\UsesDependencyEmitter; use Qossmic\Deptrac\Core\Dependency\InheritanceFlattener; use Qossmic\Deptrac\Core\Dependency\InvalidEmitterConfigurationException; -use Qossmic\Deptrac\Supportive\DependencyInjection\EmitterType; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\EventDispatcher\EventDispatcherInterface; diff --git a/tests/Supportive/DependencyInjection/DeptracExtensionTest.php b/tests/Supportive/DependencyInjection/DeptracExtensionTest.php index f84213659..a40908bf4 100644 --- a/tests/Supportive/DependencyInjection/DeptracExtensionTest.php +++ b/tests/Supportive/DependencyInjection/DeptracExtensionTest.php @@ -6,8 +6,8 @@ use InvalidArgumentException; use PHPUnit\Framework\TestCase; +use Qossmic\Deptrac\Contract\Config\EmitterType; use Qossmic\Deptrac\Supportive\DependencyInjection\DeptracExtension; -use Qossmic\Deptrac\Supportive\DependencyInjection\EmitterType; use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; use Symfony\Component\DependencyInjection\ContainerBuilder; From d43b6a1f928d90159cf77123d1cbdf2408c2a2a0 Mon Sep 17 00:00:00 2001 From: Gennadi McKelvey Date: Fri, 11 Nov 2022 08:47:45 +0100 Subject: [PATCH 21/39] fix typo --- src/Contract/Config/LayerConfig.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Contract/Config/LayerConfig.php b/src/Contract/Config/LayerConfig.php index 1b86417ac..b34857a51 100644 --- a/src/Contract/Config/LayerConfig.php +++ b/src/Contract/Config/LayerConfig.php @@ -9,7 +9,7 @@ final class LayerConfig implements Stringable { /** @var array */ - private array $colloctors = []; + private array $collectors = []; public function __construct( public readonly string $name @@ -18,13 +18,13 @@ public function __construct( public function collector(CollectorType $collectorType): CollectorConfig { - return $this->colloctors[] = CollectorConfig::fromType($collectorType); + return $this->collectors[] = CollectorConfig::fromType($collectorType); } /** @return array */ public function toArray(): array { - return ['name' => $this->name, 'collectors' => array_map(static fn (CollectorConfig $config) => $config->toArray(), $this->colloctors)]; + return ['name' => $this->name, 'collectors' => array_map(static fn (CollectorConfig $config) => $config->toArray(), $this->collectors)]; } public function __toString(): string From c12da139981db1371f2df3201e6cd00b3402be02 Mon Sep 17 00:00:00 2001 From: Gennadi McKelvey Date: Fri, 11 Nov 2022 16:25:57 +0100 Subject: [PATCH 22/39] wip --- deptrac.config.php | 134 ++++++++++-------- deptrac.config.yaml | 2 - deptrac.php | 6 +- src/Contract/Config/Collector/BoolConfig.php | 53 +++++++ .../Config/Collector/ClassNameConfig.php | 19 +++ .../Config/Collector/DirectoryConfig.php | 19 +++ src/Contract/Config/CollectorConfig.php | 52 +------ .../Config/ConfigurableCollectorConfig.php | 35 +++++ src/Contract/Config/DeptracConfig.php | 122 ++++++++++++++-- src/Contract/Config/Layer.php | 39 +++++ src/Contract/Config/LayerConfig.php | 34 ----- src/Contract/Config/RulesetConfig.php | 18 ++- 12 files changed, 371 insertions(+), 162 deletions(-) create mode 100644 src/Contract/Config/Collector/BoolConfig.php create mode 100644 src/Contract/Config/Collector/ClassNameConfig.php create mode 100644 src/Contract/Config/Collector/DirectoryConfig.php create mode 100644 src/Contract/Config/ConfigurableCollectorConfig.php create mode 100644 src/Contract/Config/Layer.php delete mode 100644 src/Contract/Config/LayerConfig.php diff --git a/deptrac.config.php b/deptrac.config.php index a808db659..74f8c310e 100755 --- a/deptrac.config.php +++ b/deptrac.config.php @@ -3,75 +3,85 @@ use Internal\Qossmic\Deptrac\IgnoreDependenciesOnContract; use Internal\Qossmic\Deptrac\IgnoreDependenciesOnShouldNotHappenException; 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\CollectorType; use Qossmic\Deptrac\Contract\Config\EmitterType; +use Qossmic\Deptrac\Contract\Config\Layer; +use Qossmic\Deptrac\Contract\Config\RulesetConfig; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; +use function Qossmic\Deptrac\Contract\Config\regex; + return static function (DeptracConfig $config, ContainerConfigurator $containerConfigurator): void { $services = $containerConfigurator->services(); $services->set(IgnoreDependenciesOnContract::class)->tag('kernel.event_listener', ['event' => ProcessEvent::class]); - $services->set(IgnoreDependenciesOnShouldNotHappenException::class)->tag('kernel.event_listener', ['event' => ProcessEvent::class]); - - $config->paths('src'); - //$config->baseline('deptrac.baseline.yaml'); - - // analyser - $config->analyser( - EmitterType::CLASS_TOKEN, - EmitterType::CLASS_SUPERGLOBAL_TOKEN, - EmitterType::FILE_TOKEN, - EmitterType::FUNCTION_TOKEN, - EmitterType::FUNCTION_SUPERGLOBAL_TOKEN, - EmitterType::FUNCTION_CALL, + $services->set(IgnoreDependenciesOnShouldNotHappenException::class)->tag( + 'kernel.event_listener', + ['event' => ProcessEvent::class] ); - // layer - $analyser = $config->layer('Analyser'); - $analyser->collector(CollectorType::TYPE_DIRECTORY)->value('src/Core/Analyser/.*'); - - $ast = $config->layer('Ast'); - $ast->collector(CollectorType::TYPE_DIRECTORY)->value('src/Core/Ast/.*'); - $ast->collector(CollectorType::TYPE_CLASS_NAME)->value('^PHPStan\\\\PhpDocParser\\\\.*')->private(); - $ast->collector(CollectorType::TYPE_CLASS_NAME)->value('^PhpParser\\\\.*')->private(); - $ast->collector(CollectorType::TYPE_CLASS_NAME)->value('^phpDocumentor\\\\Reflection\\\\.*')->private(); - - $console = $config->layer('Console'); - $console->collector(CollectorType::TYPE_DIRECTORY)->value('src/Supportive/Console/.*'); - - $dependency = $config->layer('Dependency'); - $dependency->collector(CollectorType::TYPE_DIRECTORY)->value('src/Core/Dependency/.*'); - - $dependencyInjection = $config->layer('DependencyInjection'); - $dependencyInjection->collector(CollectorType::TYPE_DIRECTORY)->value('src/Supportive/DependencyInjection/.*'); - - $contract = $config->layer('Contract'); - $contract->collector(CollectorType::TYPE_DIRECTORY)->value('src/Contract/.*'); - - $inputCollector = $config->layer('InputCollector'); - $inputCollector->collector(CollectorType::TYPE_DIRECTORY)->value('src/Core/InputCollector/.*'); - - $layer = $config->layer('Layer'); - $layer->collector(CollectorType::TYPE_DIRECTORY)->value('src/Core/Layer/.*'); - - $outputFormatter = $config->layer('OutputFormatter'); - $outputFormatter->collector(CollectorType::TYPE_DIRECTORY)->value('src/Supportive/OutputFormatter/.*'); - $outputFormatter->collector(CollectorType::TYPE_CLASS_NAME)->value('^phpDocumentor\\\\GraphViz\\\\.*')->private(); - - $file = $config->layer('File'); - $file->collector(CollectorType::TYPE_DIRECTORY)->value('src/Supportive/File/.*'); - - $supportive = $config->layer('Supportive'); - $supportiveCollector = $supportive->collector(CollectorType::TYPE_BOOL); - $supportiveCollector->mustNot(CollectorType::TYPE_DIRECTORY)->value('src/Supportive/.*/.*'); - $supportiveCollector->must(CollectorType::TYPE_DIRECTORY)->value('src/Supportive/.*'); - - // ruleset - $config->ruleset($layer)->accessesLayer($ast); - $config->ruleset($console)->accessesLayer($analyser, $outputFormatter, $dependencyInjection, $file); - $config->ruleset($dependency)->accessesLayer($ast); - $config->ruleset($analyser)->accessesLayer($layer, $dependency, $ast); - $config->ruleset($outputFormatter)->accessesLayer($console, $dependencyInjection); - $config->ruleset($ast)->accessesLayer($file, $inputCollector); - $config->ruleset($inputCollector)->accessesLayer($file); + $config + ->paths('src') + ->analyser( + 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::public('src/Core/Analyser/.*') + ), + $ast = Layer::withName('Ast')->collectors( + DirectoryConfig::public('src/Core/Ast/.*'), + ClassNameConfig::private(regex('^PHPStan\\PhpDocParser\\.*')), + ClassNameConfig::private(regex('^PhpParser\\.*')), + ClassNameConfig::private(regex('^phpDocumentor\\Reflection\\.*')) + ), + $console = Layer::withName('Console')->collectors( + DirectoryConfig::public('src/Supportive/Console/.*') + ), + $dependency = Layer::withName('Dependency')->collectors( + DirectoryConfig::public('src/Core/Dependency/.*') + ), + $dependencyInjection = Layer::withName('DependencyInjection')->collectors( + DirectoryConfig::public('src/Supportive/DependencyInjection/.*') + ), + $contract = Layer::withName('Contract')->collectors( + DirectoryConfig::public('src/Contract/.*') + ), + $inputCollector = Layer::withName('InputCollector')->collectors( + DirectoryConfig::public('src/Core/InputCollector/.*') + ), + $layer = Layer::withName('Layer')->collectors( + DirectoryConfig::public('src/Core/Layer/.*') + ), + $outputFormatter = Layer::withName('OutputFormatter')->collectors( + DirectoryConfig::public('src/Supportive/OutputFormatter/.*'), + ClassNameConfig::private(regex('^phpDocumentor\\\\GraphViz\\\\.*')), + ), + $file = Layer::withName('File')->collectors( + DirectoryConfig::public('src/Supportive/File/.*') + ), + $supportive = Layer::withName('Supportive')->collectors( + BoolConfig::public() + ->withMustNot(DirectoryConfig::public('src/Supportive/.*/.*')) + ->withMust(DirectoryConfig::public('src/Supportive/.*')) + ), + ) + ->rulesets( + RulesetConfig::layer($layer)->accesses($ast), + RulesetConfig::layer($console)->accesses($analyser, $outputFormatter, $dependencyInjection, $file), + RulesetConfig::layer($dependency)->accesses($ast), + RulesetConfig::layer($analyser)->accesses($layer, $dependency, $ast), + RulesetConfig::layer($outputFormatter)->accesses($console, $dependencyInjection), + RulesetConfig::layer($ast)->accesses($file, $inputCollector), + RulesetConfig::layer($inputCollector)->accesses($file), + RulesetConfig::layer($supportive), + RulesetConfig::layer($contract), + ); }; diff --git a/deptrac.config.yaml b/deptrac.config.yaml index 99691e1f9..94aeb094b 100644 --- a/deptrac.config.yaml +++ b/deptrac.config.yaml @@ -1,6 +1,4 @@ imports: - - deptrac.baseline.yaml - services: - class: Internal\Qossmic\Deptrac\IgnoreDependenciesOnContract tags: diff --git a/deptrac.php b/deptrac.php index 8e339eb01..e757330fc 100755 --- a/deptrac.php +++ b/deptrac.php @@ -20,8 +20,8 @@ } })(); -$xdebug = new XdebugHandler('DEPTRAC'); -$xdebug->check(); -unset($xdebug); +// $xdebug = new XdebugHandler('DEPTRAC'); +// $xdebug->check(); +// unset($xdebug); (new Application())->run(); diff --git a/src/Contract/Config/Collector/BoolConfig.php b/src/Contract/Config/Collector/BoolConfig.php new file mode 100644 index 000000000..e811fb81e --- /dev/null +++ b/src/Contract/Config/Collector/BoolConfig.php @@ -0,0 +1,53 @@ + */ + private array $mustNot = []; + + /** @var array */ + private array $must = []; + + public static function public(): self + { + return new self(collectorType: CollectorType::TYPE_BOOL, private: false); + } + + public static function private(): self + { + return new self(collectorType: CollectorType::TYPE_BOOL, private: true); + } + + public function withMustNot(CollectorConfig $CollectorConfig): self + { + $this->mustNot[] = $CollectorConfig; + + return $this; + } + + public function withMust(CollectorConfig $CollectorConfig): self + { + $this->must[] = $CollectorConfig; + + return $this; + } + + /** @return array{ + * must: array|mixed, + * must_not: array|mixed, + * private: bool, + * type: string} + */ + public function toArray(): array + { + return parent::toArray() + [ + 'must' => array_map(static fn (CollectorConfig $v) => $v->toArray(), $this->must), + 'must_not' => array_map(static fn (CollectorConfig $v) => $v->toArray(), $this->mustNot), + ]; + } +} diff --git a/src/Contract/Config/Collector/ClassNameConfig.php b/src/Contract/Config/Collector/ClassNameConfig.php new file mode 100644 index 000000000..50a52e37f --- /dev/null +++ b/src/Contract/Config/Collector/ClassNameConfig.php @@ -0,0 +1,19 @@ + */ - private array $mustNot = []; - /** @var array */ - private array $must = []; - - private function __construct( - private readonly CollectorType $collectorType + protected function __construct( + protected readonly CollectorType $collectorType = CollectorType::TYPE_BOOL, + protected readonly bool $private = false, ) { } - public static function fromType(CollectorType $collectorType): self - { - $new = new self($collectorType); - - return $new; - } - - public function value(string $value): self - { - $this->value = $value; - - return $this; - } - - public function mustNot(CollectorType $collectorType): CollectorConfig - { - return $this->mustNot[] = CollectorConfig::fromType($collectorType); - } - - public function must(CollectorType $collectorType): CollectorConfig - { - return $this->must[] = CollectorConfig::fromType($collectorType); - } - - public function private(): self - { - $this->private = true; - - return $this; - } - - /** @return array */ + /** + * @return array{'type': string, 'private': bool} + */ public function toArray(): array { return [ 'type' => $this->collectorType->value, - 'value' => $this->value, 'private' => $this->private, - 'must' => array_map(static fn (CollectorConfig $v) => $v->toArray(), $this->must), - 'must_not' => array_map(static fn (CollectorConfig $v) => $v->toArray(), $this->mustNot), ]; } } diff --git a/src/Contract/Config/ConfigurableCollectorConfig.php b/src/Contract/Config/ConfigurableCollectorConfig.php new file mode 100644 index 000000000..f79c67fbe --- /dev/null +++ b/src/Contract/Config/ConfigurableCollectorConfig.php @@ -0,0 +1,35 @@ + $this->config, + ]; + } +} diff --git a/src/Contract/Config/DeptracConfig.php b/src/Contract/Config/DeptracConfig.php index 2025759ae..a5f365582 100644 --- a/src/Contract/Config/DeptracConfig.php +++ b/src/Contract/Config/DeptracConfig.php @@ -14,13 +14,13 @@ final class DeptracConfig implements ConfigBuilderInterface /** @var array */ private array $paths = []; - /** @var array */ + /** @var array */ private array $layers = []; /** @var array */ private array $formatters = []; /** @var array */ private array $rulesets = []; - /** @var array */ + /** @var array */ private array $analyser = []; /** @var array> */ private array $skipViolations = []; @@ -40,7 +40,8 @@ public function baseline(string $baseline): self { /** @var array>> $baselineAsArray */ $baselineAsArray = Yaml::parseFile($baseline); - /** @var array */ + + /** @var array> $skipViolations */ $skipViolations = $baselineAsArray['deptrac']['skip_violations'] ?? []; foreach ($skipViolations as $class => $skipViolation) { @@ -52,19 +53,29 @@ public function baseline(string $baseline): self public function paths(string ...$paths): self { - $this->paths = $paths; + foreach ($paths as $path) { + $this->paths[] = $path; + } return $this; } - public function layer(string $name): LayerConfig + public function layers(Layer ...$layerConfigs): self { - return $this->layers[$name] = new LayerConfig($name); + foreach ($layerConfigs as $layerConfig) { + $this->layers[$layerConfig->name] = $layerConfig; + } + + return $this; } - public function ruleset(LayerConfig $layerConfig): RulesetConfig + public function rulesets(RulesetConfig ...$rulesetConfigs): self { - return $this->rulesets[] = new RulesetConfig($layerConfig); + foreach ($rulesetConfigs as $rulesetConfig) { + $this->rulesets[$rulesetConfig->layersConfig->name] = $rulesetConfig; + } + + return $this; } /** @return array */ @@ -81,7 +92,7 @@ public function toArray(): array } if ([] !== $this->layers) { - $config['layers'] = array_map(static fn (LayerConfig $layerConfig) => $layerConfig->toArray(), $this->layers); + $config['layers'] = array_map(static fn (Layer $layerConfig) => $layerConfig->toArray(), $this->layers); } if ([] !== $this->rulesets) { @@ -111,3 +122,96 @@ public function getExtensionAlias(): string return 'deptrac'; } } + +const ESCAPEES = [ + '\\', + '\\\\', + '\\"', + '"', + "\x00", + "\x01", + "\x02", + "\x03", + "\x04", + "\x05", + "\x06", + "\x07", + "\x08", + "\x09", + "\x0a", + "\x0b", + "\x0c", + "\x0d", + "\x0e", + "\x0f", + "\x10", + "\x11", + "\x12", + "\x13", + "\x14", + "\x15", + "\x16", + "\x17", + "\x18", + "\x19", + "\x1a", + "\x1b", + "\x1c", + "\x1d", + "\x1e", + "\x1f", + "\x7f", + "\xc2\x85", + "\xc2\xa0", + "\xe2\x80\xa8", + "\xe2\x80\xa9", +]; + +const ESCAPED = [ + '\\\\', + '\\"', + '\\\\', + '\\"', + '\\0', + '\\x01', + '\\x02', + '\\x03', + '\\x04', + '\\x05', + '\\x06', + '\\a', + '\\b', + '\\t', + '\\n', + '\\v', + '\\f', + '\\r', + '\\x0e', + '\\x0f', + '\\x10', + '\\x11', + '\\x12', + '\\x13', + '\\x14', + '\\x15', + '\\x16', + '\\x17', + '\\x18', + '\\x19', + '\\x1a', + '\\e', + '\\x1c', + '\\x1d', + '\\x1e', + '\\x1f', + '\\x7f', + '\\N', + '\\_', + '\\L', + '\\P', +]; + +function regex(string $regex): string +{ + return sprintf('%s', str_replace(ESCAPEES, ESCAPED, $regex)); +} diff --git a/src/Contract/Config/Layer.php b/src/Contract/Config/Layer.php new file mode 100644 index 000000000..8588dfe6b --- /dev/null +++ b/src/Contract/Config/Layer.php @@ -0,0 +1,39 @@ + */ + private array $collectors = []; + + private function __construct( + public readonly string $name + ) { + } + + public static function withName(string $name): self + { + return new self($name); + } + + public function collectors(CollectorConfig ...$collectorConfigs): self + { + foreach ($collectorConfigs as $collectorConfig) { + $this->collectors[] = $collectorConfig; + } + + return $this; + } + + /** @return array */ + public function toArray(): array + { + return [ + 'name' => $this->name, + 'collectors' => array_map(static fn (CollectorConfig $config) => $config->toArray(), $this->collectors), + ]; + } +} diff --git a/src/Contract/Config/LayerConfig.php b/src/Contract/Config/LayerConfig.php deleted file mode 100644 index b34857a51..000000000 --- a/src/Contract/Config/LayerConfig.php +++ /dev/null @@ -1,34 +0,0 @@ - */ - private array $collectors = []; - - public function __construct( - public readonly string $name - ) { - } - - public function collector(CollectorType $collectorType): CollectorConfig - { - return $this->collectors[] = CollectorConfig::fromType($collectorType); - } - - /** @return array */ - public function toArray(): array - { - return ['name' => $this->name, 'collectors' => array_map(static fn (CollectorConfig $config) => $config->toArray(), $this->collectors)]; - } - - public function __toString(): string - { - return $this->name; - } -} diff --git a/src/Contract/Config/RulesetConfig.php b/src/Contract/Config/RulesetConfig.php index 641de099e..00033b1bb 100644 --- a/src/Contract/Config/RulesetConfig.php +++ b/src/Contract/Config/RulesetConfig.php @@ -6,15 +6,20 @@ final class RulesetConfig { - /** @var array */ + /** @var array */ private array $accessableLayers = []; public function __construct( - private readonly LayerConfig $layersConfig + public readonly Layer $layersConfig ) { } - public function accessesLayer(LayerConfig ...$layersConfig): self + public static function layer(Layer $layerConfig): self + { + return new self($layerConfig); + } + + public function accesses(Layer ...$layersConfig): self { foreach ($layersConfig as $layerConfig) { $this->accessableLayers[] = $layerConfig; @@ -23,12 +28,11 @@ public function accessesLayer(LayerConfig ...$layersConfig): self return $this; } - /** @return array */ + /** @return non-empty-array */ public function toArray(): array { - /** @var array */ - $data = array_map(static fn (LayerConfig $layerConfig) => $layerConfig->__toString(), $this->accessableLayers); + $data = array_map(static fn (Layer $layerConfig) => $layerConfig->name, $this->accessableLayers); - return $data + ['name' => $this->layersConfig->__toString()]; + return $data + ['name' => $this->layersConfig->name]; } } From e96a10015bfe1d67c02090cf41cdf7661feb6cd5 Mon Sep 17 00:00:00 2001 From: Gennadi McKelvey Date: Fri, 18 Nov 2022 16:03:57 +0100 Subject: [PATCH 23/39] implement graphviz fromatterconfig --- .../Formatters/Codeclimate/SeverityConfig.php | 98 +++++++++++++++++++ .../Deptrac/Formatters/CodeclimateConfig.php | 56 +++++++++++ .../Deptrac/Formatters/GraphvizConfig.php | 97 ++++++++++++++++++ Symfony/Config/Deptrac/FormattersConfig.php | 91 +++++++++++++++++ deptrac.config.php | 16 ++- src/Contract/Config/DeptracConfig.php | 17 +++- .../Formatter/FormatterConfigInterface.php | 12 +++ .../Config/Formatter/GraphvizConfig.php | 78 +++++++++++++++ src/Contract/Config/FormatterConfig.php | 15 --- 9 files changed, 458 insertions(+), 22 deletions(-) create mode 100644 Symfony/Config/Deptrac/Formatters/Codeclimate/SeverityConfig.php create mode 100644 Symfony/Config/Deptrac/Formatters/CodeclimateConfig.php create mode 100644 Symfony/Config/Deptrac/Formatters/GraphvizConfig.php create mode 100644 Symfony/Config/Deptrac/FormattersConfig.php create mode 100644 src/Contract/Config/Formatter/FormatterConfigInterface.php create mode 100644 src/Contract/Config/Formatter/GraphvizConfig.php delete mode 100644 src/Contract/Config/FormatterConfig.php diff --git a/Symfony/Config/Deptrac/Formatters/Codeclimate/SeverityConfig.php b/Symfony/Config/Deptrac/Formatters/Codeclimate/SeverityConfig.php new file mode 100644 index 000000000..013c326f2 --- /dev/null +++ b/Symfony/Config/Deptrac/Formatters/Codeclimate/SeverityConfig.php @@ -0,0 +1,98 @@ +_usedProperties['failure'] = true; + $this->failure = $value; + + return $this; + } + + /** + * @default 'minor' + * @param ParamConfigurator|'info'|'minor'|'major'|'critical'|'blocker' $value + * @return $this + */ + public function skipped($value): static + { + $this->_usedProperties['skipped'] = true; + $this->skipped = $value; + + return $this; + } + + /** + * @default 'info' + * @param ParamConfigurator|'info'|'minor'|'major'|'critical'|'blocker' $value + * @return $this + */ + public function uncovered($value): static + { + $this->_usedProperties['uncovered'] = true; + $this->uncovered = $value; + + return $this; + } + + public function __construct(array $value = []) + { + if (array_key_exists('failure', $value)) { + $this->_usedProperties['failure'] = true; + $this->failure = $value['failure']; + unset($value['failure']); + } + + if (array_key_exists('skipped', $value)) { + $this->_usedProperties['skipped'] = true; + $this->skipped = $value['skipped']; + unset($value['skipped']); + } + + if (array_key_exists('uncovered', $value)) { + $this->_usedProperties['uncovered'] = true; + $this->uncovered = $value['uncovered']; + unset($value['uncovered']); + } + + if ([] !== $value) { + throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); + } + } + + public function toArray(): array + { + $output = []; + if (isset($this->_usedProperties['failure'])) { + $output['failure'] = $this->failure; + } + if (isset($this->_usedProperties['skipped'])) { + $output['skipped'] = $this->skipped; + } + if (isset($this->_usedProperties['uncovered'])) { + $output['uncovered'] = $this->uncovered; + } + + return $output; + } + +} diff --git a/Symfony/Config/Deptrac/Formatters/CodeclimateConfig.php b/Symfony/Config/Deptrac/Formatters/CodeclimateConfig.php new file mode 100644 index 000000000..9128e6cc0 --- /dev/null +++ b/Symfony/Config/Deptrac/Formatters/CodeclimateConfig.php @@ -0,0 +1,56 @@ +severity) { + $this->_usedProperties['severity'] = true; + $this->severity = new \Symfony\Config\Deptrac\Formatters\Codeclimate\SeverityConfig($value); + } elseif (0 < \func_num_args()) { + throw new InvalidConfigurationException('The node created by "severity()" has already been initialized. You cannot pass values the second time you call severity().'); + } + + return $this->severity; + } + + public function __construct(array $value = []) + { + if (array_key_exists('severity', $value)) { + $this->_usedProperties['severity'] = true; + $this->severity = new \Symfony\Config\Deptrac\Formatters\Codeclimate\SeverityConfig($value['severity']); + unset($value['severity']); + } + + if ([] !== $value) { + throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); + } + } + + public function toArray(): array + { + $output = []; + if (isset($this->_usedProperties['severity'])) { + $output['severity'] = $this->severity->toArray(); + } + + return $output; + } + +} diff --git a/Symfony/Config/Deptrac/Formatters/GraphvizConfig.php b/Symfony/Config/Deptrac/Formatters/GraphvizConfig.php new file mode 100644 index 000000000..a27ed1bf1 --- /dev/null +++ b/Symfony/Config/Deptrac/Formatters/GraphvizConfig.php @@ -0,0 +1,97 @@ + $value + * + * @return $this + */ + public function hiddenLayers(ParamConfigurator|array $value): static + { + $this->_usedProperties['hiddenLayers'] = true; + $this->hiddenLayers = $value; + + return $this; + } + + /** + * @return $this + */ + public function groups(string $name, ParamConfigurator|array $value): static + { + $this->_usedProperties['groups'] = true; + $this->groups[$name] = $value; + + return $this; + } + + /** + * When a layer is part of a group, should edges point towards the group or the layer? + * @default false + * @param ParamConfigurator|bool $value + * @return $this + */ + public function pointToGroups($value): static + { + $this->_usedProperties['pointToGroups'] = true; + $this->pointToGroups = $value; + + return $this; + } + + public function __construct(array $value = []) + { + if (array_key_exists('hidden_layers', $value)) { + $this->_usedProperties['hiddenLayers'] = true; + $this->hiddenLayers = $value['hidden_layers']; + unset($value['hidden_layers']); + } + + if (array_key_exists('groups', $value)) { + $this->_usedProperties['groups'] = true; + $this->groups = $value['groups']; + unset($value['groups']); + } + + if (array_key_exists('point_to_groups', $value)) { + $this->_usedProperties['pointToGroups'] = true; + $this->pointToGroups = $value['point_to_groups']; + unset($value['point_to_groups']); + } + + if ([] !== $value) { + throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); + } + } + + public function toArray(): array + { + $output = []; + if (isset($this->_usedProperties['hiddenLayers'])) { + $output['hidden_layers'] = $this->hiddenLayers; + } + if (isset($this->_usedProperties['groups'])) { + $output['groups'] = $this->groups; + } + if (isset($this->_usedProperties['pointToGroups'])) { + $output['point_to_groups'] = $this->pointToGroups; + } + + return $output; + } + +} diff --git a/Symfony/Config/Deptrac/FormattersConfig.php b/Symfony/Config/Deptrac/FormattersConfig.php new file mode 100644 index 000000000..5a4277375 --- /dev/null +++ b/Symfony/Config/Deptrac/FormattersConfig.php @@ -0,0 +1,91 @@ +_usedProperties['graphviz'] = true; + $this->graphviz = $value; + + return $this; + } + + if (!$this->graphviz instanceof \Symfony\Config\Deptrac\Formatters\GraphvizConfig) { + $this->_usedProperties['graphviz'] = true; + $this->graphviz = new \Symfony\Config\Deptrac\Formatters\GraphvizConfig($value); + } elseif (0 < \func_num_args()) { + throw new InvalidConfigurationException('The node created by "graphviz()" has already been initialized. You cannot pass values the second time you call graphviz().'); + } + + return $this->graphviz; + } + + /** + * Configure Codeclimate output formatters + * @default {"severity":{"failure":"major","skipped":"minor","uncovered":"info"}} + */ + public function codeclimate(array $value = []): \Symfony\Config\Deptrac\Formatters\CodeclimateConfig + { + if (null === $this->codeclimate) { + $this->_usedProperties['codeclimate'] = true; + $this->codeclimate = new \Symfony\Config\Deptrac\Formatters\CodeclimateConfig($value); + } elseif (0 < \func_num_args()) { + throw new InvalidConfigurationException('The node created by "codeclimate()" has already been initialized. You cannot pass values the second time you call codeclimate().'); + } + + return $this->codeclimate; + } + + public function __construct(array $value = []) + { + if (array_key_exists('graphviz', $value)) { + $this->_usedProperties['graphviz'] = true; + $this->graphviz = \is_array($value['graphviz']) ? new \Symfony\Config\Deptrac\Formatters\GraphvizConfig($value['graphviz']) : $value['graphviz']; + unset($value['graphviz']); + } + + if (array_key_exists('codeclimate', $value)) { + $this->_usedProperties['codeclimate'] = true; + $this->codeclimate = new \Symfony\Config\Deptrac\Formatters\CodeclimateConfig($value['codeclimate']); + unset($value['codeclimate']); + } + + if ([] !== $value) { + throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); + } + } + + public function toArray(): array + { + $output = []; + if (isset($this->_usedProperties['graphviz'])) { + $output['graphviz'] = $this->graphviz instanceof \Symfony\Config\Deptrac\Formatters\GraphvizConfig ? $this->graphviz->toArray() : $this->graphviz; + } + if (isset($this->_usedProperties['codeclimate'])) { + $output['codeclimate'] = $this->codeclimate->toArray(); + } + + return $output; + } + +} diff --git a/deptrac.config.php b/deptrac.config.php index 74f8c310e..5b5f5ced4 100755 --- a/deptrac.config.php +++ b/deptrac.config.php @@ -8,10 +8,10 @@ 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\RulesetConfig; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; - use function Qossmic\Deptrac\Contract\Config\regex; return static function (DeptracConfig $config, ContainerConfigurator $containerConfigurator): void { @@ -24,7 +24,7 @@ $config ->paths('src') - ->analyser( + ->analysers( EmitterType::CLASS_TOKEN, EmitterType::CLASS_SUPERGLOBAL_TOKEN, EmitterType::FILE_TOKEN, @@ -81,7 +81,15 @@ RulesetConfig::layer($outputFormatter)->accesses($console, $dependencyInjection), RulesetConfig::layer($ast)->accesses($file, $inputCollector), RulesetConfig::layer($inputCollector)->accesses($file), - RulesetConfig::layer($supportive), + RulesetConfig::layer($supportive)->accesses($file), RulesetConfig::layer($contract), - ); + ) + ->formatters( + GraphvizConfig::create() + ->groups('Contract', $contract) + ->groups('Supportive', $supportive, $file) + ->groups('Symfony', $console, $dependencyInjection, $outputFormatter) + ->groups('Core', $analyser, $ast, $dependency, $inputCollector, $layer) + ) + ; }; diff --git a/src/Contract/Config/DeptracConfig.php b/src/Contract/Config/DeptracConfig.php index a5f365582..1ff47572e 100644 --- a/src/Contract/Config/DeptracConfig.php +++ b/src/Contract/Config/DeptracConfig.php @@ -4,6 +4,8 @@ namespace Qossmic\Deptrac\Contract\Config; +use Qossmic\Deptrac\Contract\Config\Formatter\FormatterConfigInterface; +use Qossmic\Deptrac\Contract\Config\Formatter\FormatterInterface; use Symfony\Component\Config\Builder\ConfigBuilderInterface; use Symfony\Component\Yaml\Yaml; @@ -16,7 +18,7 @@ final class DeptracConfig implements ConfigBuilderInterface private array $paths = []; /** @var array */ private array $layers = []; - /** @var array */ + /** @var array */ private array $formatters = []; /** @var array */ private array $rulesets = []; @@ -27,7 +29,7 @@ final class DeptracConfig implements ConfigBuilderInterface /** @var array */ private array $excludeFiles = []; - public function analyser(EmitterType ...$types): self + public function analysers(EmitterType ...$types): self { foreach ($types as $type) { $this->analyser[$type->value] = $type; @@ -51,6 +53,15 @@ public function baseline(string $baseline): self return $this; } + public function formatters(FormatterConfigInterface ...$formatters): self + { + foreach ($formatters as $formatter) { + $this->formatters[$formatter->getName()] = $formatter; + } + + return $this; + } + public function paths(string ...$paths): self { foreach ($paths as $path) { @@ -104,7 +115,7 @@ public function toArray(): array } if ([] !== $this->formatters) { - $config['formatters'] = array_map(static fn (FormatterConfig $formatterConfig) => $formatterConfig->__toString(), $this->formatters); + $config['formatters'] = array_map(static fn (FormatterConfigInterface $formatterConfig) => $formatterConfig->toArray(), $this->formatters); } if ([] !== $this->skipViolations) { diff --git a/src/Contract/Config/Formatter/FormatterConfigInterface.php b/src/Contract/Config/Formatter/FormatterConfigInterface.php new file mode 100644 index 000000000..c08dc3ea2 --- /dev/null +++ b/src/Contract/Config/Formatter/FormatterConfigInterface.php @@ -0,0 +1,12 @@ + */ + private array $groups = []; + + private function __construct() + { + } + + public static function create(): self + { + return new self(); + } + + public function pointsToGroup(bool $pointsToGroup = true): self + { + $this->pointsToGroup = $pointsToGroup; + + return $this; + } + + public function hiddenLayers(Layer ...$LayerConfigs): self + { + foreach ($LayerConfigs as $layerConfig) { + $this->hiddenLayers[] = $layerConfig; + } + + return $this; + } + + public function groups(string $name, Layer ...$layerConfigs): self + { + foreach ($layerConfigs as $layerConfig) { + $this->groups[$name][] = $layerConfig; + } + + return $this; + } + + public function toArray(): array + { + $output = []; + + if ([] !== $this->hiddenLayers) { + $output['hidden_layers'] = array_map(static fn (Layer $config) => $config->name, $this->hiddenLayers); + } + + if ([] !== $this->groups) { + $output['groups'] = array_map( + static fn (array $configs) => array_map(static fn (Layer $layer) => $layer->name, $configs), + $this->groups + ); + } + + $output['point_to_groups'] = $this->pointsToGroup; + + return $output; + } + + public function getName(): string + { + return $this->name; + } +} diff --git a/src/Contract/Config/FormatterConfig.php b/src/Contract/Config/FormatterConfig.php deleted file mode 100644 index 871bdf91f..000000000 --- a/src/Contract/Config/FormatterConfig.php +++ /dev/null @@ -1,15 +0,0 @@ - Date: Sat, 19 Nov 2022 22:01:12 +0100 Subject: [PATCH 24/39] only set private if true --- deptrac.config.php | 3 ++- src/Contract/Config/Collector/BoolConfig.php | 2 +- src/Contract/Config/CollectorConfig.php | 2 +- src/Contract/Config/DeptracConfig.php | 19 +++++++++---------- .../Formatter/FormatterConfigInterface.php | 1 + 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/deptrac.config.php b/deptrac.config.php index 5b5f5ced4..9f4bf09d8 100755 --- a/deptrac.config.php +++ b/deptrac.config.php @@ -62,7 +62,7 @@ ), $outputFormatter = Layer::withName('OutputFormatter')->collectors( DirectoryConfig::public('src/Supportive/OutputFormatter/.*'), - ClassNameConfig::private(regex('^phpDocumentor\\\\GraphViz\\\\.*')), + ClassNameConfig::private(regex('^phpDocumentor\\GraphViz\\.*')), ), $file = Layer::withName('File')->collectors( DirectoryConfig::public('src/Supportive/File/.*') @@ -86,6 +86,7 @@ ) ->formatters( GraphvizConfig::create() + ->pointsToGroup(true) ->groups('Contract', $contract) ->groups('Supportive', $supportive, $file) ->groups('Symfony', $console, $dependencyInjection, $outputFormatter) diff --git a/src/Contract/Config/Collector/BoolConfig.php b/src/Contract/Config/Collector/BoolConfig.php index e811fb81e..a385af1bc 100644 --- a/src/Contract/Config/Collector/BoolConfig.php +++ b/src/Contract/Config/Collector/BoolConfig.php @@ -46,8 +46,8 @@ public function withMust(CollectorConfig $CollectorConfig): self public function toArray(): array { return parent::toArray() + [ - 'must' => array_map(static fn (CollectorConfig $v) => $v->toArray(), $this->must), 'must_not' => array_map(static fn (CollectorConfig $v) => $v->toArray(), $this->mustNot), + 'must' => array_map(static fn (CollectorConfig $v) => $v->toArray(), $this->must), ]; } } diff --git a/src/Contract/Config/CollectorConfig.php b/src/Contract/Config/CollectorConfig.php index 28c61a0fe..9be692425 100644 --- a/src/Contract/Config/CollectorConfig.php +++ b/src/Contract/Config/CollectorConfig.php @@ -18,8 +18,8 @@ protected function __construct( public function toArray(): array { return [ - 'type' => $this->collectorType->value, 'private' => $this->private, + 'type' => $this->collectorType->value, ]; } } diff --git a/src/Contract/Config/DeptracConfig.php b/src/Contract/Config/DeptracConfig.php index 1ff47572e..123d90a85 100644 --- a/src/Contract/Config/DeptracConfig.php +++ b/src/Contract/Config/DeptracConfig.php @@ -5,7 +5,6 @@ namespace Qossmic\Deptrac\Contract\Config; use Qossmic\Deptrac\Contract\Config\Formatter\FormatterConfigInterface; -use Qossmic\Deptrac\Contract\Config\Formatter\FormatterInterface; use Symfony\Component\Config\Builder\ConfigBuilderInterface; use Symfony\Component\Yaml\Yaml; @@ -18,7 +17,7 @@ final class DeptracConfig implements ConfigBuilderInterface private array $paths = []; /** @var array */ private array $layers = []; - /** @var array */ + /** @var array */ private array $formatters = []; /** @var array */ private array $rulesets = []; @@ -98,6 +97,14 @@ public function toArray(): array $config['paths'] = $this->paths; } + if ([] !== $this->analyser) { + $config['analyser']['types'] = array_map(static fn (EmitterType $emitterType) => $emitterType->value, $this->analyser); + } + + if ([] !== $this->formatters) { + $config['formatters'] = array_map(static fn (FormatterConfigInterface $formatterConfig) => $formatterConfig->toArray(), $this->formatters); + } + if ([] !== $this->excludeFiles) { $config['exclude_files'] = $this->excludeFiles; } @@ -114,14 +121,6 @@ public function toArray(): array $config['skip_violations'] = $this->skipViolations; } - if ([] !== $this->formatters) { - $config['formatters'] = array_map(static fn (FormatterConfigInterface $formatterConfig) => $formatterConfig->toArray(), $this->formatters); - } - - if ([] !== $this->skipViolations) { - $config['analyser']['types'] = array_map(static fn (EmitterType $emitterType) => $emitterType->value, $this->analyser); - } - $config['ignore_uncovered_internal_classes'] = $this->ignoreUncoveredInternalClasses; $config['use_relative_path_from_depfile'] = $this->useRelativePathFromDepfile; diff --git a/src/Contract/Config/Formatter/FormatterConfigInterface.php b/src/Contract/Config/Formatter/FormatterConfigInterface.php index c08dc3ea2..7a5c6e7f8 100644 --- a/src/Contract/Config/Formatter/FormatterConfigInterface.php +++ b/src/Contract/Config/Formatter/FormatterConfigInterface.php @@ -8,5 +8,6 @@ interface FormatterConfigInterface { public function getName(): string; + /** @return array */ public function toArray(): array; } From ea4b4884f8985cf6bdeaf5e785228468d8f51d0f Mon Sep 17 00:00:00 2001 From: Gennadi McKelvey Date: Sat, 19 Nov 2022 22:13:21 +0100 Subject: [PATCH 25/39] use deptrac.config.php as default make command --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 23f30b208..9dcc4743e 100644 --- a/Makefile +++ b/Makefile @@ -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) From bab7b9be68e57974c1024a65f797ff09c0677d51 Mon Sep 17 00:00:00 2001 From: Gennadi McKelvey Date: Sun, 20 Nov 2022 13:32:58 +0100 Subject: [PATCH 26/39] implement codeclimateconfig --- .../Formatters/Codeclimate/SeverityConfig.php | 98 ------------------- .../Deptrac/Formatters/CodeclimateConfig.php | 56 ----------- .../Deptrac/Formatters/GraphvizConfig.php | 97 ------------------ Symfony/Config/Deptrac/FormattersConfig.php | 91 ----------------- src/Contract/Config/CodeclimateLevelEnum.php | 12 +++ .../Config/Formatter/CodeclimateConfig.php | 52 ++++++++++ 6 files changed, 64 insertions(+), 342 deletions(-) delete mode 100644 Symfony/Config/Deptrac/Formatters/Codeclimate/SeverityConfig.php delete mode 100644 Symfony/Config/Deptrac/Formatters/CodeclimateConfig.php delete mode 100644 Symfony/Config/Deptrac/Formatters/GraphvizConfig.php delete mode 100644 Symfony/Config/Deptrac/FormattersConfig.php create mode 100644 src/Contract/Config/CodeclimateLevelEnum.php create mode 100644 src/Contract/Config/Formatter/CodeclimateConfig.php diff --git a/Symfony/Config/Deptrac/Formatters/Codeclimate/SeverityConfig.php b/Symfony/Config/Deptrac/Formatters/Codeclimate/SeverityConfig.php deleted file mode 100644 index 013c326f2..000000000 --- a/Symfony/Config/Deptrac/Formatters/Codeclimate/SeverityConfig.php +++ /dev/null @@ -1,98 +0,0 @@ -_usedProperties['failure'] = true; - $this->failure = $value; - - return $this; - } - - /** - * @default 'minor' - * @param ParamConfigurator|'info'|'minor'|'major'|'critical'|'blocker' $value - * @return $this - */ - public function skipped($value): static - { - $this->_usedProperties['skipped'] = true; - $this->skipped = $value; - - return $this; - } - - /** - * @default 'info' - * @param ParamConfigurator|'info'|'minor'|'major'|'critical'|'blocker' $value - * @return $this - */ - public function uncovered($value): static - { - $this->_usedProperties['uncovered'] = true; - $this->uncovered = $value; - - return $this; - } - - public function __construct(array $value = []) - { - if (array_key_exists('failure', $value)) { - $this->_usedProperties['failure'] = true; - $this->failure = $value['failure']; - unset($value['failure']); - } - - if (array_key_exists('skipped', $value)) { - $this->_usedProperties['skipped'] = true; - $this->skipped = $value['skipped']; - unset($value['skipped']); - } - - if (array_key_exists('uncovered', $value)) { - $this->_usedProperties['uncovered'] = true; - $this->uncovered = $value['uncovered']; - unset($value['uncovered']); - } - - if ([] !== $value) { - throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); - } - } - - public function toArray(): array - { - $output = []; - if (isset($this->_usedProperties['failure'])) { - $output['failure'] = $this->failure; - } - if (isset($this->_usedProperties['skipped'])) { - $output['skipped'] = $this->skipped; - } - if (isset($this->_usedProperties['uncovered'])) { - $output['uncovered'] = $this->uncovered; - } - - return $output; - } - -} diff --git a/Symfony/Config/Deptrac/Formatters/CodeclimateConfig.php b/Symfony/Config/Deptrac/Formatters/CodeclimateConfig.php deleted file mode 100644 index 9128e6cc0..000000000 --- a/Symfony/Config/Deptrac/Formatters/CodeclimateConfig.php +++ /dev/null @@ -1,56 +0,0 @@ -severity) { - $this->_usedProperties['severity'] = true; - $this->severity = new \Symfony\Config\Deptrac\Formatters\Codeclimate\SeverityConfig($value); - } elseif (0 < \func_num_args()) { - throw new InvalidConfigurationException('The node created by "severity()" has already been initialized. You cannot pass values the second time you call severity().'); - } - - return $this->severity; - } - - public function __construct(array $value = []) - { - if (array_key_exists('severity', $value)) { - $this->_usedProperties['severity'] = true; - $this->severity = new \Symfony\Config\Deptrac\Formatters\Codeclimate\SeverityConfig($value['severity']); - unset($value['severity']); - } - - if ([] !== $value) { - throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); - } - } - - public function toArray(): array - { - $output = []; - if (isset($this->_usedProperties['severity'])) { - $output['severity'] = $this->severity->toArray(); - } - - return $output; - } - -} diff --git a/Symfony/Config/Deptrac/Formatters/GraphvizConfig.php b/Symfony/Config/Deptrac/Formatters/GraphvizConfig.php deleted file mode 100644 index a27ed1bf1..000000000 --- a/Symfony/Config/Deptrac/Formatters/GraphvizConfig.php +++ /dev/null @@ -1,97 +0,0 @@ - $value - * - * @return $this - */ - public function hiddenLayers(ParamConfigurator|array $value): static - { - $this->_usedProperties['hiddenLayers'] = true; - $this->hiddenLayers = $value; - - return $this; - } - - /** - * @return $this - */ - public function groups(string $name, ParamConfigurator|array $value): static - { - $this->_usedProperties['groups'] = true; - $this->groups[$name] = $value; - - return $this; - } - - /** - * When a layer is part of a group, should edges point towards the group or the layer? - * @default false - * @param ParamConfigurator|bool $value - * @return $this - */ - public function pointToGroups($value): static - { - $this->_usedProperties['pointToGroups'] = true; - $this->pointToGroups = $value; - - return $this; - } - - public function __construct(array $value = []) - { - if (array_key_exists('hidden_layers', $value)) { - $this->_usedProperties['hiddenLayers'] = true; - $this->hiddenLayers = $value['hidden_layers']; - unset($value['hidden_layers']); - } - - if (array_key_exists('groups', $value)) { - $this->_usedProperties['groups'] = true; - $this->groups = $value['groups']; - unset($value['groups']); - } - - if (array_key_exists('point_to_groups', $value)) { - $this->_usedProperties['pointToGroups'] = true; - $this->pointToGroups = $value['point_to_groups']; - unset($value['point_to_groups']); - } - - if ([] !== $value) { - throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); - } - } - - public function toArray(): array - { - $output = []; - if (isset($this->_usedProperties['hiddenLayers'])) { - $output['hidden_layers'] = $this->hiddenLayers; - } - if (isset($this->_usedProperties['groups'])) { - $output['groups'] = $this->groups; - } - if (isset($this->_usedProperties['pointToGroups'])) { - $output['point_to_groups'] = $this->pointToGroups; - } - - return $output; - } - -} diff --git a/Symfony/Config/Deptrac/FormattersConfig.php b/Symfony/Config/Deptrac/FormattersConfig.php deleted file mode 100644 index 5a4277375..000000000 --- a/Symfony/Config/Deptrac/FormattersConfig.php +++ /dev/null @@ -1,91 +0,0 @@ -_usedProperties['graphviz'] = true; - $this->graphviz = $value; - - return $this; - } - - if (!$this->graphviz instanceof \Symfony\Config\Deptrac\Formatters\GraphvizConfig) { - $this->_usedProperties['graphviz'] = true; - $this->graphviz = new \Symfony\Config\Deptrac\Formatters\GraphvizConfig($value); - } elseif (0 < \func_num_args()) { - throw new InvalidConfigurationException('The node created by "graphviz()" has already been initialized. You cannot pass values the second time you call graphviz().'); - } - - return $this->graphviz; - } - - /** - * Configure Codeclimate output formatters - * @default {"severity":{"failure":"major","skipped":"minor","uncovered":"info"}} - */ - public function codeclimate(array $value = []): \Symfony\Config\Deptrac\Formatters\CodeclimateConfig - { - if (null === $this->codeclimate) { - $this->_usedProperties['codeclimate'] = true; - $this->codeclimate = new \Symfony\Config\Deptrac\Formatters\CodeclimateConfig($value); - } elseif (0 < \func_num_args()) { - throw new InvalidConfigurationException('The node created by "codeclimate()" has already been initialized. You cannot pass values the second time you call codeclimate().'); - } - - return $this->codeclimate; - } - - public function __construct(array $value = []) - { - if (array_key_exists('graphviz', $value)) { - $this->_usedProperties['graphviz'] = true; - $this->graphviz = \is_array($value['graphviz']) ? new \Symfony\Config\Deptrac\Formatters\GraphvizConfig($value['graphviz']) : $value['graphviz']; - unset($value['graphviz']); - } - - if (array_key_exists('codeclimate', $value)) { - $this->_usedProperties['codeclimate'] = true; - $this->codeclimate = new \Symfony\Config\Deptrac\Formatters\CodeclimateConfig($value['codeclimate']); - unset($value['codeclimate']); - } - - if ([] !== $value) { - throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); - } - } - - public function toArray(): array - { - $output = []; - if (isset($this->_usedProperties['graphviz'])) { - $output['graphviz'] = $this->graphviz instanceof \Symfony\Config\Deptrac\Formatters\GraphvizConfig ? $this->graphviz->toArray() : $this->graphviz; - } - if (isset($this->_usedProperties['codeclimate'])) { - $output['codeclimate'] = $this->codeclimate->toArray(); - } - - return $output; - } - -} diff --git a/src/Contract/Config/CodeclimateLevelEnum.php b/src/Contract/Config/CodeclimateLevelEnum.php new file mode 100644 index 000000000..d5f007285 --- /dev/null +++ b/src/Contract/Config/CodeclimateLevelEnum.php @@ -0,0 +1,12 @@ +failure = $failure; + $this->skipped = $skipped; + $this->uncovered = $uncovered; + + return $this; + } + + /** + * @return array{'severity': array{'failure': string, 'skipped': string, 'uncovered': string}} + */ + public function toArray(): array + { + return ['severity' => [ + 'failure' => $this->failure->value, + 'skipped' => $this->skipped->value, + 'uncovered' => $this->uncovered->value, + ]]; + } + + public function getName(): string + { + return 'codeclimate'; + } +} From 7165fe7d9844c0edbbc88873b081de0d401190c6 Mon Sep 17 00:00:00 2001 From: Gennadi McKelvey Date: Sun, 20 Nov 2022 16:23:50 +0100 Subject: [PATCH 27/39] add all other CollectorConfigs --- .../Config/Collector/AttributeConfig.php | 19 +++++++++ src/Contract/Config/Collector/ClassConfig.php | 19 +++++++++ .../Config/Collector/ClassLikeConfig.php | 19 +++++++++ .../Config/Collector/ExtendsConfig.php | 19 +++++++++ .../Config/Collector/FunctionNameConfig.php | 19 +++++++++ src/Contract/Config/Collector/GlobConfig.php | 19 +++++++++ .../Config/Collector/ImplementsConfig.php | 19 +++++++++ .../Config/Collector/InheritsConfig.php | 19 +++++++++ .../Config/Collector/InterfaceConfig.php | 19 +++++++++ src/Contract/Config/Collector/LayerConfig.php | 19 +++++++++ .../Config/Collector/MethodConfig.php | 19 +++++++++ .../Config/Collector/PhpInteralConfig.php | 19 +++++++++ .../Config/Collector/SuperGlobalConfig.php | 40 +++++++++++++++++++ src/Contract/Config/Collector/TraitConfig.php | 19 +++++++++ src/Contract/Config/Collector/UsesConfig.php | 19 +++++++++ 15 files changed, 306 insertions(+) create mode 100644 src/Contract/Config/Collector/AttributeConfig.php create mode 100644 src/Contract/Config/Collector/ClassConfig.php create mode 100644 src/Contract/Config/Collector/ClassLikeConfig.php create mode 100644 src/Contract/Config/Collector/ExtendsConfig.php create mode 100644 src/Contract/Config/Collector/FunctionNameConfig.php create mode 100644 src/Contract/Config/Collector/GlobConfig.php create mode 100644 src/Contract/Config/Collector/ImplementsConfig.php create mode 100644 src/Contract/Config/Collector/InheritsConfig.php create mode 100644 src/Contract/Config/Collector/InterfaceConfig.php create mode 100644 src/Contract/Config/Collector/LayerConfig.php create mode 100644 src/Contract/Config/Collector/MethodConfig.php create mode 100644 src/Contract/Config/Collector/PhpInteralConfig.php create mode 100644 src/Contract/Config/Collector/SuperGlobalConfig.php create mode 100644 src/Contract/Config/Collector/TraitConfig.php create mode 100644 src/Contract/Config/Collector/UsesConfig.php diff --git a/src/Contract/Config/Collector/AttributeConfig.php b/src/Contract/Config/Collector/AttributeConfig.php new file mode 100644 index 000000000..256b1ba3e --- /dev/null +++ b/src/Contract/Config/Collector/AttributeConfig.php @@ -0,0 +1,19 @@ + $this->private, + 'type' => CollectorType::TYPE_SUPERGLOBAL->value, + 'value' => $this->config, + ]; + } +} diff --git a/src/Contract/Config/Collector/TraitConfig.php b/src/Contract/Config/Collector/TraitConfig.php new file mode 100644 index 000000000..9194115f0 --- /dev/null +++ b/src/Contract/Config/Collector/TraitConfig.php @@ -0,0 +1,19 @@ + Date: Fri, 25 Nov 2022 16:08:26 +0100 Subject: [PATCH 28/39] add excludeFiles --- src/Contract/Config/DeptracConfig.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Contract/Config/DeptracConfig.php b/src/Contract/Config/DeptracConfig.php index 123d90a85..597d4596e 100644 --- a/src/Contract/Config/DeptracConfig.php +++ b/src/Contract/Config/DeptracConfig.php @@ -70,6 +70,15 @@ public function paths(string ...$paths): self return $this; } + public function excludeFiles(string ...$excludeFiles): self + { + foreach ($excludeFiles as $excludeFile) { + $this->excludeFiles[] = $excludeFile; + } + + return $this; + } + public function layers(Layer ...$layerConfigs): self { foreach ($layerConfigs as $layerConfig) { From 3746ec9fb1591ea5adaa763057b03c8fdea132ba Mon Sep 17 00:00:00 2001 From: Gennadi McKelvey Date: Sun, 27 Nov 2022 15:03:38 +0100 Subject: [PATCH 29/39] remove readonly --- src/Contract/Config/Collector/SuperGlobalConfig.php | 4 ++-- src/Contract/Config/CollectorConfig.php | 4 ++-- src/Contract/Config/ConfigurableCollectorConfig.php | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Contract/Config/Collector/SuperGlobalConfig.php b/src/Contract/Config/Collector/SuperGlobalConfig.php index 74734ba06..92b32e1b0 100644 --- a/src/Contract/Config/Collector/SuperGlobalConfig.php +++ b/src/Contract/Config/Collector/SuperGlobalConfig.php @@ -11,8 +11,8 @@ final class SuperGlobalConfig extends CollectorConfig * @param string[] $config */ protected function __construct( - protected readonly array $config, - protected readonly bool $private = false, + protected array $config, + protected bool $private = false, ) { } diff --git a/src/Contract/Config/CollectorConfig.php b/src/Contract/Config/CollectorConfig.php index 9be692425..2e38133b0 100644 --- a/src/Contract/Config/CollectorConfig.php +++ b/src/Contract/Config/CollectorConfig.php @@ -7,8 +7,8 @@ abstract class CollectorConfig { protected function __construct( - protected readonly CollectorType $collectorType = CollectorType::TYPE_BOOL, - protected readonly bool $private = false, + protected CollectorType $collectorType = CollectorType::TYPE_BOOL, + protected bool $private = false, ) { } diff --git a/src/Contract/Config/ConfigurableCollectorConfig.php b/src/Contract/Config/ConfigurableCollectorConfig.php index f79c67fbe..30c5fdd32 100644 --- a/src/Contract/Config/ConfigurableCollectorConfig.php +++ b/src/Contract/Config/ConfigurableCollectorConfig.php @@ -7,9 +7,9 @@ abstract class ConfigurableCollectorConfig extends CollectorConfig { final protected function __construct( - protected readonly string $config, - protected readonly CollectorType $collectorType = CollectorType::TYPE_BOOL, - protected readonly bool $private = false, + protected string $config, + protected CollectorType $collectorType = CollectorType::TYPE_BOOL, + protected bool $private = false, ) { } From 0f0dab0aac938f1d655f17dadda36d3d8ffb0502 Mon Sep 17 00:00:00 2001 From: Gennadi McKelvey Date: Sun, 27 Nov 2022 18:13:19 +0100 Subject: [PATCH 30/39] cleanup collector creation --- deptrac.config.php | 34 +++--- .../Config/Collector/AttributeConfig.php | 10 +- src/Contract/Config/Collector/BoolConfig.php | 38 ++++-- src/Contract/Config/Collector/ClassConfig.php | 10 +- .../Config/Collector/ClassLikeConfig.php | 10 +- .../Config/Collector/ClassNameConfig.php | 10 +- .../Config/Collector/DirectoryConfig.php | 10 +- .../Config/Collector/ExtendsConfig.php | 10 +- .../Config/Collector/FunctionNameConfig.php | 10 +- src/Contract/Config/Collector/GlobConfig.php | 10 +- .../Config/Collector/ImplementsConfig.php | 10 +- .../Config/Collector/InheritsConfig.php | 10 +- .../Config/Collector/InterfaceConfig.php | 10 +- src/Contract/Config/Collector/LayerConfig.php | 10 +- .../Config/Collector/MethodConfig.php | 10 +- .../Config/Collector/PhpInteralConfig.php | 10 +- .../Config/Collector/SuperGlobalConfig.php | 15 ++- src/Contract/Config/Collector/TraitConfig.php | 10 +- src/Contract/Config/Collector/UsesConfig.php | 10 +- src/Contract/Config/CollectorConfig.php | 18 +-- .../Config/ConfigurableCollectorConfig.php | 113 ++++++++++++++++-- src/Contract/Config/DeptracConfig.php | 101 +--------------- src/Contract/Config/EmitterType.php | 1 - .../Config/Formatter/GraphvizConfig.php | 14 +-- .../Config/{Layer.php => LayerConfig.php} | 13 +- src/Contract/Config/RulesetConfig.php | 24 ++-- 26 files changed, 219 insertions(+), 312 deletions(-) rename src/Contract/Config/{Layer.php => LayerConfig.php} (68%) diff --git a/deptrac.config.php b/deptrac.config.php index 9f4bf09d8..d4706bfa6 100755 --- a/deptrac.config.php +++ b/deptrac.config.php @@ -34,43 +34,43 @@ ) ->layers( $analyser = Layer::withName('Analyser')->collectors( - DirectoryConfig::public('src/Core/Analyser/.*') + DirectoryConfig::create('src/Core/Analyser/.*') ), $ast = Layer::withName('Ast')->collectors( - DirectoryConfig::public('src/Core/Ast/.*'), - ClassNameConfig::private(regex('^PHPStan\\PhpDocParser\\.*')), - ClassNameConfig::private(regex('^PhpParser\\.*')), - ClassNameConfig::private(regex('^phpDocumentor\\Reflection\\.*')) + DirectoryConfig::create('src/Core/Ast/.*'), + ClassNameConfig::create(regex('^PHPStan\\PhpDocParser\\.*'), true), + ClassNameConfig::create(regex('^PhpParser\\.*'), true), + ClassNameConfig::create(regex('^phpDocumentor\\Reflection\\.*'), true) ), $console = Layer::withName('Console')->collectors( - DirectoryConfig::public('src/Supportive/Console/.*') + DirectoryConfig::create('src/Supportive/Console/.*') ), $dependency = Layer::withName('Dependency')->collectors( - DirectoryConfig::public('src/Core/Dependency/.*') + DirectoryConfig::create('src/Core/Dependency/.*') ), $dependencyInjection = Layer::withName('DependencyInjection')->collectors( - DirectoryConfig::public('src/Supportive/DependencyInjection/.*') + DirectoryConfig::create('src/Supportive/DependencyInjection/.*') ), $contract = Layer::withName('Contract')->collectors( - DirectoryConfig::public('src/Contract/.*') + DirectoryConfig::create('src/Contract/.*') ), $inputCollector = Layer::withName('InputCollector')->collectors( - DirectoryConfig::public('src/Core/InputCollector/.*') + DirectoryConfig::create('src/Core/InputCollector/.*') ), $layer = Layer::withName('Layer')->collectors( - DirectoryConfig::public('src/Core/Layer/.*') + DirectoryConfig::create('src/Core/Layer/.*') ), $outputFormatter = Layer::withName('OutputFormatter')->collectors( - DirectoryConfig::public('src/Supportive/OutputFormatter/.*'), - ClassNameConfig::private(regex('^phpDocumentor\\GraphViz\\.*')), + DirectoryConfig::create('src/Supportive/OutputFormatter/.*'), + ClassNameConfig::create(regex('^phpDocumentor\\GraphViz\\.*'), true), ), $file = Layer::withName('File')->collectors( - DirectoryConfig::public('src/Supportive/File/.*') + DirectoryConfig::create('src/Supportive/File/.*') ), $supportive = Layer::withName('Supportive')->collectors( - BoolConfig::public() - ->withMustNot(DirectoryConfig::public('src/Supportive/.*/.*')) - ->withMust(DirectoryConfig::public('src/Supportive/.*')) + BoolConfig::create() + ->withMustNot(DirectoryConfig::create('src/Supportive/.*/.*')) + ->withMust(DirectoryConfig::create('src/Supportive/.*')) ), ) ->rulesets( diff --git a/src/Contract/Config/Collector/AttributeConfig.php b/src/Contract/Config/Collector/AttributeConfig.php index 256b1ba3e..394658d8a 100644 --- a/src/Contract/Config/Collector/AttributeConfig.php +++ b/src/Contract/Config/Collector/AttributeConfig.php @@ -7,13 +7,5 @@ final class AttributeConfig extends ConfigurableCollectorConfig { - public static function public(string $config): self - { - return new self($config, CollectorType::TYPE_BOOL, false); - } - - public static function private(string $config): self - { - return new self($config, CollectorType::TYPE_BOOL, true); - } + protected CollectorType $collectorType = CollectorType::TYPE_ATTRIBUTE; } diff --git a/src/Contract/Config/Collector/BoolConfig.php b/src/Contract/Config/Collector/BoolConfig.php index a385af1bc..1a12facdd 100644 --- a/src/Contract/Config/Collector/BoolConfig.php +++ b/src/Contract/Config/Collector/BoolConfig.php @@ -7,32 +7,50 @@ final class BoolConfig extends CollectorConfig { + protected CollectorType $collectorType = CollectorType::TYPE_BOOL; + /** @var array */ private array $mustNot = []; /** @var array */ private array $must = []; - public static function public(): self + private function __construct() { - return new self(collectorType: CollectorType::TYPE_BOOL, private: false); } - public static function private(): self + /** + * @param array $must + * @param array $mostNot + */ + public static function create(array $must = [], array $mostNot = []): self { - return new self(collectorType: CollectorType::TYPE_BOOL, private: true); + return (new self()) + ->must(...$must) + ->mustNot(...$mostNot); + } + + public function private(): self + { + $this->private = true; + + return $this; } - public function withMustNot(CollectorConfig $CollectorConfig): self + public function mustNot(CollectorConfig ...$collectorConfigs): self { - $this->mustNot[] = $CollectorConfig; + foreach ($collectorConfigs as $collectorConfig) { + $this->mustNot[] = $collectorConfig; + } return $this; } - public function withMust(CollectorConfig $CollectorConfig): self + public function must(CollectorConfig ...$collectorConfigs): self { - $this->must[] = $CollectorConfig; + foreach ($collectorConfigs as $collectorConfig) { + $this->must[] = $collectorConfig; + } return $this; } @@ -45,9 +63,11 @@ public function withMust(CollectorConfig $CollectorConfig): self */ public function toArray(): array { - return parent::toArray() + [ + 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, ]; } } diff --git a/src/Contract/Config/Collector/ClassConfig.php b/src/Contract/Config/Collector/ClassConfig.php index 760f6efd3..e7a285d8d 100644 --- a/src/Contract/Config/Collector/ClassConfig.php +++ b/src/Contract/Config/Collector/ClassConfig.php @@ -7,13 +7,5 @@ final class ClassConfig extends ConfigurableCollectorConfig { - public static function public(string $config): static - { - return new self(config: $config, collectorType: CollectorType::TYPE_CLASS, private: false); - } - - public static function private(string $config): static - { - return new self(config: $config, collectorType: CollectorType::TYPE_CLASS, private: true); - } + protected CollectorType $collectorType = CollectorType::TYPE_CLASS; } diff --git a/src/Contract/Config/Collector/ClassLikeConfig.php b/src/Contract/Config/Collector/ClassLikeConfig.php index c58d900de..2f57f558f 100644 --- a/src/Contract/Config/Collector/ClassLikeConfig.php +++ b/src/Contract/Config/Collector/ClassLikeConfig.php @@ -7,13 +7,5 @@ final class ClassLikeConfig extends ConfigurableCollectorConfig { - public static function public(string $config): static - { - return new self(config: $config, collectorType: CollectorType::TYPE_CLASSLIKE, private: false); - } - - public static function private(string $config): static - { - return new self(config: $config, collectorType: CollectorType::TYPE_CLASSLIKE, private: true); - } + protected CollectorType $collectorType = CollectorType::TYPE_CLASSLIKE; } diff --git a/src/Contract/Config/Collector/ClassNameConfig.php b/src/Contract/Config/Collector/ClassNameConfig.php index 50a52e37f..cb7e15faa 100644 --- a/src/Contract/Config/Collector/ClassNameConfig.php +++ b/src/Contract/Config/Collector/ClassNameConfig.php @@ -7,13 +7,5 @@ final class ClassNameConfig extends ConfigurableCollectorConfig { - public static function public(string $config): static - { - return new self(config: $config, collectorType: CollectorType::TYPE_CLASS_NAME, private: false); - } - - public static function private(string $config): static - { - return new self(config: $config, collectorType: CollectorType::TYPE_CLASS_NAME, private: true); - } + protected CollectorType $collectorType = CollectorType::TYPE_CLASS_NAME; } diff --git a/src/Contract/Config/Collector/DirectoryConfig.php b/src/Contract/Config/Collector/DirectoryConfig.php index 1787f3306..1009a9366 100644 --- a/src/Contract/Config/Collector/DirectoryConfig.php +++ b/src/Contract/Config/Collector/DirectoryConfig.php @@ -7,13 +7,5 @@ final class DirectoryConfig extends ConfigurableCollectorConfig { - public static function public(string $config): static - { - return new self(config: $config, collectorType: CollectorType::TYPE_DIRECTORY, private: false); - } - - public static function private(string $config): static - { - return new self(config: $config, collectorType: CollectorType::TYPE_DIRECTORY, private: true); - } + protected CollectorType $collectorType = CollectorType::TYPE_DIRECTORY; } diff --git a/src/Contract/Config/Collector/ExtendsConfig.php b/src/Contract/Config/Collector/ExtendsConfig.php index 28c0122f6..23d702402 100644 --- a/src/Contract/Config/Collector/ExtendsConfig.php +++ b/src/Contract/Config/Collector/ExtendsConfig.php @@ -7,13 +7,5 @@ final class ExtendsConfig extends ConfigurableCollectorConfig { - public static function public(string $config): static - { - return new self(config: $config, collectorType: CollectorType::TYPE_EXTENDS, private: false); - } - - public static function private(string $config): static - { - return new self(config: $config, collectorType: CollectorType::TYPE_EXTENDS, private: true); - } + protected CollectorType $collectorType = CollectorType::TYPE_EXTENDS; } diff --git a/src/Contract/Config/Collector/FunctionNameConfig.php b/src/Contract/Config/Collector/FunctionNameConfig.php index 3b2fe3f9e..9b90877c0 100644 --- a/src/Contract/Config/Collector/FunctionNameConfig.php +++ b/src/Contract/Config/Collector/FunctionNameConfig.php @@ -7,13 +7,5 @@ final class FunctionNameConfig extends ConfigurableCollectorConfig { - public static function public(string $config): static - { - return new self(config: $config, collectorType: CollectorType::TYPE_FUNCTION_NAME, private: false); - } - - public static function private(string $config): static - { - return new self(config: $config, collectorType: CollectorType::TYPE_FUNCTION_NAME, private: true); - } + protected CollectorType $collectorType = CollectorType::TYPE_FUNCTION_NAME; } diff --git a/src/Contract/Config/Collector/GlobConfig.php b/src/Contract/Config/Collector/GlobConfig.php index 1a04fdbc3..22778b9d7 100644 --- a/src/Contract/Config/Collector/GlobConfig.php +++ b/src/Contract/Config/Collector/GlobConfig.php @@ -7,13 +7,5 @@ final class GlobConfig extends ConfigurableCollectorConfig { - public static function public(string $config): static - { - return new self(config: $config, collectorType: CollectorType::TYPE_GLOB, private: false); - } - - public static function private(string $config): static - { - return new self(config: $config, collectorType: CollectorType::TYPE_GLOB, private: true); - } + protected CollectorType $collectorType = CollectorType::TYPE_GLOB; } diff --git a/src/Contract/Config/Collector/ImplementsConfig.php b/src/Contract/Config/Collector/ImplementsConfig.php index 69f0e7b2f..af6d88ba3 100644 --- a/src/Contract/Config/Collector/ImplementsConfig.php +++ b/src/Contract/Config/Collector/ImplementsConfig.php @@ -7,13 +7,5 @@ final class ImplementsConfig extends ConfigurableCollectorConfig { - public static function public(string $config): static - { - return new self(config: $config, collectorType: CollectorType::TYPE_IMPLEMENTS, private: false); - } - - public static function private(string $config): static - { - return new self(config: $config, collectorType: CollectorType::TYPE_IMPLEMENTS, private: true); - } + protected CollectorType $collectorType = CollectorType::TYPE_IMPLEMENTS; } diff --git a/src/Contract/Config/Collector/InheritsConfig.php b/src/Contract/Config/Collector/InheritsConfig.php index 686f57aa5..033c6004a 100644 --- a/src/Contract/Config/Collector/InheritsConfig.php +++ b/src/Contract/Config/Collector/InheritsConfig.php @@ -7,13 +7,5 @@ final class InheritsConfig extends ConfigurableCollectorConfig { - public static function public(string $config): static - { - return new self(config: $config, collectorType: CollectorType::TYPE_INHERITS, private: false); - } - - public static function private(string $config): static - { - return new self(config: $config, collectorType: CollectorType::TYPE_INHERITS, private: true); - } + protected CollectorType $collectorType = CollectorType::TYPE_INHERITS; } diff --git a/src/Contract/Config/Collector/InterfaceConfig.php b/src/Contract/Config/Collector/InterfaceConfig.php index c21d61ea0..0deb5319f 100644 --- a/src/Contract/Config/Collector/InterfaceConfig.php +++ b/src/Contract/Config/Collector/InterfaceConfig.php @@ -7,13 +7,5 @@ final class InterfaceConfig extends ConfigurableCollectorConfig { - public static function public(string $config): static - { - return new self(config: $config, collectorType: CollectorType::TYPE_INTERFACE, private: false); - } - - public static function private(string $config): static - { - return new self(config: $config, collectorType: CollectorType::TYPE_INTERFACE, private: true); - } + protected CollectorType $collectorType = CollectorType::TYPE_INTERFACE; } diff --git a/src/Contract/Config/Collector/LayerConfig.php b/src/Contract/Config/Collector/LayerConfig.php index 9acda985d..b3b4b1c20 100644 --- a/src/Contract/Config/Collector/LayerConfig.php +++ b/src/Contract/Config/Collector/LayerConfig.php @@ -7,13 +7,5 @@ final class LayerConfig extends ConfigurableCollectorConfig { - public static function public(string $config): static - { - return new self(config: $config, collectorType: CollectorType::TYPE_LAYER, private: false); - } - - public static function private(string $config): static - { - return new self(config: $config, collectorType: CollectorType::TYPE_LAYER, private: true); - } + protected CollectorType $collectorType = CollectorType::TYPE_LAYER; } diff --git a/src/Contract/Config/Collector/MethodConfig.php b/src/Contract/Config/Collector/MethodConfig.php index 7f9d5edc9..a72e3b595 100644 --- a/src/Contract/Config/Collector/MethodConfig.php +++ b/src/Contract/Config/Collector/MethodConfig.php @@ -7,13 +7,5 @@ final class MethodConfig extends ConfigurableCollectorConfig { - public static function public(string $config): static - { - return new self(config: $config, collectorType: CollectorType::TYPE_METHOD, private: false); - } - - public static function private(string $config): static - { - return new self(config: $config, collectorType: CollectorType::TYPE_METHOD, private: true); - } + protected CollectorType $collectorType = CollectorType::TYPE_METHOD; } diff --git a/src/Contract/Config/Collector/PhpInteralConfig.php b/src/Contract/Config/Collector/PhpInteralConfig.php index 8da9d3123..c5a9ae760 100644 --- a/src/Contract/Config/Collector/PhpInteralConfig.php +++ b/src/Contract/Config/Collector/PhpInteralConfig.php @@ -7,13 +7,5 @@ final class PhpInteralConfig extends ConfigurableCollectorConfig { - public static function public(string $config): static - { - return new self(config: $config, collectorType: CollectorType::TYPE_PHP_INTERNAL, private: false); - } - - public static function private(string $config): static - { - return new self(config: $config, collectorType: CollectorType::TYPE_PHP_INTERNAL, private: true); - } + protected CollectorType $collectorType = CollectorType::TYPE_PHP_INTERNAL; } diff --git a/src/Contract/Config/Collector/SuperGlobalConfig.php b/src/Contract/Config/Collector/SuperGlobalConfig.php index 92b32e1b0..c3086d050 100644 --- a/src/Contract/Config/Collector/SuperGlobalConfig.php +++ b/src/Contract/Config/Collector/SuperGlobalConfig.php @@ -7,23 +7,26 @@ final class SuperGlobalConfig extends CollectorConfig { + protected CollectorType $collectorType = CollectorType::TYPE_SUPERGLOBAL; + /** * @param string[] $config */ - protected function __construct( + private function __construct( protected array $config, - protected bool $private = false, ) { } - public static function public(string ...$config): static + public static function create(string ...$config): self { - return new self(config: $config); + return new self($config); } - public static function private(string ...$config): static + public function private(): self { - return new self(config: $config, private: true); + $this->private = true; + + return $this; } /** diff --git a/src/Contract/Config/Collector/TraitConfig.php b/src/Contract/Config/Collector/TraitConfig.php index 9194115f0..f67dc8786 100644 --- a/src/Contract/Config/Collector/TraitConfig.php +++ b/src/Contract/Config/Collector/TraitConfig.php @@ -7,13 +7,5 @@ final class TraitConfig extends ConfigurableCollectorConfig { - public static function public(string $config): static - { - return new self(config: $config, collectorType: CollectorType::TYPE_TRAIT, private: false); - } - - public static function private(string $config): static - { - return new self(config: $config, collectorType: CollectorType::TYPE_TRAIT, private: true); - } + protected CollectorType $collectorType = CollectorType::TYPE_TRAIT; } diff --git a/src/Contract/Config/Collector/UsesConfig.php b/src/Contract/Config/Collector/UsesConfig.php index 4cb56a9b5..3001fc7f7 100644 --- a/src/Contract/Config/Collector/UsesConfig.php +++ b/src/Contract/Config/Collector/UsesConfig.php @@ -7,13 +7,5 @@ final class UsesConfig extends ConfigurableCollectorConfig { - public static function public(string $config): static - { - return new self(config: $config, collectorType: CollectorType::TYPE_USES, private: false); - } - - public static function private(string $config): static - { - return new self(config: $config, collectorType: CollectorType::TYPE_USES, private: true); - } + protected CollectorType $collectorType = CollectorType::TYPE_USES; } diff --git a/src/Contract/Config/CollectorConfig.php b/src/Contract/Config/CollectorConfig.php index 2e38133b0..ec5d835f4 100644 --- a/src/Contract/Config/CollectorConfig.php +++ b/src/Contract/Config/CollectorConfig.php @@ -6,20 +6,22 @@ abstract class CollectorConfig { - protected function __construct( - protected CollectorType $collectorType = CollectorType::TYPE_BOOL, - protected bool $private = false, - ) { + protected bool $private = false; + protected CollectorType $collectorType; + + public function private(): self + { + $this->private = true; + + return $this; } - /** - * @return array{'type': string, 'private': bool} - */ + /** @return array{'type': string, 'private': bool} */ public function toArray(): array { return [ - 'private' => $this->private, 'type' => $this->collectorType->value, + 'private' => $this->private, ]; } } diff --git a/src/Contract/Config/ConfigurableCollectorConfig.php b/src/Contract/Config/ConfigurableCollectorConfig.php index 30c5fdd32..25943d062 100644 --- a/src/Contract/Config/ConfigurableCollectorConfig.php +++ b/src/Contract/Config/ConfigurableCollectorConfig.php @@ -6,30 +6,127 @@ abstract class ConfigurableCollectorConfig extends CollectorConfig { + private const ESCAPEES = [ + '\\', + '\\\\', + '\\"', + '"', + "\x00", + "\x01", + "\x02", + "\x03", + "\x04", + "\x05", + "\x06", + "\x07", + "\x08", + "\x09", + "\x0a", + "\x0b", + "\x0c", + "\x0d", + "\x0e", + "\x0f", + "\x10", + "\x11", + "\x12", + "\x13", + "\x14", + "\x15", + "\x16", + "\x17", + "\x18", + "\x19", + "\x1a", + "\x1b", + "\x1c", + "\x1d", + "\x1e", + "\x1f", + "\x7f", + "\xc2\x85", + "\xc2\xa0", + "\xe2\x80\xa8", + "\xe2\x80\xa9", + ]; + + private const ESCAPED = [ + '\\\\', + '\\"', + '\\\\', + '\\"', + '\\0', + '\\x01', + '\\x02', + '\\x03', + '\\x04', + '\\x05', + '\\x06', + '\\a', + '\\b', + '\\t', + '\\n', + '\\v', + '\\f', + '\\r', + '\\x0e', + '\\x0f', + '\\x10', + '\\x11', + '\\x12', + '\\x13', + '\\x14', + '\\x15', + '\\x16', + '\\x17', + '\\x18', + '\\x19', + '\\x1a', + '\\e', + '\\x1c', + '\\x1d', + '\\x1e', + '\\x1f', + '\\x7f', + '\\N', + '\\_', + '\\L', + '\\P', + ]; + + protected CollectorType $collectorType; + final protected function __construct( protected string $config, - protected CollectorType $collectorType = CollectorType::TYPE_BOOL, - protected bool $private = false, ) { } - public static function public(string $config): static + public static function create(string $config): self { - return new static($config); + return new static(self::regex($config)); } - public static function private(string $config): static + public function private(): self { - return new static(config: $config, private: true); + $this->private = true; + + return $this; } /** - * @return array{private: bool, type: string, value: mixed|string} + * @return array{private: bool, type: string, value: string} */ public function toArray(): array { - return parent::toArray() + [ + return [ 'value' => $this->config, + 'type' => $this->collectorType->value, + 'private' => $this->private, ]; } + + private static function regex(string $regex): string + { + return sprintf('%s', str_replace(self::ESCAPEES, self::ESCAPED, $regex)); + } } diff --git a/src/Contract/Config/DeptracConfig.php b/src/Contract/Config/DeptracConfig.php index 597d4596e..445c7e543 100644 --- a/src/Contract/Config/DeptracConfig.php +++ b/src/Contract/Config/DeptracConfig.php @@ -15,7 +15,7 @@ final class DeptracConfig implements ConfigBuilderInterface /** @var array */ private array $paths = []; - /** @var array */ + /** @var array */ private array $layers = []; /** @var array */ private array $formatters = []; @@ -79,7 +79,7 @@ public function excludeFiles(string ...$excludeFiles): self return $this; } - public function layers(Layer ...$layerConfigs): self + public function layers(LayerConfig ...$layerConfigs): self { foreach ($layerConfigs as $layerConfig) { $this->layers[$layerConfig->name] = $layerConfig; @@ -91,7 +91,7 @@ public function layers(Layer ...$layerConfigs): self public function rulesets(RulesetConfig ...$rulesetConfigs): self { foreach ($rulesetConfigs as $rulesetConfig) { - $this->rulesets[$rulesetConfig->layersConfig->name] = $rulesetConfig; + $this->rulesets[$rulesetConfig->layerConfig->name] = $rulesetConfig; } return $this; @@ -119,7 +119,7 @@ public function toArray(): array } if ([] !== $this->layers) { - $config['layers'] = array_map(static fn (Layer $layerConfig) => $layerConfig->toArray(), $this->layers); + $config['layers'] = array_map(static fn (LayerConfig $layerConfig) => $layerConfig->toArray(), $this->layers); } if ([] !== $this->rulesets) { @@ -141,96 +141,3 @@ public function getExtensionAlias(): string return 'deptrac'; } } - -const ESCAPEES = [ - '\\', - '\\\\', - '\\"', - '"', - "\x00", - "\x01", - "\x02", - "\x03", - "\x04", - "\x05", - "\x06", - "\x07", - "\x08", - "\x09", - "\x0a", - "\x0b", - "\x0c", - "\x0d", - "\x0e", - "\x0f", - "\x10", - "\x11", - "\x12", - "\x13", - "\x14", - "\x15", - "\x16", - "\x17", - "\x18", - "\x19", - "\x1a", - "\x1b", - "\x1c", - "\x1d", - "\x1e", - "\x1f", - "\x7f", - "\xc2\x85", - "\xc2\xa0", - "\xe2\x80\xa8", - "\xe2\x80\xa9", -]; - -const ESCAPED = [ - '\\\\', - '\\"', - '\\\\', - '\\"', - '\\0', - '\\x01', - '\\x02', - '\\x03', - '\\x04', - '\\x05', - '\\x06', - '\\a', - '\\b', - '\\t', - '\\n', - '\\v', - '\\f', - '\\r', - '\\x0e', - '\\x0f', - '\\x10', - '\\x11', - '\\x12', - '\\x13', - '\\x14', - '\\x15', - '\\x16', - '\\x17', - '\\x18', - '\\x19', - '\\x1a', - '\\e', - '\\x1c', - '\\x1d', - '\\x1e', - '\\x1f', - '\\x7f', - '\\N', - '\\_', - '\\L', - '\\P', -]; - -function regex(string $regex): string -{ - return sprintf('%s', str_replace(ESCAPEES, ESCAPED, $regex)); -} diff --git a/src/Contract/Config/EmitterType.php b/src/Contract/Config/EmitterType.php index df6634b4a..a1d5bd713 100644 --- a/src/Contract/Config/EmitterType.php +++ b/src/Contract/Config/EmitterType.php @@ -13,7 +13,6 @@ enum EmitterType: string case FUNCTION_CALL = 'function_call'; case FUNCTION_SUPERGLOBAL_TOKEN = 'function_superglobal'; case USE_TOKEN = 'use'; - /** * @return list */ diff --git a/src/Contract/Config/Formatter/GraphvizConfig.php b/src/Contract/Config/Formatter/GraphvizConfig.php index b3a8f3c67..ec735e609 100644 --- a/src/Contract/Config/Formatter/GraphvizConfig.php +++ b/src/Contract/Config/Formatter/GraphvizConfig.php @@ -4,17 +4,17 @@ namespace Qossmic\Deptrac\Contract\Config\Formatter; -use Qossmic\Deptrac\Contract\Config\Layer; +use Qossmic\Deptrac\Contract\Config\LayerConfig; final class GraphvizConfig implements FormatterConfigInterface { private string $name = 'graphviz'; private bool $pointsToGroup = false; - /** @var Layer[] */ + /** @var LayerConfig[] */ private array $hiddenLayers = []; - /** @var array */ + /** @var array */ private array $groups = []; private function __construct() @@ -33,7 +33,7 @@ public function pointsToGroup(bool $pointsToGroup = true): self return $this; } - public function hiddenLayers(Layer ...$LayerConfigs): self + public function hiddenLayers(LayerConfig ...$LayerConfigs): self { foreach ($LayerConfigs as $layerConfig) { $this->hiddenLayers[] = $layerConfig; @@ -42,7 +42,7 @@ public function hiddenLayers(Layer ...$LayerConfigs): self return $this; } - public function groups(string $name, Layer ...$layerConfigs): self + public function groups(string $name, LayerConfig ...$layerConfigs): self { foreach ($layerConfigs as $layerConfig) { $this->groups[$name][] = $layerConfig; @@ -56,12 +56,12 @@ public function toArray(): array $output = []; if ([] !== $this->hiddenLayers) { - $output['hidden_layers'] = array_map(static fn (Layer $config) => $config->name, $this->hiddenLayers); + $output['hidden_layers'] = array_map(static fn (LayerConfig $config) => $config->name, $this->hiddenLayers); } if ([] !== $this->groups) { $output['groups'] = array_map( - static fn (array $configs) => array_map(static fn (Layer $layer) => $layer->name, $configs), + static fn (array $configs) => array_map(static fn (LayerConfig $layer) => $layer->name, $configs), $this->groups ); } diff --git a/src/Contract/Config/Layer.php b/src/Contract/Config/LayerConfig.php similarity index 68% rename from src/Contract/Config/Layer.php rename to src/Contract/Config/LayerConfig.php index 8588dfe6b..ae87ab1be 100644 --- a/src/Contract/Config/Layer.php +++ b/src/Contract/Config/LayerConfig.php @@ -4,17 +4,20 @@ namespace Qossmic\Deptrac\Contract\Config; -final class Layer +final class LayerConfig { /** @var array */ private array $collectors = []; + public string $name; - private function __construct( - public readonly string $name - ) { + /** @param array $collectorConfig */ + public function __construct(string $name, array $collectorConfig = []) + { + $this->name = $name; + $this->collectors(...$collectorConfig); } - public static function withName(string $name): self + public static function create(string $name): self { return new self($name); } diff --git a/src/Contract/Config/RulesetConfig.php b/src/Contract/Config/RulesetConfig.php index 00033b1bb..61604a262 100644 --- a/src/Contract/Config/RulesetConfig.php +++ b/src/Contract/Config/RulesetConfig.php @@ -6,22 +6,26 @@ final class RulesetConfig { - /** @var array */ + public LayerConfig $layerConfig; + + /** @var array */ private array $accessableLayers = []; - public function __construct( - public readonly Layer $layersConfig - ) { + /** @param array $layerConfigs */ + public function __construct(LayerConfig $layerConfig, array $layerConfigs) + { + $this->layerConfig = $layerConfig; + $this->accesses(...$layerConfigs); } - public static function layer(Layer $layerConfig): self + public static function create(LayerConfig $layerConfig): self { - return new self($layerConfig); + return new self($layerConfig, []); } - public function accesses(Layer ...$layersConfig): self + public function accesses(LayerConfig ...$layerConfigs): self { - foreach ($layersConfig as $layerConfig) { + foreach ($layerConfigs as $layerConfig) { $this->accessableLayers[] = $layerConfig; } @@ -31,8 +35,8 @@ public function accesses(Layer ...$layersConfig): self /** @return non-empty-array */ public function toArray(): array { - $data = array_map(static fn (Layer $layerConfig) => $layerConfig->name, $this->accessableLayers); + $data = array_map(static fn (LayerConfig $layerConfig) => $layerConfig->name, $this->accessableLayers); - return $data + ['name' => $this->layersConfig->name]; + return $data + ['name' => $this->layerConfig->name]; } } From 33a39e53841318b4c00d0ab29f9e519fd19a7d23 Mon Sep 17 00:00:00 2001 From: Gennadi McKelvey Date: Tue, 6 Dec 2022 21:24:03 +0100 Subject: [PATCH 31/39] fix cs --- src/Contract/Config/EmitterType.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Contract/Config/EmitterType.php b/src/Contract/Config/EmitterType.php index a1d5bd713..df6634b4a 100644 --- a/src/Contract/Config/EmitterType.php +++ b/src/Contract/Config/EmitterType.php @@ -13,6 +13,7 @@ enum EmitterType: string case FUNCTION_CALL = 'function_call'; case FUNCTION_SUPERGLOBAL_TOKEN = 'function_superglobal'; case USE_TOKEN = 'use'; + /** * @return list */ From 81a79d5fb0fe70cd2f26ae277eb8d9b1483f6961 Mon Sep 17 00:00:00 2001 From: Gennadi McKelvey Date: Tue, 6 Dec 2022 21:52:55 +0100 Subject: [PATCH 32/39] fix deptrac.config.php --- deptrac.config.php | 36 +++++++++---------- src/Contract/Config/CollectorConfig.php | 2 +- .../Config/ConfigurableCollectorConfig.php | 2 -- src/Contract/Config/DeptracConfig.php | 14 ++++---- .../Config/Formatter/GraphvizConfig.php | 14 ++++---- .../Config/{LayerConfig.php => Layer.php} | 4 +-- .../Config/{RulesetConfig.php => Ruleset.php} | 16 ++++----- 7 files changed, 42 insertions(+), 46 deletions(-) rename src/Contract/Config/{LayerConfig.php => Layer.php} (92%) rename src/Contract/Config/{RulesetConfig.php => Ruleset.php} (55%) diff --git a/deptrac.config.php b/deptrac.config.php index d4706bfa6..587ae61eb 100755 --- a/deptrac.config.php +++ b/deptrac.config.php @@ -10,9 +10,8 @@ use Qossmic\Deptrac\Contract\Config\EmitterType; use Qossmic\Deptrac\Contract\Config\Formatter\GraphvizConfig; use Qossmic\Deptrac\Contract\Config\Layer; -use Qossmic\Deptrac\Contract\Config\RulesetConfig; +use Qossmic\Deptrac\Contract\Config\Ruleset; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; -use function Qossmic\Deptrac\Contract\Config\regex; return static function (DeptracConfig $config, ContainerConfigurator $containerConfigurator): void { $services = $containerConfigurator->services(); @@ -38,9 +37,9 @@ ), $ast = Layer::withName('Ast')->collectors( DirectoryConfig::create('src/Core/Ast/.*'), - ClassNameConfig::create(regex('^PHPStan\\PhpDocParser\\.*'), true), - ClassNameConfig::create(regex('^PhpParser\\.*'), true), - ClassNameConfig::create(regex('^phpDocumentor\\Reflection\\.*'), true) + ClassNameConfig::create('^PHPStan\\PhpDocParser\\.*')->private(), + ClassNameConfig::create('^PhpParser\\.*')->private(), + ClassNameConfig::create('^phpDocumentor\\Reflection\\.*')->private(), ), $console = Layer::withName('Console')->collectors( DirectoryConfig::create('src/Supportive/Console/.*') @@ -62,27 +61,27 @@ ), $outputFormatter = Layer::withName('OutputFormatter')->collectors( DirectoryConfig::create('src/Supportive/OutputFormatter/.*'), - ClassNameConfig::create(regex('^phpDocumentor\\GraphViz\\.*'), true), + ClassNameConfig::create('^phpDocumentor\\GraphViz\\.*')->private(), ), $file = Layer::withName('File')->collectors( DirectoryConfig::create('src/Supportive/File/.*') ), $supportive = Layer::withName('Supportive')->collectors( BoolConfig::create() - ->withMustNot(DirectoryConfig::create('src/Supportive/.*/.*')) - ->withMust(DirectoryConfig::create('src/Supportive/.*')) + ->mustNot(DirectoryConfig::create('src/Supportive/.*/.*')) + ->must(DirectoryConfig::create('src/Supportive/.*')) ), ) ->rulesets( - RulesetConfig::layer($layer)->accesses($ast), - RulesetConfig::layer($console)->accesses($analyser, $outputFormatter, $dependencyInjection, $file), - RulesetConfig::layer($dependency)->accesses($ast), - RulesetConfig::layer($analyser)->accesses($layer, $dependency, $ast), - RulesetConfig::layer($outputFormatter)->accesses($console, $dependencyInjection), - RulesetConfig::layer($ast)->accesses($file, $inputCollector), - RulesetConfig::layer($inputCollector)->accesses($file), - RulesetConfig::layer($supportive)->accesses($file), - RulesetConfig::layer($contract), + 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() @@ -91,6 +90,5 @@ ->groups('Supportive', $supportive, $file) ->groups('Symfony', $console, $dependencyInjection, $outputFormatter) ->groups('Core', $analyser, $ast, $dependency, $inputCollector, $layer) - ) - ; + ); }; diff --git a/src/Contract/Config/CollectorConfig.php b/src/Contract/Config/CollectorConfig.php index ec5d835f4..632fbb7e5 100644 --- a/src/Contract/Config/CollectorConfig.php +++ b/src/Contract/Config/CollectorConfig.php @@ -7,7 +7,7 @@ abstract class CollectorConfig { protected bool $private = false; - protected CollectorType $collectorType; + protected CollectorType $collectorType = CollectorType::TYPE_DIRECTORY; public function private(): self { diff --git a/src/Contract/Config/ConfigurableCollectorConfig.php b/src/Contract/Config/ConfigurableCollectorConfig.php index 25943d062..a48f35c72 100644 --- a/src/Contract/Config/ConfigurableCollectorConfig.php +++ b/src/Contract/Config/ConfigurableCollectorConfig.php @@ -94,8 +94,6 @@ abstract class ConfigurableCollectorConfig extends CollectorConfig '\\P', ]; - protected CollectorType $collectorType; - final protected function __construct( protected string $config, ) { diff --git a/src/Contract/Config/DeptracConfig.php b/src/Contract/Config/DeptracConfig.php index 445c7e543..3027d8523 100644 --- a/src/Contract/Config/DeptracConfig.php +++ b/src/Contract/Config/DeptracConfig.php @@ -15,13 +15,13 @@ final class DeptracConfig implements ConfigBuilderInterface /** @var array */ private array $paths = []; - /** @var array */ + /** @var array */ private array $layers = []; /** @var array */ private array $formatters = []; - /** @var array */ + /** @var array */ private array $rulesets = []; - /** @var array */ + /** @var array */ private array $analyser = []; /** @var array> */ private array $skipViolations = []; @@ -79,7 +79,7 @@ public function excludeFiles(string ...$excludeFiles): self return $this; } - public function layers(LayerConfig ...$layerConfigs): self + public function layers(Layer ...$layerConfigs): self { foreach ($layerConfigs as $layerConfig) { $this->layers[$layerConfig->name] = $layerConfig; @@ -88,7 +88,7 @@ public function layers(LayerConfig ...$layerConfigs): self return $this; } - public function rulesets(RulesetConfig ...$rulesetConfigs): self + public function rulesets(Ruleset ...$rulesetConfigs): self { foreach ($rulesetConfigs as $rulesetConfig) { $this->rulesets[$rulesetConfig->layerConfig->name] = $rulesetConfig; @@ -119,11 +119,11 @@ public function toArray(): array } if ([] !== $this->layers) { - $config['layers'] = array_map(static fn (LayerConfig $layerConfig) => $layerConfig->toArray(), $this->layers); + $config['layers'] = array_map(static fn (Layer $layerConfig) => $layerConfig->toArray(), $this->layers); } if ([] !== $this->rulesets) { - $config['ruleset'] = array_map(static fn (RulesetConfig $rulesetConfig) => $rulesetConfig->toArray(), $this->rulesets); + $config['ruleset'] = array_map(static fn (Ruleset $rulesetConfig) => $rulesetConfig->toArray(), $this->rulesets); } if ([] !== $this->skipViolations) { diff --git a/src/Contract/Config/Formatter/GraphvizConfig.php b/src/Contract/Config/Formatter/GraphvizConfig.php index ec735e609..b3a8f3c67 100644 --- a/src/Contract/Config/Formatter/GraphvizConfig.php +++ b/src/Contract/Config/Formatter/GraphvizConfig.php @@ -4,17 +4,17 @@ namespace Qossmic\Deptrac\Contract\Config\Formatter; -use Qossmic\Deptrac\Contract\Config\LayerConfig; +use Qossmic\Deptrac\Contract\Config\Layer; final class GraphvizConfig implements FormatterConfigInterface { private string $name = 'graphviz'; private bool $pointsToGroup = false; - /** @var LayerConfig[] */ + /** @var Layer[] */ private array $hiddenLayers = []; - /** @var array */ + /** @var array */ private array $groups = []; private function __construct() @@ -33,7 +33,7 @@ public function pointsToGroup(bool $pointsToGroup = true): self return $this; } - public function hiddenLayers(LayerConfig ...$LayerConfigs): self + public function hiddenLayers(Layer ...$LayerConfigs): self { foreach ($LayerConfigs as $layerConfig) { $this->hiddenLayers[] = $layerConfig; @@ -42,7 +42,7 @@ public function hiddenLayers(LayerConfig ...$LayerConfigs): self return $this; } - public function groups(string $name, LayerConfig ...$layerConfigs): self + public function groups(string $name, Layer ...$layerConfigs): self { foreach ($layerConfigs as $layerConfig) { $this->groups[$name][] = $layerConfig; @@ -56,12 +56,12 @@ public function toArray(): array $output = []; if ([] !== $this->hiddenLayers) { - $output['hidden_layers'] = array_map(static fn (LayerConfig $config) => $config->name, $this->hiddenLayers); + $output['hidden_layers'] = array_map(static fn (Layer $config) => $config->name, $this->hiddenLayers); } if ([] !== $this->groups) { $output['groups'] = array_map( - static fn (array $configs) => array_map(static fn (LayerConfig $layer) => $layer->name, $configs), + static fn (array $configs) => array_map(static fn (Layer $layer) => $layer->name, $configs), $this->groups ); } diff --git a/src/Contract/Config/LayerConfig.php b/src/Contract/Config/Layer.php similarity index 92% rename from src/Contract/Config/LayerConfig.php rename to src/Contract/Config/Layer.php index ae87ab1be..4f5f07e2f 100644 --- a/src/Contract/Config/LayerConfig.php +++ b/src/Contract/Config/Layer.php @@ -4,7 +4,7 @@ namespace Qossmic\Deptrac\Contract\Config; -final class LayerConfig +final class Layer { /** @var array */ private array $collectors = []; @@ -17,7 +17,7 @@ public function __construct(string $name, array $collectorConfig = []) $this->collectors(...$collectorConfig); } - public static function create(string $name): self + public static function withName(string $name): self { return new self($name); } diff --git a/src/Contract/Config/RulesetConfig.php b/src/Contract/Config/Ruleset.php similarity index 55% rename from src/Contract/Config/RulesetConfig.php rename to src/Contract/Config/Ruleset.php index 61604a262..9797599aa 100644 --- a/src/Contract/Config/RulesetConfig.php +++ b/src/Contract/Config/Ruleset.php @@ -4,26 +4,26 @@ namespace Qossmic\Deptrac\Contract\Config; -final class RulesetConfig +final class Ruleset { - public LayerConfig $layerConfig; + public Layer $layerConfig; - /** @var array */ + /** @var array */ private array $accessableLayers = []; - /** @param array $layerConfigs */ - public function __construct(LayerConfig $layerConfig, array $layerConfigs) + /** @param array $layerConfigs */ + public function __construct(Layer $layerConfig, array $layerConfigs) { $this->layerConfig = $layerConfig; $this->accesses(...$layerConfigs); } - public static function create(LayerConfig $layerConfig): self + public static function forLayer(Layer $layerConfig): self { return new self($layerConfig, []); } - public function accesses(LayerConfig ...$layerConfigs): self + public function accesses(Layer ...$layerConfigs): self { foreach ($layerConfigs as $layerConfig) { $this->accessableLayers[] = $layerConfig; @@ -35,7 +35,7 @@ public function accesses(LayerConfig ...$layerConfigs): self /** @return non-empty-array */ public function toArray(): array { - $data = array_map(static fn (LayerConfig $layerConfig) => $layerConfig->name, $this->accessableLayers); + $data = array_map(static fn (Layer $layerConfig) => $layerConfig->name, $this->accessableLayers); return $data + ['name' => $this->layerConfig->name]; } From d6ec68ab40dd34b80d771275bc33b6994098d04d Mon Sep 17 00:00:00 2001 From: Gennadi McKelvey Date: Fri, 20 Jan 2023 14:57:56 +0100 Subject: [PATCH 33/39] comment in xdebughandler --- deptrac.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/deptrac.php b/deptrac.php index e757330fc..f7855b840 100755 --- a/deptrac.php +++ b/deptrac.php @@ -20,8 +20,8 @@ } })(); -// $xdebug = new XdebugHandler('DEPTRAC'); -// $xdebug->check(); -// unset($xdebug); + $xdebug = new XdebugHandler('DEPTRAC'); + $xdebug->check(); + unset($xdebug); (new Application())->run(); From 322adfba4df59d4f39d629d65c0f0aaf49a63964 Mon Sep 17 00:00:00 2001 From: Gennadi McKelvey Date: Fri, 20 Jan 2023 15:05:54 +0100 Subject: [PATCH 34/39] fix rebase --- deptrac.php | 6 +++--- src/Contract/Config/DeptracConfig.php | 4 ++++ src/Core/Analyser/TokenInLayerAnalyser.php | 1 + src/Core/Analyser/UnassignedTokenAnalyser.php | 1 + 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/deptrac.php b/deptrac.php index f7855b840..8e339eb01 100755 --- a/deptrac.php +++ b/deptrac.php @@ -20,8 +20,8 @@ } })(); - $xdebug = new XdebugHandler('DEPTRAC'); - $xdebug->check(); - unset($xdebug); +$xdebug = new XdebugHandler('DEPTRAC'); +$xdebug->check(); +unset($xdebug); (new Application())->run(); diff --git a/src/Contract/Config/DeptracConfig.php b/src/Contract/Config/DeptracConfig.php index 3027d8523..ae062473f 100644 --- a/src/Contract/Config/DeptracConfig.php +++ b/src/Contract/Config/DeptracConfig.php @@ -37,6 +37,10 @@ public function analysers(EmitterType ...$types): self return $this; } + /** + * @param string $baseline + * @return $this + */ public function baseline(string $baseline): self { /** @var array>> $baselineAsArray */ diff --git a/src/Core/Analyser/TokenInLayerAnalyser.php b/src/Core/Analyser/TokenInLayerAnalyser.php index b8cd45f56..f66add150 100644 --- a/src/Core/Analyser/TokenInLayerAnalyser.php +++ b/src/Core/Analyser/TokenInLayerAnalyser.php @@ -5,6 +5,7 @@ namespace Qossmic\Deptrac\Core\Analyser; use Qossmic\Deptrac\Contract\Ast\CouldNotParseFileException; +use Qossmic\Deptrac\Contract\Config\EmitterType; use Qossmic\Deptrac\Contract\Layer\InvalidCollectorDefinitionException; use Qossmic\Deptrac\Contract\Layer\InvalidLayerDefinitionException; use Qossmic\Deptrac\Core\Ast\AstException; diff --git a/src/Core/Analyser/UnassignedTokenAnalyser.php b/src/Core/Analyser/UnassignedTokenAnalyser.php index 05c6a33c5..ddaeda31e 100644 --- a/src/Core/Analyser/UnassignedTokenAnalyser.php +++ b/src/Core/Analyser/UnassignedTokenAnalyser.php @@ -5,6 +5,7 @@ namespace Qossmic\Deptrac\Core\Analyser; use Qossmic\Deptrac\Contract\Ast\CouldNotParseFileException; +use Qossmic\Deptrac\Contract\Config\EmitterType; use Qossmic\Deptrac\Contract\Layer\InvalidCollectorDefinitionException; use Qossmic\Deptrac\Contract\Layer\InvalidLayerDefinitionException; use Qossmic\Deptrac\Core\Ast\AstException; From c5eeff3461579bf1c8b7115fc8350223efdaa8fe Mon Sep 17 00:00:00 2001 From: Gennadi McKelvey Date: Fri, 20 Jan 2023 15:09:05 +0100 Subject: [PATCH 35/39] add throws ParseException --- src/Contract/Config/DeptracConfig.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Contract/Config/DeptracConfig.php b/src/Contract/Config/DeptracConfig.php index ae062473f..d622ea326 100644 --- a/src/Contract/Config/DeptracConfig.php +++ b/src/Contract/Config/DeptracConfig.php @@ -6,6 +6,7 @@ use Qossmic\Deptrac\Contract\Config\Formatter\FormatterConfigInterface; use Symfony\Component\Config\Builder\ConfigBuilderInterface; +use Symfony\Component\Yaml\Exception\ParseException; use Symfony\Component\Yaml\Yaml; final class DeptracConfig implements ConfigBuilderInterface @@ -38,8 +39,7 @@ public function analysers(EmitterType ...$types): self } /** - * @param string $baseline - * @return $this + * @throws ParseException */ public function baseline(string $baseline): self { From 789c7f37affaa02b02798cd755c1aa5ef8717d1f Mon Sep 17 00:00:00 2001 From: Gennadi McKelvey Date: Fri, 20 Jan 2023 15:25:02 +0100 Subject: [PATCH 36/39] fix deptrac.config.php and cleanup yaml version --- config/services.php | 57 +++++++------------ deptrac.baseline.yaml | 10 ++-- deptrac.config.php | 6 +- deptrac.config.yaml | 8 +-- .../DependencyInjection/Configuration.php | 1 + .../DeptracExtensionTest.php | 2 +- 6 files changed, 28 insertions(+), 56 deletions(-) diff --git a/config/services.php b/config/services.php index 53315b884..3d56a79a6 100644 --- a/config/services.php +++ b/config/services.php @@ -238,84 +238,65 @@ $services->alias(CollectorResolverInterface::class, CollectorResolver::class); $services ->set(AttributeCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_ATTRIBUTE->value]) - ->tag('collector', ['type' => AttributeCollector::class]); + ->tag('collector', ['type' => CollectorType::TYPE_ATTRIBUTE->value]); $services ->set(BoolCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_BOOL->value]) - ->tag('collector', ['type' => BoolCollector::class]); + ->tag('collector', ['type' => CollectorType::TYPE_BOOL->value]); $services ->set(ClassCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_CLASS->value]) - ->tag('collector', ['type' => ClassCollector::class]); + ->tag('collector', ['type' => CollectorType::TYPE_CLASS->value]); $services ->set(ClassLikeCollector::class) ->tag('collector', ['type' => CollectorType::TYPE_CLASSLIKE->value]) - ->tag('collector', ['type' => CollectorType::TYPE_CLASS_NAME->value]) - ->tag('collector', ['type' => ClassLikeCollector::class]); + ->tag('collector', ['type' => CollectorType::TYPE_CLASS_NAME->value]); $services ->set(ClassNameRegexCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_CLASS_NAME_REGEX->value]) - ->tag('collector', ['type' => ClassNameRegexCollector::class]); + ->tag('collector', ['type' => CollectorType::TYPE_CLASS_NAME_REGEX->value]); $services ->set(DirectoryCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_DIRECTORY->value]) - ->tag('collector', ['type' => DirectoryCollector::class]); + ->tag('collector', ['type' => CollectorType::TYPE_DIRECTORY->value]); $services ->set(ExtendsCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_EXTENDS->value]) - ->tag('collector', ['type' => ExtendsCollector::class]); + ->tag('collector', ['type' => CollectorType::TYPE_EXTENDS->value]); $services ->set(FunctionNameCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_FUNCTION_NAME->value]) - ->tag('collector', ['type' => FunctionNameCollector::class]); + ->tag('collector', ['type' => CollectorType::TYPE_FUNCTION_NAME->value]); $services ->set(GlobCollector::class) ->args([ '$basePath' => param('projectDirectory'), ]) - ->tag('collector', ['type' => CollectorType::TYPE_GLOB->value]) - ->tag('collector', ['type' => GlobCollector::class]); + ->tag('collector', ['type' => CollectorType::TYPE_GLOB->value]); $services ->set(ImplementsCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_IMPLEMENTS->value]) - ->tag('collector', ['type' => ImplementsCollector::class]); + ->tag('collector', ['type' => CollectorType::TYPE_IMPLEMENTS->value]); $services ->set(InheritanceLevelCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_INHERITANCE->value]) - ->tag('collector', ['type' => InheritanceLevelCollector::class]); + ->tag('collector', ['type' => CollectorType::TYPE_INHERITANCE->value]); $services ->set(InterfaceCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_INTERFACE->value]) - ->tag('collector', ['type' => InterfaceCollector::class]); + ->tag('collector', ['type' => CollectorType::TYPE_INTERFACE->value]); $services ->set(InheritsCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_INHERITS->value]) - ->tag('collector', ['type' => InheritsCollector::class]); + ->tag('collector', ['type' => CollectorType::TYPE_INHERITS->value]); $services ->set(LayerCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_LAYER->value]) - ->tag('collector', ['type' => LayerCollector::class]); + ->tag('collector', ['type' => CollectorType::TYPE_LAYER->value]); $services ->set(MethodCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_METHOD->value]) - ->tag('collector', ['type' => MethodCollector::class]); + ->tag('collector', ['type' => CollectorType::TYPE_METHOD->value]); $services ->set(SuperglobalCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_SUPERGLOBAL->value]) - ->tag('collector', ['type' => SuperglobalCollector::class]); + ->tag('collector', ['type' => CollectorType::TYPE_SUPERGLOBAL->value]); $services ->set(TraitCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_TRAIT->value]) - ->tag('collector', ['type' => TraitCollector::class]); + ->tag('collector', ['type' => CollectorType::TYPE_TRAIT->value]); $services ->set(UsesCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_USES->value]) - ->tag('collector', ['type' => UsesCollector::class]); + ->tag('collector', ['type' => CollectorType::TYPE_USES->value]); $services ->set(PhpInternalCollector::class) - ->tag('collector', ['type' => CollectorType::TYPE_PHP_INTERNAL->value]) - ->tag('collector', ['type' => PhpInternalCollector::class]); + ->tag('collector', ['type' => CollectorType::TYPE_PHP_INTERNAL->value]); /* * Analyser diff --git a/deptrac.baseline.yaml b/deptrac.baseline.yaml index cdefc1909..4c37a358d 100644 --- a/deptrac.baseline.yaml +++ b/deptrac.baseline.yaml @@ -1,8 +1,6 @@ deptrac: skip_violations: - Qossmic\Deptrac\Core\Analyser\TokenInLayerAnalyser: - - Qossmic\Deptrac\Supportive\DependencyInjection\EmitterType - Qossmic\Deptrac\Core\Analyser\TokenType: - - Qossmic\Deptrac\Supportive\DependencyInjection\EmitterType - Qossmic\Deptrac\Core\Analyser\UnassignedTokenAnalyser: - - Qossmic\Deptrac\Supportive\DependencyInjection\EmitterType + Qossmic\Deptrac\Core\Ast\Parser\Cache\AstFileReferenceFileCache: + - Qossmic\Deptrac\Supportive\File\Exception\CouldNotReadFileException + Qossmic\Deptrac\Core\Ast\Parser\NikicPhpParser\NikicPhpParser: + - Qossmic\Deptrac\Supportive\File\Exception\CouldNotReadFileException diff --git a/deptrac.config.php b/deptrac.config.php index 587ae61eb..6ebe762fe 100755 --- a/deptrac.config.php +++ b/deptrac.config.php @@ -1,7 +1,6 @@ services(); $services->set(IgnoreDependenciesOnContract::class)->tag('kernel.event_listener', ['event' => ProcessEvent::class]); - $services->set(IgnoreDependenciesOnShouldNotHappenException::class)->tag( - 'kernel.event_listener', - ['event' => ProcessEvent::class] - ); $config + ->baseline('deptrac.baseline.yaml') ->paths('src') ->analysers( EmitterType::CLASS_TOKEN, diff --git a/deptrac.config.yaml b/deptrac.config.yaml index 94aeb094b..8c76ba57e 100644 --- a/deptrac.config.yaml +++ b/deptrac.config.yaml @@ -1,4 +1,6 @@ imports: + - deptrac.baseline.yaml + services: - class: Internal\Qossmic\Deptrac\IgnoreDependenciesOnContract tags: @@ -111,19 +113,13 @@ deptrac: - File Dependency: - Ast -# Result: -# - Dependency Analyser: -# - Result - Layer - Dependency - Ast OutputFormatter: -# - Result - Console - DependencyInjection -# Events: -# - Result Ast: - File - InputCollector diff --git a/src/Supportive/DependencyInjection/Configuration.php b/src/Supportive/DependencyInjection/Configuration.php index d376c7464..f948ccc26 100644 --- a/src/Supportive/DependencyInjection/Configuration.php +++ b/src/Supportive/DependencyInjection/Configuration.php @@ -78,6 +78,7 @@ private function appendLayers(ArrayNodeDefinition $node): void $node ->children() ->arrayNode('layers') + ->useAttributeAsKey('name', false) ->arrayPrototype() ->children() ->scalarNode('name') diff --git a/tests/Supportive/DependencyInjection/DeptracExtensionTest.php b/tests/Supportive/DependencyInjection/DeptracExtensionTest.php index a40908bf4..bac7bb420 100644 --- a/tests/Supportive/DependencyInjection/DeptracExtensionTest.php +++ b/tests/Supportive/DependencyInjection/DeptracExtensionTest.php @@ -204,7 +204,7 @@ public function testLayers(): void self::assertSame( [ - 0 => [ + 'test' => [ 'name' => 'test', 'collectors' => [ [ From 986a59425833018ba94e3f186a6e961ebb183f1d Mon Sep 17 00:00:00 2001 From: Gennadi McKelvey Date: Fri, 20 Jan 2023 15:42:29 +0100 Subject: [PATCH 37/39] cleanup ServiceContainerBuilder enforce container to load php config --- src/Supportive/DependencyInjection/ServiceContainerBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Supportive/DependencyInjection/ServiceContainerBuilder.php b/src/Supportive/DependencyInjection/ServiceContainerBuilder.php index c1d066d43..42e5c4c0a 100644 --- a/src/Supportive/DependencyInjection/ServiceContainerBuilder.php +++ b/src/Supportive/DependencyInjection/ServiceContainerBuilder.php @@ -161,7 +161,7 @@ private static function loadConfiguration(ContainerBuilder $container, SplFileIn $loader = new DelegatingLoader(new LoaderResolver([ new YamlFileLoader($container, new FileLocator([$configPathInfo->getPathname()])), - new PhpFileLoader($container, new FileLocator([$configPathInfo->getPathname()]), generator: new ConfigBuilderGenerator('./src/Supportive/Config/')), + new PhpFileLoader($container, new FileLocator([$configPathInfo->getPathname()]), generator: new ConfigBuilderGenerator('.')), ])); try { From 30d4d9f8e24879ef9a452c22f80e1204da8a52c6 Mon Sep 17 00:00:00 2001 From: Gennadi McKelvey Date: Fri, 20 Jan 2023 15:50:17 +0100 Subject: [PATCH 38/39] remove duplicate method --- src/Contract/Config/ConfigurableCollectorConfig.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/Contract/Config/ConfigurableCollectorConfig.php b/src/Contract/Config/ConfigurableCollectorConfig.php index a48f35c72..82ad996f8 100644 --- a/src/Contract/Config/ConfigurableCollectorConfig.php +++ b/src/Contract/Config/ConfigurableCollectorConfig.php @@ -104,13 +104,6 @@ public static function create(string $config): self return new static(self::regex($config)); } - public function private(): self - { - $this->private = true; - - return $this; - } - /** * @return array{private: bool, type: string, value: string} */ From 94af79f21c18c8eea7f6613d88d7c6a64b2faac0 Mon Sep 17 00:00:00 2001 From: Gennadi McKelvey Date: Fri, 31 Mar 2023 14:31:58 +0200 Subject: [PATCH 39/39] cleanup --- config/services.php | 2 +- deptrac.baseline.yaml | 6 ------ deptrac.config.php | 1 - deptrac.config.yaml => deptrac.yaml | 3 --- src/Supportive/DependencyInjection/Configuration.php | 2 +- 5 files changed, 2 insertions(+), 12 deletions(-) delete mode 100644 deptrac.baseline.yaml rename deptrac.config.yaml => deptrac.yaml (98%) diff --git a/config/services.php b/config/services.php index 3d56a79a6..754c527a6 100644 --- a/config/services.php +++ b/config/services.php @@ -7,9 +7,9 @@ use PhpParser\ParserFactory; use Psr\EventDispatcher\EventDispatcherInterface; use Qossmic\Deptrac\Contract\Analyser\EventHelper; -use Qossmic\Deptrac\Contract\Layer\LayerProvider; 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; use Qossmic\Deptrac\Core\Analyser\EventHandler\DependsOnDisallowedLayer; diff --git a/deptrac.baseline.yaml b/deptrac.baseline.yaml deleted file mode 100644 index 4c37a358d..000000000 --- a/deptrac.baseline.yaml +++ /dev/null @@ -1,6 +0,0 @@ -deptrac: - skip_violations: - Qossmic\Deptrac\Core\Ast\Parser\Cache\AstFileReferenceFileCache: - - Qossmic\Deptrac\Supportive\File\Exception\CouldNotReadFileException - Qossmic\Deptrac\Core\Ast\Parser\NikicPhpParser\NikicPhpParser: - - Qossmic\Deptrac\Supportive\File\Exception\CouldNotReadFileException diff --git a/deptrac.config.php b/deptrac.config.php index 6ebe762fe..e4f366942 100755 --- a/deptrac.config.php +++ b/deptrac.config.php @@ -17,7 +17,6 @@ $services->set(IgnoreDependenciesOnContract::class)->tag('kernel.event_listener', ['event' => ProcessEvent::class]); $config - ->baseline('deptrac.baseline.yaml') ->paths('src') ->analysers( EmitterType::CLASS_TOKEN, diff --git a/deptrac.config.yaml b/deptrac.yaml similarity index 98% rename from deptrac.config.yaml rename to deptrac.yaml index 8c76ba57e..4afdc891c 100644 --- a/deptrac.config.yaml +++ b/deptrac.yaml @@ -1,6 +1,3 @@ -imports: - - deptrac.baseline.yaml - services: - class: Internal\Qossmic\Deptrac\IgnoreDependenciesOnContract tags: diff --git a/src/Supportive/DependencyInjection/Configuration.php b/src/Supportive/DependencyInjection/Configuration.php index f948ccc26..9a567f540 100644 --- a/src/Supportive/DependencyInjection/Configuration.php +++ b/src/Supportive/DependencyInjection/Configuration.php @@ -5,8 +5,8 @@ namespace Qossmic\Deptrac\Supportive\DependencyInjection; use InvalidArgumentException; -use RuntimeException; use Qossmic\Deptrac\Contract\Config\EmitterType; +use RuntimeException; use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\ConfigurationInterface;