Conditions | 6 |
Paths | 7 |
Total Lines | 26 |
Lines | 0 |
Ratio | 0 % |
Tests | 13 |
CRAP Score | 6.0852 |
Changes | 0 |
1 | <?php |
||
43 | 3 | protected function buildRouter(ServerRequestInterface $request): Router |
|
44 | { |
||
45 | 3 | if (true === $this->cacheEnabled && file_exists($this->cacheFile)) { |
|
46 | 3 | $cache = file_get_contents($this->cacheFile); |
|
47 | 3 | $router = u($cache, ['allowed_classes' => true]); |
|
48 | |||
49 | 3 | if ($router instanceof Router) { |
|
50 | 3 | return $router; |
|
51 | } |
||
52 | } |
||
53 | |||
54 | 3 | $builder = $this->builder; |
|
55 | 3 | $router = $builder(new Router()); |
|
56 | |||
57 | 3 | if (false === $this->cacheEnabled) { |
|
58 | return $router; |
||
59 | } |
||
60 | |||
61 | 3 | if ($router instanceof Router) { |
|
62 | 3 | $router->prepareRoutes($request); |
|
63 | 3 | file_put_contents($this->cacheFile, s($router)); |
|
64 | 3 | return $router; |
|
65 | } |
||
66 | |||
67 | throw new InvalidArgumentException('Invalid Router builder provided to cached router'); |
||
68 | } |
||
69 | } |
||
70 |