ErrorController::exception()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
ccs 8
cts 8
cp 1
rs 9.4285
cc 2
eloc 7
nc 2
nop 1
crap 2
1
<?php
2
namespace Nkey\Caribu\Mvc\Controller;
3
4
use Generics\Client\HttpStatus;
5
6
/**
7
 * The error controller
8
 *
9
 * The error controller provides the fallback rendering if some request
10
 * could not be routed correctly.
11
 *
12
 * It will be registered in application as soon as the Application::init()
13
 * function is performed.
14
 *
15
 * @author Maik Greubel <[email protected]>
16
 *
17
 *         This file is part of Caribu MVC package
18
 */
19
class ErrorController extends AbstractController
20
{
21
22
    /**
23
     * Error processing method
24
     *
25
     * @param Request $request
26
     *            The request
27
     */
28 4
    public function error(Request $request)
29
    {
30 4
        $this->response->setCode(404);
31 4
        printf("<h2>%s</h2>", HttpStatus::getStatus(404));
32 4
        printf("Requested document %s on %s could not be found!", $request->getAction(), $request->getController());
33 4
    }
34
35
    /**
36
     * Error processing for exceptions
37
     *
38
     * @param Request $request
39
     *            The request which contains an exception
40
     */
41 1
    public function exception(Request $request)
42
    {
43 1
        $ex = $request->getException();
44
        
45 1
        $this->response->setCode(500);
46 1
        printf("<h2>%s</h2>", HttpStatus::getStatus(500));
47 1
        while ($ex != null) {
48 1
            printf("<h3>%s</h3><pre>%s</pre>", $ex->getMessage(), $ex->getTraceAsString());
49 1
            $ex = $ex->getPrevious();
50
        }
51 1
    }
52
}
53