Conditions | 8 |
Paths | 14 |
Total Lines | 32 |
Code Lines | 21 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 72 |
Changes | 0 |
1 | <?php |
||
17 | public function handle(array $headers, array $payload, bool $isPreview = false): array |
||
18 | { |
||
19 | if (! isset($headers['x-contentful-topic'])) { |
||
20 | return $this->response('Page not found', 404); |
||
21 | } |
||
22 | |||
23 | $topics = explode('.', $headers['x-contentful-topic'][0]); |
||
24 | if ($topics[0] !== 'ContentManagement') { |
||
25 | return $this->response('Page not found', 404); |
||
26 | } |
||
27 | |||
28 | switch ($topics[1]) { |
||
29 | case 'Asset': |
||
30 | $handler = new AssetHandler; |
||
31 | break; |
||
32 | case 'Entry': |
||
33 | $handler = new EntryHandler; |
||
34 | break; |
||
35 | case 'ContentType': |
||
36 | default: |
||
37 | $handler = null; |
||
38 | } |
||
39 | |||
40 | if (! empty($handler)) { |
||
41 | try { |
||
42 | $handler->handle($topics[2], $payload, $isPreview); |
||
43 | } catch (Exception $e) { |
||
44 | return $this->response($e->getMessage(), 500); |
||
45 | } |
||
46 | } |
||
47 | |||
48 | return $this->response(); |
||
49 | } |
||
66 |