Completed
Push — master ( b8b690...4f6cf9 )
by Mikael
10:54
created

ErrorHandlerController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 50
ccs 0
cts 33
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A catchAll() 0 36 2
1
<?php
2
3
namespace Anax\Controller;
4
5
use Anax\Commons\ContainerInjectableInterface;
6
use Anax\Commons\ContainerInjectableTrait;
7
use Anax\Route\Exception\NotFoundException;
8
9
/**
10
 * A controller to ease with development and debugging information.
11
 */
12
class ErrorHandlerController implements ContainerInjectableInterface
13
{
14
    use ContainerInjectableTrait;
15
16
17
18
    /**
19
     * Add internal routes for 403, 404 and 500.
20
     *
21
     * @throws Anax\Route\Exception\NotFoundException
22
23
     * @return void
24
     */
25
    public function catchAll()
26
    {
27
        $title = " | Anax";
28
        $pages = [
29
            "403" => [
30
                "Anax 403: Forbidden",
31
                "You are not permitted to do this."
32
            ],
33
            "404" => [
34
                "Anax 404: Not Found",
35
                "The page you are looking for is not here."
36
            ],
37
            "500" => [
38
                "Anax 500: Internal Server Error",
39
                "An unexpected condition was encountered."
40
            ],
41
        ];
42
43
        $path = $this->di->get("router")->getMatchedPath();
44
        if (!array_key_exists($path, $pages)) {
45
            throw new NotFoundException("Internal route for '$path' is not found.");
46
        }
47
48
        $page = $this->di->get("page");
49
        $page->add(
50
            "anax/v2/error/default",
51
            [
52
                "header" => $pages[$path][0],
53
                "text" => $pages[$path][1],
54
            ]
55
        );
56
57
        return $page->render([
58
            "title" => $pages[$path][0] . $title
59
        ], $path); 
60
    }
61
}
62