Passed
Push — main ( af755d...c6deb1 )
by Dimitri
04:08
created

Debugger   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
dl 0
loc 58
rs 10
c 1
b 0
f 0
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A initWhoops() 0 24 4
A init() 0 7 3
A initIgnition() 0 7 1
1
<?php
2
3
/**
4
 * This file is part of Blitz PHP framework.
5
 *
6
 * (c) 2022 Dimitri Sitchet Tomkeu <[email protected]>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
namespace BlitzPHP\Debug;
13
14
use BlitzPHP\Container\Services;
15
use Spatie\Ignition\Ignition;
0 ignored issues
show
Bug introduced by
The type Spatie\Ignition\Ignition was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use Throwable;
17
use Whoops\Exception\Inspector;
0 ignored issues
show
Bug introduced by
The type Whoops\Exception\Inspector was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
use Whoops\Handler\Handler;
0 ignored issues
show
Bug introduced by
The type Whoops\Handler\Handler was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
use Whoops\Handler\JsonResponseHandler;
0 ignored issues
show
Bug introduced by
The type Whoops\Handler\JsonResponseHandler was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
use Whoops\Handler\PlainTextHandler;
0 ignored issues
show
Bug introduced by
The type Whoops\Handler\PlainTextHandler was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
use Whoops\Handler\PrettyPageHandler;
0 ignored issues
show
Bug introduced by
The type Whoops\Handler\PrettyPageHandler was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
22
use Whoops\Run;
0 ignored issues
show
Bug introduced by
The type Whoops\Run was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
23
use Whoops\RunInterface;
0 ignored issues
show
Bug introduced by
The type Whoops\RunInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
use Whoops\Util\Misc;
0 ignored issues
show
Bug introduced by
The type Whoops\Util\Misc was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
25
26
/**
27
 * Capture et affiche les erreurs et exceptions via whoops
28
 *
29
 * Necessite l'instalation de `flip/whoops` ou `spatie/ignition`
30
 */
31
class Debugger
32
{
33
    /**
34
     * Demarre le processus
35
     *
36
     * @return void
37
     */
38
    public static function init()
39
    {
40
        if (class_exists(Run::class)) {
41
            return self::initWhoops();
0 ignored issues
show
Bug introduced by
Are you sure the usage of self::initWhoops() targeting BlitzPHP\Debug\Debugger::initWhoops() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
42
        }
43
        if (class_exists(Ignition::class)) {
44
            return self::initIgnition();
0 ignored issues
show
Bug introduced by
Are you sure the usage of self::initIgnition() targeting BlitzPHP\Debug\Debugger::initIgnition() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
45
        }
46
    }
47
48
    /**
49
     * Initialisation du debugger a travers filp/Whoops
50
     */
51
    private static function initWhoops()
52
    {
53
        $debugger = new Run();
54
55
        if (! is_online()) {
56
            if (Misc::isCommandLine()) {
57
                $debugger->pushHandler(new PlainTextHandler());
58
            } elseif (Misc::isAjaxRequest()) {
59
                $debugger->pushHandler(new JsonResponseHandler());
60
            } else {
61
                $debugger->pushHandler(new PrettyPageHandler());
62
            }
63
        }
64
65
        /**
66
         * On log toutes les erreurs
67
         */
68
        $debugger->pushHandler(static function (Throwable $exception, Inspector $inspector, RunInterface $run) {
0 ignored issues
show
Unused Code introduced by
The parameter $inspector 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

68
        $debugger->pushHandler(static function (Throwable $exception, /** @scrutinizer ignore-unused */ Inspector $inspector, RunInterface $run) {

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...
Unused Code introduced by
The parameter $run 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

68
        $debugger->pushHandler(static function (Throwable $exception, Inspector $inspector, /** @scrutinizer ignore-unused */ RunInterface $run) {

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...
69
            Services::logger()->error($exception);
70
71
            return Handler::DONE;
72
        });
73
74
        $debugger->register();
75
    }
76
77
    /**
78
     * Initialisation du debugger a travers spatie/ignition
79
     * 
80
     * @todo customisation du debugger et log des erreurs
81
     */
82
    private static function initIgnition()
83
    {
84
        $debugger = Ignition::make();
85
86
        $debugger->applicationPath(ROOTPATH)
87
            ->shouldDisplayException(! on_prod())
88
            ->register();
89
    }
90
}
91