public function completeItem($id) : JsonResponse { $status = Nullable::fromValue($id)->reject('')->map('intval')->filter(P::lt(0))->flatMap(Item::class . '::findNullable')->map(function ($item) { return $item->setStateId(State::of('completed')->id)->save(); })->getOrThrow(new \RuntimeException("Item by ID {$id} not found!")); return response()->json(['status' => $status, 'id' => $id]); }
public function testLt() { $greaterThan2 = P::lt(2); $lessThan = P::flip('P::lt', 2); $lessThan2 = $lessThan(2); $this->assertFalse(P::lt(4, 2)); $this->assertTrue(P::lt(0, 2)); $this->assertTrue($lessThan2(1)); $this->assertTrue($greaterThan2(3)); }