Skip to content

Commit

Permalink
fix deptrac.config.php
Browse files Browse the repository at this point in the history
  • Loading branch information
Gennadi McKelvey committed Dec 6, 2022
1 parent 2826f9e commit 3558b0b
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 45 deletions.
35 changes: 17 additions & 18 deletions deptrac.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
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;

Expand Down Expand Up @@ -38,9 +38,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/.*')
Expand All @@ -62,27 +62,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()
Expand All @@ -91,6 +91,5 @@
->groups('Supportive', $supportive, $file)
->groups('Symfony', $console, $dependencyInjection, $outputFormatter)
->groups('Core', $analyser, $ast, $dependency, $inputCollector, $layer)
)
;
);
};
2 changes: 1 addition & 1 deletion src/Contract/Config/CollectorConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
abstract class CollectorConfig
{
protected bool $private = false;
protected CollectorType $collectorType;
protected CollectorType $collectorType = CollectorType::TYPE_DIRECTORY;

public function private(): self
{
Expand Down
2 changes: 0 additions & 2 deletions src/Contract/Config/ConfigurableCollectorConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ abstract class ConfigurableCollectorConfig extends CollectorConfig
'\\P',
];

protected CollectorType $collectorType;

final protected function __construct(
protected string $config,
) {
Expand Down
14 changes: 7 additions & 7 deletions src/Contract/Config/DeptracConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ final class DeptracConfig implements ConfigBuilderInterface

/** @var array<string> */
private array $paths = [];
/** @var array<LayerConfig> */
/** @var array<Layer> */
private array $layers = [];
/** @var array<FormatterConfigInterface> */
private array $formatters = [];
/** @var array<RulesetConfig> */
/** @var array<Ruleset> */
private array $rulesets = [];
/** @var array<string, \Qossmic\Deptrac\Contract\Config\EmitterType> */
/** @var array<string, EmitterType> */
private array $analyser = [];
/** @var array<string, array<string>> */
private array $skipViolations = [];
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
14 changes: 7 additions & 7 deletions src/Contract/Config/Formatter/GraphvizConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, LayerConfig[]> */
/** @var array<string, Layer[]> */
private array $groups = [];

private function __construct()
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Qossmic\Deptrac\Contract\Config;

final class LayerConfig
final class Layer
{
/** @var array<CollectorConfig> */
private array $collectors = [];
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@

namespace Qossmic\Deptrac\Contract\Config;

final class RulesetConfig
final class Ruleset
{
public LayerConfig $layerConfig;
public Layer $layerConfig;

/** @var array<LayerConfig> */
/** @var array<Layer> */
private array $accessableLayers = [];

/** @param array<LayerConfig> $layerConfigs */
public function __construct(LayerConfig $layerConfig, array $layerConfigs)
/** @param array<Layer> $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;
Expand All @@ -35,7 +35,7 @@ public function accesses(LayerConfig ...$layerConfigs): self
/** @return non-empty-array<array-key, string> */
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];
}
Expand Down

0 comments on commit 3558b0b

Please sign in to comment.