Skip to content

Commit

Permalink
docs/missing-as-null-limitations (#26)
Browse files Browse the repository at this point in the history
* Add limitations to README.md

* Add tests.

---------

Co-authored-by: david_smith <david_smith@sweetwater.com>
  • Loading branch information
zero-to-prod and david_smith authored Oct 24, 2024
1 parent af23810 commit 05cbe6a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,11 @@ $user = User::from();
echo $user->username // 'N/A'
```

### Limitations
Note that using null as a default will not work: `#[Describe(['default' => null])]`.

Use `#[Describe(['missing_as_null' => true])]` to set a null value.

## Nullable Missing Values

Set missing values to null by setting `missing_as_null => true`. This can be placed at the class or property level.
Expand All @@ -394,6 +399,10 @@ $User = User::from();
echo $User->name; // null
echo $User->age; // null
```
### Limitations
Note that using null as a default will not work: `#[Describe(['default' => null])]`.

Use `#[Describe(['missing_as_null' => true])]` to set a null value.

## Re-Mapping

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class MissingAsNullTest extends TestCase
$User = User::from();

$this->assertNull($User->name);
$this->assertEmpty($User->last_name);
$this->assertEquals(2, $User->age);
}
}
3 changes: 3 additions & 0 deletions tests/Unit/Metadata/MissingAsNullProperty/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ class User
#[Describe(['missing_as_null' => true])]
public ?string $name;

#[Describe(['default' => ''])]
public string $last_name;

#[Describe(['default' => 2])]
public ?int $age;
}

0 comments on commit 05cbe6a

Please sign in to comment.