Skip to content

Commit

Permalink
cs
Browse files Browse the repository at this point in the history
  • Loading branch information
tenmajkl committed Jun 23, 2023
1 parent 74c88be commit b12dc26
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/Lemon/DataMapper/DataMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ public static function typeCheck(mixed $value, ReflectionType $type): Maybe
{
$type_name = trim((string) $type, '?');
if (class_exists($type_name)) {
if ($type->allowsNull() && $value === null) {
if ($type->allowsNull() && null === $value) {
return Maybe::just(null);
}

if (!is_array($value)) {
return Maybe::nothing();
}
}

return ($v = static::mapTo($value, $type_name)) === null ? Maybe::nothing() : Maybe::just($v);
}

if (!$type->allowsNull() && $value === null) {
if (!$type->allowsNull() && null === $value) {
return Maybe::nothing();
}

Expand Down
6 changes: 4 additions & 2 deletions tests/Http/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,17 @@ public function testValidationSuccess()
public function testMustBe(): void
{
$r = new Request('/', '', 'GET', ['Content-Type' => 'application/json'], '{"foo":10}', [], [], '');
$f = new \Fiber(function(Request $r) {
$f = new \Fiber(function (Request $r) {
$r->mustBe('application/parek', 'foo');

return 'bar';
});

$this->assertSame('foo', $f->start($r));

$f = new \Fiber(function(Request $r) {
$f = new \Fiber(function (Request $r) {
$r->mustBe('application/json', 'foo');

return 'bar';
});

Expand Down

0 comments on commit b12dc26

Please sign in to comment.