Passed
Push — master ( fa46b3...ce6672 )
by Ylva
05:16 queued 02:30
created

ErrorHandlerController::catchAll()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 34
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
nc 2
nop 1
dl 0
loc 34
c 1
b 0
f 0
cc 2
rs 9.584
1
<?php
2
3
namespace Anax\Controller;
4
5
use Anax\Commons\ContainerInjectableInterface;
0 ignored issues
show
Bug introduced by
The type Anax\Commons\ContainerInjectableInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Anax\Commons\ContainerInjectableTrait;
0 ignored issues
show
Bug introduced by
The type Anax\Commons\ContainerInjectableTrait was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Anax\Route\Exception\NotFoundException;
0 ignored issues
show
Bug introduced by
The type Anax\Route\Exception\NotFoundException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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.
23
     *
24
     * @throws Anax\Route\Exception\NotFoundException
25
26
     * @return object as the response.
27
     */
28
    public function catchAll(...$args) : object
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