diff --git a/src/Lemon/DataMapper/DataMapper.php b/src/Lemon/DataMapper/DataMapper.php index a44b448..64f8b8e 100644 --- a/src/Lemon/DataMapper/DataMapper.php +++ b/src/Lemon/DataMapper/DataMapper.php @@ -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(); } diff --git a/tests/Http/RequestTest.php b/tests/Http/RequestTest.php index ddf1ba2..589844f 100644 --- a/tests/Http/RequestTest.php +++ b/tests/Http/RequestTest.php @@ -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'; });