Passed
Push — main ( ecbf01...8eb3ca )
by Качула
04:24 queued 02:06
created

ServiceProvider::startDebug()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ka4ivan\ApiDebugger;
6
7
use Illuminate\Http\Request;
0 ignored issues
show
Bug introduced by
The type Illuminate\Http\Request 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...
8
use Illuminate\Routing\Router;
0 ignored issues
show
Bug introduced by
The type Illuminate\Routing\Router 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...
9
use Ka4ivan\ApiDebugger\Middleware\ApiDebuggerMiddleware;
10
use Ka4ivan\ApiDebugger\Support\ApiDebugger;
11
12
class ServiceProvider extends \Illuminate\Support\ServiceProvider
13
{
14
    /**
15
     * Bootstrap the application services.
16
     *
17
     * @return void
18
     */
19
    public function boot(): void
20
    {
21
        $this->registerMacros();
22
        $this->registerMiddleware();
23
24
        if (app(ApiDebugger::class)->isActive()) {
0 ignored issues
show
Bug introduced by
The function app was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

24
        if (/** @scrutinizer ignore-call */ app(ApiDebugger::class)->isActive()) {
Loading history...
25
            $this->startDebug();
26
        }
27
    }
28
29
    /**
30
     * Register the application services.
31
     *
32
     * @return void
33
     */
34
    public function register(): void
35
    {
36
        $this->app->singleton(ApiDebugger::class);
37
    }
38
39
    /**
40
     * Register macros for Request class.
41
     *
42
     * @return void
43
     */
44
    protected function registerMacros(): void
45
    {
46
        Request::macro('startDebug', fn() => app(ApiDebugger::class)->startDebug());
0 ignored issues
show
Bug introduced by
The function app was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

46
        Request::macro('startDebug', fn() => /** @scrutinizer ignore-call */ app(ApiDebugger::class)->startDebug());
Loading history...
47
        Request::macro('getDebug', fn() => app(ApiDebugger::class)->getDebug(request()));
0 ignored issues
show
Bug introduced by
The function request was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

47
        Request::macro('getDebug', fn() => app(ApiDebugger::class)->getDebug(/** @scrutinizer ignore-call */ request()));
Loading history...
Bug introduced by
The function app was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

47
        Request::macro('getDebug', fn() => /** @scrutinizer ignore-call */ app(ApiDebugger::class)->getDebug(request()));
Loading history...
48
    }
49
50
    /**
51
     * Register middleware for API routes.
52
     *
53
     * @return void
54
     */
55
    protected function registerMiddleware(): void
56
    {
57
        $this->app->booted(fn() => tap($this->app->make(Router::class), function(Router $router) {
58
            $router->middlewareGroup('api', array_merge(
59
                $router->getMiddlewareGroups()['api'] ?? [],
60
                [ApiDebuggerMiddleware::class]
61
            ));
62
        }));
63
    }
64
65
    /**
66
     * Start Debugging
67
     *
68
     * @return void
69
     */
70
    protected function startDebug(): void
71
    {
72
        $this->app->booted(function () {
73
            app(ApiDebugger::class)->startDebug();
0 ignored issues
show
Bug introduced by
The function app was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

73
            /** @scrutinizer ignore-call */ 
74
            app(ApiDebugger::class)->startDebug();
Loading history...
74
        });
75
    }
76
}
77