Conditions | 2 |
Paths | 2 |
Total Lines | 17 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 6 |
Changes | 0 |
1 | <?php declare(strict_types=1); |
||
19 | public function handle(ServerRequestInterface $request): ResponseInterface |
||
20 | { |
||
21 | $contentType = $request->getHeaderLine('Accept'); |
||
22 | $parts = explode('/', $contentType, 2); |
||
23 | Assertion::count($parts, 2, "Invalid content type '$contentType'."); |
||
24 | $methodName = 'respondTo'.ucfirst($parts[1]); |
||
25 | $responseHandler = [$this, $methodName]; |
||
26 | if (!is_callable($responseHandler)) { |
||
27 | throw new RuntimeException(sprintf( |
||
28 | "Method '%s' for content type '%s' missing from '%s'.", |
||
29 | $methodName, |
||
30 | $contentType, |
||
31 | static::class |
||
32 | )); |
||
33 | } |
||
34 | |||
35 | return $responseHandler($request); |
||
36 | } |
||
38 |