Passed
Push — develop ( 9ae090...ce9409 )
by Schlaefer
42s
created

Development::displayDeveloperOutput()   B

Complexity

Conditions 5
Paths 12

Size

Total Lines 58
Code Lines 44

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 58
ccs 0
cts 36
cp 0
rs 8.7274
cc 5
eloc 44
nc 12
nop 6
crap 30

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * @link http://philecms.github.io/
4
 * @license http://opensource.org/licenses/MIT
5
 * @package Phile\Plugin\Phile\ErrorHandler
6
 */
7
8
namespace Phile\Plugin\Phile\ErrorHandler;
9
10
use Phile\ServiceLocator\ErrorHandlerInterface;
11
use Whoops\Handler\Handler;
12
use Whoops\Handler\PlainTextHandler;
13
use Whoops\Handler\PrettyPageHandler;
14
use Whoops\Run;
15
16
/**
17
 * Developement error handler: use whoops
18
 */
19
class Development implements ErrorHandlerInterface
20
{
21
    protected $settings;
22
23
    protected $whoops;
24
25 29
    public function __construct(array $settings = [])
26
    {
27 29
        $this->settings = $settings;
28 29
        $this->whoops = new Run();
29 29
        $this->whoops->pushHandler($this->createHandler());
0 ignored issues
show
Documentation introduced by
$this->createHandler() is of type object<Whoops\Handler\Handler>, but the function expects a callable.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
30 29
    }
31
32
    public function handleError(int $errno, string $errstr, ?string $errfile, ?int $errline)
33
    {
34
        $level = $this->settings['level'];
35
        $this->whoops->{Run::ERROR_HANDLER}($level, $errstr, $errfile, $errline);
36
    }
37
38 1
    public function handleException(\Throwable $exception)
39
    {
40 1
        $this->whoops->{Run::EXCEPTION_HANDLER}($exception);
41 1
    }
42
43
    public function handleShutdown()
44
    {
45
        $this->whoops->{Run::SHUTDOWN_HANDLER}();
46
    }
47
48 29
    protected function createHandler(): Handler
49
    {
50 29
        if (PHILE_CLI_MODE) {
51 29
            $handler = new PlainTextHandler;
52 29
            $this->whoops->allowQuit(false);
53 29
            return $handler;
54
        }
55
56
        $handler = new PrettyPageHandler;
57
        if (!empty($this->settings['editor'])) {
58
            $handler->setEditor($this->settings['editor']);
59
        }
60
        return $handler;
61
    }
62
}
63