Lines 85.71% 12 / 14
Methods 0.00% 0 / 1
Classes 0.00% 0 / 1
Name Lines Methods CRAP
 fromRequest 85.71% 12 / 14 0.00% 0 / 1 6.10
11final class AddDistrictCommandFactory
12{
13    public function fromRequest(Request $request): AddDistrictCommand
14    {
15        $parsedBody = $request->getParsedBody();
16        if (!is_array($parsedBody)) {
17            throw new HttpBadRequestException($request);
18        }
19
20        if (
21            array_key_exists("city", $parsedBody)
22            && array_key_exists("name", $parsedBody)
23            && array_key_exists("area", $parsedBody)
24            && array_key_exists("population", $parsedBody)
25        ) {
26            return new AddDistrictCommand(
27                intval($parsedBody["city"]),
28                trim($parsedBody["name"]),
29                floatval($parsedBody["area"]),
30                intval($parsedBody["population"]),
31            );
32        }
33
34        throw new HttpBadRequestException($request);
35    }
36}