Skip to content

Commit

Permalink
Use !isset($context[$Property->getName()]) for evaluating a nullabl…
Browse files Browse the repository at this point in the history
…e property. (#23)

Co-authored-by: david_smith <[email protected]>
  • Loading branch information
zero-to-prod and david_smith authored Nov 20, 2024
1 parent 076e226 commit 2451ff1
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/DataModelHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static function mapOf(mixed $value, array $context, ?ReflectionAttribute
throw new PropertyRequiredException("Property `\${$Property->getName()}` is required.");
}

if (!$value && $Property->getType()?->allowsNull()) {
if (!isset($context[$Property->getName()]) && $Property->getType()?->allowsNull()) {
return null;
}

Expand Down Expand Up @@ -122,7 +122,7 @@ public static function pregReplace(mixed $value, array $context, ?ReflectionAttr
throw new PropertyRequiredException("Property `\${$Property->getName()}` is required.");
}

if (!$value) {
if (!isset($context[$Property->getName()])) {
return $Property->getType()?->allowsNull()
? null
: '';
Expand Down Expand Up @@ -156,7 +156,7 @@ public static function pregMatch(mixed $value, array $context, ?ReflectionAttrib
throw new PropertyRequiredException("Property `\${$Property->getName()}` is required.");
}

if (!$value && $Property->getType()?->allowsNull()) {
if (!isset($context[$Property->getName()]) && $Property->getType()?->allowsNull()) {
return null;
}

Expand Down Expand Up @@ -196,7 +196,7 @@ public static function isUrl(mixed $value, array $context, ?ReflectionAttribute
throw new PropertyRequiredException("Property `\${$Property->getName()}` is required.");
}

if (!$value && $Property->getType()?->allowsNull()) {
if (!isset($context[$Property->getName()]) && $Property->getType()?->allowsNull()) {
return null;
}

Expand Down Expand Up @@ -242,7 +242,7 @@ public static function isEmail(mixed $value, array $context, ?ReflectionAttribut
throw new PropertyRequiredException("Property `\${$Property->getName()}` is required.");
}

if (!$value && $Property->getType()?->allowsNull()) {
if (!isset($context[$Property->getName()]) && $Property->getType()?->allowsNull()) {
return null;
}

Expand Down Expand Up @@ -289,7 +289,7 @@ public static function isMultiple(mixed $value, array $context, ?ReflectionAttri
throw new PropertyRequiredException("Property `\${$Property->getName()}` is required.");
}

if (!$value && $Property->getType()?->allowsNull()) {
if (!isset($context[$Property->getName()]) && $Property->getType()?->allowsNull()) {
return null;
}

Expand Down Expand Up @@ -336,7 +336,7 @@ public static function when(mixed $value, array $context, ?ReflectionAttribute $
throw new PropertyRequiredException("Property `\${$Property->getName()}` is required.");
}

if (!$value && $Property->getType()?->allowsNull()) {
if (!isset($context[$Property->getName()]) && $Property->getType()?->allowsNull()) {
return null;
}

Expand Down

0 comments on commit 2451ff1

Please sign in to comment.