ErrorController   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 61
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 3

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setErrorController() 0 5 1
A getErrorController() 0 7 2
A canHandle() 0 4 1
A handle() 0 13 1
1
<?php
2
namespace FMUP\ErrorHandler\Plugin;
3
4
use FMUP\Controller\Error;
5
use FMUP\Exception;
6
7
/**
8
 * Class ErrorController
9
 * @package FMUP\ErrorHandler
10
 */
11
class ErrorController extends Abstraction
12
{
13
    private $errorController;
14
15
    /**
16
     * @param Error $errorController
17
     */
18 3
    public function __construct(Error $errorController)
19
    {
20 3
        $this->setErrorController($errorController);
21 3
    }
22
23
    /**
24
     * @param Error $errorController
25
     * @return $this
26
     */
27 3
    public function setErrorController(Error $errorController)
28
    {
29 3
        $this->errorController = $errorController;
30 3
        return $this;
31
    }
32
33
    /**
34
     * @return Error
35
     * @throws Exception
36
     */
37 3
    public function getErrorController()
38
    {
39 3
        if (!$this->errorController) {
40 1
            throw new Exception('Error Controller must be set');
41
        }
42 2
        return $this->errorController;
43
    }
44
45
    /**
46
     * Always handle error with error controller
47
     * @return bool
48
     */
49 1
    public function canHandle()
50
    {
51 1
        return true;
52
    }
53
54
    /**
55
     * @return $this
56
     * @throws \FMUP\Exception
57
     */
58 1
    public function handle()
59
    {
60 1
        $errorController = $this->getErrorController();
61
        $errorController
62 1
            ->setBootstrap($this->getBootstrap())
63 1
            ->setRequest($this->getRequest())
64 1
            ->setResponse($this->getResponse())
65 1
            ->setException($this->getException());
66 1
        $errorController->preFilter('index');
0 ignored issues
show
Unused Code introduced by
The call to the method FMUP\Controller\Error::preFilter() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
67 1
        $errorController->indexAction();
68 1
        $errorController->postFilter('index');
0 ignored issues
show
Unused Code introduced by
The call to the method FMUP\Controller\Error::postFilter() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
69 1
        return $this;
70
    }
71
}
72