Issues (122)

src/Controller/ErrorHandlerController.php (1 issue)

Severity
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
 * @SuppressWarnings(PHPMD)
12
 */
13
class ErrorHandlerController implements ContainerInjectableInterface
14
{
15
    use ContainerInjectableTrait;
16
17
18
19
    /**
20
     * Add internal routes for 403, 404 and 500 that provides a page with
21
     * error information, using the default page layout.
22
     *
23
     * @param string $message with details.
24
     *
25
     * @throws Anax\Route\Exception\NotFoundException
26
27
     * @return object as the response.
28
     */
29
    public function catchAll(...$args) : object
0 ignored issues
show
The parameter $args is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

29
    public function catchAll(/** @scrutinizer ignore-unused */ ...$args) : object

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

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