Skip to content

Commit

Permalink
add method ReferenceRepository::ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
MartkCz committed Nov 4, 2021
1 parent ef04fd8 commit ade7e8f
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/Reference/ReferenceRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace WebChemistry\Fixtures\Reference;

use BadMethodCallException;
use LogicException;
use OutOfBoundsException;
use WeakMap;
use WebChemistry\Fixtures\Utility\Range;

final class ReferenceRepository
Expand All @@ -15,8 +17,19 @@ final class ReferenceRepository
/** @var mixed[] */
private array $processed = [];

private WeakMap $ignores;

public function __construct()
{
$this->ignores = new WeakMap();
}

public function setReference(string $name, object $reference): object
{
if (isset($this->ignores[$reference])) {
throw new LogicException(sprintf('Given object is ignored.'));
}

return $this->references[$reference::class][$name] = $reference;
}

Expand All @@ -39,6 +52,10 @@ public function addReference(string $name, object $object): object
*/
public function addProcessed(object $object): object
{
if (isset($this->ignores[$object])) {
return $object;
}

$this->processed[$object::class][] = $object;

return $object;
Expand All @@ -64,6 +81,18 @@ public function hasReference(string $className, string $name): bool
return isset($this->references[$className][$name]);
}

/**
* @template T of object
* @param T $object
* @return T
*/
public function ignore(object $object): object
{
$this->ignores[$object] = true;

return $object;
}

/**
* @template T of object
* @param class-string<T> $className
Expand Down

0 comments on commit ade7e8f

Please sign in to comment.