feat(presets): refactors code

This commit is contained in:
Nuno Maduro
2024-06-09 22:22:46 +01:00
parent 84256aa8b9
commit ceb7244b43
7 changed files with 105 additions and 43 deletions

View File

@ -0,0 +1,54 @@
<?php
declare(strict_types=1);
namespace Pest\ArchPresets;
use Pest\Arch\Contracts\ArchExpectation;
/**
* @internal
*/
abstract class AbstractPreset
{
/**
* Creates a new preset instance.
*
* @param array<int, string> $userNamespaces
* @param array<int, ArchExpectation> $expectations
*/
final public function __construct(// @phpstan-ignore-line
protected array $userNamespaces,
protected array $expectations = [],
) {
//
}
/**
* Executes the arch preset.
*
* @internal
*/
abstract public function execute(): void;
/**
* Ignores the given "targets" or "dependencies".
*
* @param array<int, string>|string $targetsOrDependencies
*/
final public function ignoring(array|string $targetsOrDependencies): void
{
$this->expectations = array_map(
fn (ArchExpectation $expectation): \Pest\Arch\Contracts\ArchExpectation => $expectation->ignoring($targetsOrDependencies),
$this->expectations,
);
}
/**
* Flushes the expectations.
*/
final public function flush(): void
{
$this->expectations = [];
}
}