LaravelTracerServiceProvider   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 12 2
A boot() 0 11 3
1
<?php
2
3
namespace ProtoneMedia\LaravelTracer;
4
5
use Illuminate\Http\Request;
6
use Illuminate\Support\ServiceProvider;
7
8
class LaravelTracerServiceProvider extends ServiceProvider
9
{
10
    /**
11
     * Bootstrap the application services.
12
     */
13
    public function boot()
14
    {
15
        if ($this->app->runningInConsole()) {
16
            $this->publishes([
17
                __DIR__ . '/../config/config.php' => config_path('laravel-tracer.php'),
18
            ], 'config');
19
20
            if (!class_exists('CreateUserRequestsTable')) {
21
                $this->publishes([
22
                    __DIR__ . '/../database/migrations/create_user_requests_table.php.stub' => database_path('migrations/' . date('Y_m_d_His', time()) . '_create_user_requests_table.php'),
23
                ], 'migrations');
24
            }
25
        }
26
    }
27
28
    /**
29
     * Register the application services.
30
     */
31
    public function register()
32
    {
33
        $this->mergeConfigFrom(__DIR__ . '/../config/config.php', 'laravel-tracer');
34
35
        // setter for the qualified route
36
        Request::macro('qualifyAs', function (string $name, $secondsBetweenLogs = null) {
37
            $this->qualifiedRoute = new QualifiedRoute($this->route(), $name, $secondsBetweenLogs);
0 ignored issues
show
Bug Best Practice introduced by
The property qualifiedRoute does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
Bug introduced by
The method route() does not exist on ProtoneMedia\LaravelTrac...elTracerServiceProvider. ( Ignorable by Annotation )

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

37
            $this->qualifiedRoute = new QualifiedRoute($this->/** @scrutinizer ignore-call */ route(), $name, $secondsBetweenLogs);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
38
        });
39
40
        // getter for the qualified route
41
        Request::macro('qualifiedRoute', function (): QualifiedRoute {
42
            return $this->qualifiedRoute ?: QualifiedRoute::fromRequest($this);
0 ignored issues
show
Bug introduced by
$this of type ProtoneMedia\LaravelTrac...elTracerServiceProvider is incompatible with the type Illuminate\Http\Request expected by parameter $request of ProtoneMedia\LaravelTrac...iedRoute::fromRequest(). ( Ignorable by Annotation )

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

42
            return $this->qualifiedRoute ?: QualifiedRoute::fromRequest(/** @scrutinizer ignore-type */ $this);
Loading history...
43
        });
44
    }
45
}
46