ErrorHandlerController   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 52
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 52
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A catchAll() 0 35 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 that provides a page with
20
     * error information, using the default page layout.
21
     *
22
     * @param string $message with details.
0 ignored issues
show
Bug introduced by
There is no parameter named $message. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
23
     *
24
     * @throws Anax\Route\Exception\NotFoundException
25
26
     * @return object as the response.
27
     */
28
    public function catchAll(...$args) : object
0 ignored issues
show
Unused Code introduced by
The parameter $args is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
29
    {
30
        $pages = [
31
            "403" => [
32
                "403: Forbidden",
33
                "You are not permitted to do this."
34
            ],
35
            "404" => [
36
                "404: Not Found",
37
                "The page you are looking for is not here."
38
            ],
39
            "500" => [
40
                "500: Internal Server Error",
41
                "An unexpected condition was encountered."
42
            ],
43
        ];
44
45
        $path = $this->di->get("router")->getMatchedPath();
46
        if (!array_key_exists($path, $pages)) {
47
            throw new NotFoundException("Internal route for '$path' is not found.");
48
        }
49
50
        $page = $this->di->get("page");
51
        $page->add(
52
            "anax/v2/error/default",
53
            [
54
                "header" => $pages[$path][0],
55
                "text" => $pages[$path][1],
56
            ]
57
        );
58
59
        return $page->render([
60
            "title" => $pages[$path][0]
61
        ], $path);
62
    }
63
}
64