IndexController::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0185

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 5
cts 6
cp 0.8333
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 3
crap 2.0185
1
<?php
2
3
namespace Flatdown\Controllers;
4
5
use Flatdown\Application;
6
use Psr\Http\Message\ServerRequestInterface;
7
8
class IndexController
9
{
10 3
    public function __invoke(ServerRequestInterface $req, array $params, Application $app)
11
    {
12 3
        $index_filename = $app->getConfig('content_path') . '/index.md';
13
14 3
        if (file_exists($index_filename)) {
15
            return $app->get('markdown.page', [$index_filename]);
16
        } else {
17 3
            return $app->getResponse(302)
18 3
                       ->withHeader('location', $app->getConfig('base_url') . '/_index');
19
        }
20
    }
21
22 3
    public function index(ServerRequestInterface $req, array $params, Application $app)
23
    {
24 3
        $data = ['files' => $app->get('markdown.files'), 'window_title' => 'Flatdown - Index'];
25
26 3
        return $app->get('templates')->render('index', $data);
27
    }
28
29
    public function about(ServerRequestInterface $req, array $params, Application $app)
30
    {
31
        $index_filename = $app->getConfig('base_path') . '/README.md';
32
33
        return $app->get('markdown.page', [$index_filename]);
34
    }
35
}
36