Skip to content

Commit

Permalink
cleanup collector creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Gennadi McKelvey committed Nov 27, 2022
1 parent 11d63b8 commit effcb98
Show file tree
Hide file tree
Showing 23 changed files with 73 additions and 205 deletions.
34 changes: 17 additions & 17 deletions deptrac.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
10 changes: 1 addition & 9 deletions src/Contract/Config/Collector/AttributeConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
22 changes: 13 additions & 9 deletions src/Contract/Config/Collector/BoolConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,24 @@
use Qossmic\Deptrac\Contract\Config\CollectorConfig;
use Qossmic\Deptrac\Contract\Config\CollectorType;

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

private function __construct(
private bool $private,
) {
}

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

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

public static function public(): self
{
return new self(collectorType: CollectorType::TYPE_BOOL, private: false);
}

public static function private(): self
public static function create(bool $private = false): self
{
return new self(collectorType: CollectorType::TYPE_BOOL, private: true);
return new self($private);
}

public function withMustNot(CollectorConfig $CollectorConfig): self
Expand All @@ -45,9 +47,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,
];
}
}
10 changes: 1 addition & 9 deletions src/Contract/Config/Collector/ClassConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
10 changes: 1 addition & 9 deletions src/Contract/Config/Collector/ClassLikeConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
10 changes: 1 addition & 9 deletions src/Contract/Config/Collector/ClassNameConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
10 changes: 1 addition & 9 deletions src/Contract/Config/Collector/DirectoryConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
10 changes: 1 addition & 9 deletions src/Contract/Config/Collector/ExtendsConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
10 changes: 1 addition & 9 deletions src/Contract/Config/Collector/FunctionNameConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
10 changes: 1 addition & 9 deletions src/Contract/Config/Collector/GlobConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
10 changes: 1 addition & 9 deletions src/Contract/Config/Collector/ImplementsConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
10 changes: 1 addition & 9 deletions src/Contract/Config/Collector/InheritsConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
10 changes: 1 addition & 9 deletions src/Contract/Config/Collector/InterfaceConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
10 changes: 1 addition & 9 deletions src/Contract/Config/Collector/LayerConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
10 changes: 1 addition & 9 deletions src/Contract/Config/Collector/MethodConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
10 changes: 1 addition & 9 deletions src/Contract/Config/Collector/PhpInteralConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
4 changes: 2 additions & 2 deletions src/Contract/Config/Collector/SuperGlobalConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
use Qossmic\Deptrac\Contract\Config\CollectorConfig;
use Qossmic\Deptrac\Contract\Config\CollectorType;

final class SuperGlobalConfig extends CollectorConfig
final class SuperGlobalConfig implements CollectorConfig
{
/**
* @param string[] $config
*/
protected function __construct(
private function __construct(
protected array $config,
protected bool $private = false,
) {
Expand Down
10 changes: 1 addition & 9 deletions src/Contract/Config/Collector/TraitConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
10 changes: 1 addition & 9 deletions src/Contract/Config/Collector/UsesConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
20 changes: 3 additions & 17 deletions src/Contract/Config/CollectorConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,8 @@

namespace Qossmic\Deptrac\Contract\Config;

abstract class CollectorConfig
interface CollectorConfig
{
protected function __construct(
protected CollectorType $collectorType = CollectorType::TYPE_BOOL,
protected bool $private = false,
) {
}

/**
* @return array{'type': string, 'private': bool}
*/
public function toArray(): array
{
return [
'private' => $this->private,
'type' => $this->collectorType->value,
];
}
/** @return array{'type': string, 'private': bool} */
public function toArray(): array;
}
Loading

0 comments on commit effcb98

Please sign in to comment.