IndexController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 66.67%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 28
ccs 8
cts 12
cp 0.6667
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 11 2
A index() 0 6 1
A about() 0 6 1
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