SaralaServiceProvider   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 14
dl 0
loc 22
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 11 1
A register() 0 7 1
1
<?php
2
3
namespace Sarala;
4
5
use Illuminate\Http\Request;
6
use Illuminate\Support\ServiceProvider;
7
use League\Fractal\Manager;
8
use League\Fractal\Serializer\DataArraySerializer;
9
use League\Fractal\Serializer\JsonApiSerializer;
10
use Sarala\Query\Fields;
11
use Sarala\Query\QueryParamBag;
12
use Sarala\Query\Sorts;
13
14
class SaralaServiceProvider extends ServiceProvider
15
{
16
    public function boot()
17
    {
18
        $this->publishes([
19
            __DIR__.'/../config/sarala.php' => config_path('sarala.php'),
20
        ], 'config');
21
22
        Request::macro('filters', fn () => new QueryParamBag($this, 'filter'));
0 ignored issues
show
Bug introduced by
$this of type Sarala\SaralaServiceProvider is incompatible with the type Illuminate\Http\Request expected by parameter $request of Sarala\Query\QueryParamBag::__construct(). ( Ignorable by Annotation )

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

22
        Request::macro('filters', fn () => new QueryParamBag(/** @scrutinizer ignore-type */ $this, 'filter'));
Loading history...
23
        Request::macro('includes', fn () => new QueryParamBag($this, 'include'));
0 ignored issues
show
Bug introduced by
$this of type Sarala\SaralaServiceProvider is incompatible with the type Illuminate\Http\Request expected by parameter $request of Sarala\Query\QueryParamBag::__construct(). ( Ignorable by Annotation )

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

23
        Request::macro('includes', fn () => new QueryParamBag(/** @scrutinizer ignore-type */ $this, 'include'));
Loading history...
24
        Request::macro('fields', fn () => resolve(Fields::class));
25
        Request::macro('sorts', fn () => new Sorts($this));
0 ignored issues
show
Bug introduced by
$this of type Sarala\SaralaServiceProvider is incompatible with the type Illuminate\Http\Request expected by parameter $request of Sarala\Query\Sorts::__construct(). ( Ignorable by Annotation )

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

25
        Request::macro('sorts', fn () => new Sorts(/** @scrutinizer ignore-type */ $this));
Loading history...
26
        Request::macro('allowedIncludes', fn () => []);
27
    }
28
29
    public function register(): void
30
    {
31
        $this->app->singleton(Sarala::class, Sarala::class);
32
        $this->app->bind(JsonApiSerializer::class, fn () => new JsonApiSerializer(config('sarala.base_url')));
33
        $this->app->bind(DataArraySerializer::class, DataArraySerializer::class);
34
        $this->app->singleton(Fields::class, Fields::class);
35
        $this->app->bind(Manager::class, fn ($app) => (new Manager())->setSerializer($app->make(Sarala::class)->getSerializer()));
36
    }
37
}
38