diff --git a/src/Blueprint.php b/src/Blueprint.php index 9208d73..0384920 100644 --- a/src/Blueprint.php +++ b/src/Blueprint.php @@ -60,14 +60,14 @@ public static function make(Targets $target, Dependencies $dependencies): self */ public function expectToUse(LayerOptions $options, callable $failure): void { - AssertLocker::incrementAndLock(); - foreach ($this->target->value as $targetValue) { $targetLayer = $this->layerFactory->make($options, $targetValue); foreach ($this->dependencies->values as $dependency) { $dependencyLayer = $this->layerFactory->make($options, $dependency->value); + AssertLocker::incrementAndLock(); + try { $this->assertDoesNotDependOn($targetLayer, $dependencyLayer); } catch (ExpectationFailedException) { @@ -90,8 +90,6 @@ public function expectToUse(LayerOptions $options, callable $failure): void */ public function targeted(callable $callback, LayerOptions $options, callable $failure, callable $lineFinder): void { - AssertLocker::incrementAndLock(); - foreach ($this->target->value as $targetValue) { $targetLayer = $this->layerFactory->make($options, $targetValue); @@ -102,6 +100,8 @@ public function targeted(callable $callback, LayerOptions $options, callable $fa } } + AssertLocker::incrementAndLock(); + if ($callback($object)) { continue; } @@ -124,8 +124,6 @@ public function targeted(callable $callback, LayerOptions $options, callable $fa */ public function expectToOnlyUse(LayerOptions $options, callable $failure): void { - AssertLocker::incrementAndLock(); - foreach ($this->target->value as $targetValue) { $allowedUses = array_merge( ...array_map(fn (Layer $layer): array => array_map( @@ -142,6 +140,8 @@ public function expectToOnlyUse(LayerOptions $options, callable $failure): void $layer = $this->layerFactory->make($options, $targetValue); foreach ($layer as $object) { foreach ($object->uses as $use) { + AssertLocker::incrementAndLock(); + if (! in_array($use, $allowedUses, true)) { $failure($targetValue, $this->dependencies->__toString(), $use, $this->getUsagePathAndLines($layer, $targetValue, $use));