Skip to content

Commit ffb32c4

Browse files
authored
feat: Add missing value checks for migration dtos (#25)
1 parent 9dcff76 commit ffb32c4

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/IsMigrationDataTransferObject.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ trait IsMigrationDataTransferObject
1414
{
1515
use ForwardsCalls;
1616

17+
/** @var list<mixed> */
18+
private static array $missingValues = [];
19+
20+
/**
21+
* @param list<mixed> $values
22+
*/
23+
public static function treatAsMissing(array $values): void
24+
{
25+
self::$missingValues = $values;
26+
}
27+
1728
/**
1829
* @deprecated
1930
*/
@@ -127,7 +138,8 @@ protected function has(string $key): bool
127138
{
128139
$this->assertFieldExists($key);
129140

130-
return (new ReflectionProperty(static::class, $this->keyToProperty($key)))->isInitialized($this);
141+
return (new ReflectionProperty(static::class, $this->keyToProperty($key)))->isInitialized($this) &&
142+
!in_array($this->{$this->keyToProperty($key)}, self::$missingValues, true);
131143
}
132144

133145
/**

0 commit comments

Comments
 (0)