ContentController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 21
ccs 8
cts 10
cp 0.8
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 18 3
1
<?php
2
3
namespace Flatdown\Controllers;
4
5
use Flatdown\Application;
6
use Flatdown\Exceptions\FileNotFoundException;
7
use Middlewares\HttpErrorException;
8
use Psr\Http\Message\ServerRequestInterface;
9
10
class ContentController
11
{
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