Skip to content

Commit e0b4d28

Browse files
committed
improve constructor
1 parent de433e3 commit e0b4d28

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/MetadataHydrator.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
use Patchlevel\Hydrator\Metadata\ClassNotFound;
1414
use Patchlevel\Hydrator\Metadata\MetadataFactory;
1515
use Patchlevel\Hydrator\Normalizer\HydratorAwareNormalizer;
16-
use Psr\EventDispatcher\EventDispatcherInterface;
1716
use ReflectionParameter;
1817
use Symfony\Component\EventDispatcher\EventDispatcher;
18+
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
1919
use Throwable;
2020
use TypeError;
2121

@@ -29,22 +29,22 @@ final class MetadataHydrator implements Hydrator
2929
/** @var array<int, class-string> */
3030
private array $stack = [];
3131

32-
private readonly EventDispatcherInterface|null $eventDispatcher;
33-
3432
public function __construct(
3533
private readonly MetadataFactory $metadataFactory = new AttributeMetadataFactory(),
36-
PayloadCryptographer|EventDispatcherInterface|null $cryptographer = null,
34+
PayloadCryptographer|null $cryptographer = null,
35+
private EventDispatcherInterface|null $eventDispatcher = null,
3736
) {
38-
if ($cryptographer === null) {
39-
$this->eventDispatcher = null;
40-
} elseif ($cryptographer instanceof EventDispatcherInterface) {
41-
$this->eventDispatcher = $cryptographer;
42-
} else {
37+
if (!$cryptographer) {
38+
return;
39+
}
40+
41+
if (!$this->eventDispatcher) {
4342
$this->eventDispatcher = new EventDispatcher();
44-
$this->eventDispatcher->addSubscriber(
45-
new CryptographySubscriber($cryptographer),
46-
);
4743
}
44+
45+
$this->eventDispatcher->addSubscriber(
46+
new CryptographySubscriber($cryptographer),
47+
);
4848
}
4949

5050
/**

0 commit comments

Comments
 (0)