ErrorController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 37
rs 10
wmc 3
lcom 1
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A statusCodeAction() 0 22 3
1
<?php
2
3
namespace Anax\MVC;
4
5
/**
6
 * Anax base class implementing Dependency Injection / Service Locator 
7
 * of the services used by the framework, using lazy loading.
8
 *
9
 */
10
class ErrorController
11
{
12
    use \Anax\DI\TInjectionAware;
13
14
15
16
   /**
17
     * Display a page for a HTTP status code.
18
     *
19
     * @param string code    status code to set the http header.
20
     * @param string message an optional message to display together with the error code.
21
     *
22
     * @return void
23
     */
24
    public function statusCodeAction($code = null, $message = null)
25
    {
26
        $codes = [
27
            403 => "403 Forbidden",
28
            404 => "404 Not Found",
29
            500 => "500 Internal Server Error",
30
        ];
31
32
        // Key being integer also (unintentionally) prevents this action from direct url usage
33
        if (!$code || !in_array($code, $codes)) {
34
            throw new \Anax\Exception\NotFoundException("Not a valid HTTP status code.");
35
        }
36
37
        $title = $codes[$code];
38
        $this->di->response->setHeader($code);
39
        $this->di->theme->setTitle($title);
40
        $this->di->views->add('default/error', [
41
            'title' => $title,
42
            'content' => $message,
43
            'details' => $this->di->flash->getMessage(),
44
        ]);
45
    }
46
}
47