Skip to content

Commit

Permalink
Throw exception in the getter
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet authored and OskarStark committed Apr 11, 2021
1 parent dd90adc commit 84c87f8
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/Model/AuditManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,6 @@ public function __construct(ContainerInterface $container)

public function setReader(string $serviceId, array $classes): void
{
$reader = $this->container->get($serviceId);
if (!$reader instanceof AuditReaderInterface) {
throw new \InvalidArgumentException(sprintf(
'Service "%s" MUST implement interface "%s".',
$serviceId,
AuditReaderInterface::class,
));
}

$this->readers[$serviceId] = $classes;
}

Expand All @@ -66,7 +57,13 @@ public function getReader(string $class): AuditReaderInterface
foreach ($this->readers as $readerId => $classes) {
if (\in_array($class, $classes, true)) {
$reader = $this->container->get($readerId);
\assert($reader instanceof AuditReaderInterface);
if (!$reader instanceof AuditReaderInterface) {
throw new \LogicException(sprintf(
'Service "%s" MUST implement interface "%s".',
$readerId,
AuditReaderInterface::class,
));
}

return $reader;
}
Expand Down

0 comments on commit 84c87f8

Please sign in to comment.