Conditions | 3 |
Paths | 4 |
Total Lines | 18 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Tests | 8 |
CRAP Score | 3.072 |
Changes | 0 |
1 | <?php |
||
12 | 6 | public function __invoke(ServerRequestInterface $req, array $params, Application $app) |
|
13 | { |
||
14 | // do not allow dangerous path chars |
||
15 | 6 | $document = str_replace(['..', '*', '?', './'], '_', $params['document']); |
|
16 | 6 | $index_filename = $app->getConfig('content_path') . '/' . $document . '/index.md'; |
|
17 | |||
18 | 6 | if (file_exists($index_filename)) { |
|
19 | $filename = $index_filename; |
||
20 | } else { |
||
21 | 6 | $filename = $app->getConfig('content_path') . '/' . $document . '.md'; |
|
22 | } |
||
23 | |||
24 | try { |
||
25 | 6 | return $app->get('markdown.page', [$filename]); |
|
26 | 3 | } catch (FileNotFoundException $e) { |
|
27 | 3 | throw HttpErrorException::create(404); |
|
28 | } |
||
29 | } |
||
30 | } |
||
31 |