Skip to content

Commit e0d22e2

Browse files
committed
early return first
1 parent b2e56c2 commit e0d22e2

2 files changed

Lines changed: 16 additions & 16 deletions

File tree

src/Normalizer/ObjectMapNormalizer.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ public function setHydrator(Hydrator $hydrator): void
4444
*/
4545
public function normalize(mixed $value, array $context): mixed
4646
{
47-
if (!$this->hydrator) {
48-
throw new MissingHydrator();
49-
}
50-
5147
if ($value === null) {
5248
return null;
5349
}
5450

51+
if (!$this->hydrator) {
52+
throw new MissingHydrator();
53+
}
54+
5555
if (!is_object($value)) {
5656
throw InvalidArgument::withWrongType(
5757
sprintf('%s|null', implode('|', array_keys($this->classToTypeMap))),
@@ -84,14 +84,14 @@ public function normalize(mixed $value, array $context): mixed
8484
*/
8585
public function denormalize(mixed $value, array $context): mixed
8686
{
87-
if (!$this->hydrator) {
88-
throw new MissingHydrator();
89-
}
90-
9187
if ($value === null) {
9288
return null;
9389
}
9490

91+
if (!$this->hydrator) {
92+
throw new MissingHydrator();
93+
}
94+
9595
if (!is_array($value)) {
9696
throw InvalidArgument::withWrongType('array<string, mixed>|null', $value);
9797
}

src/Normalizer/ObjectNormalizer.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ public function __construct(
2626
/** @param array<string, mixed> $context */
2727
public function normalize(mixed $value, array $context): mixed
2828
{
29-
if (!$this->hydrator) {
30-
throw new MissingHydrator();
31-
}
32-
3329
if ($value === null) {
3430
return null;
3531
}
3632

33+
if (!$this->hydrator) {
34+
throw new MissingHydrator();
35+
}
36+
3737
$className = $this->getClassName();
3838

3939
if (!$value instanceof $className) {
@@ -46,14 +46,14 @@ public function normalize(mixed $value, array $context): mixed
4646
/** @param array<string, mixed> $context */
4747
public function denormalize(mixed $value, array $context): object|null
4848
{
49-
if (!$this->hydrator) {
50-
throw new MissingHydrator();
51-
}
52-
5349
if ($value === null) {
5450
return null;
5551
}
5652

53+
if (!$this->hydrator) {
54+
throw new MissingHydrator();
55+
}
56+
5757
$className = $this->getClassName();
5858

5959
return $this->hydrator->hydrate($className, $value, $context);

0 commit comments

Comments
 (0)