Completed
Push — master ( d78d08...71c71b )
by Milroy
20s
created

SaralaServiceProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 9

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 9
dl 0
loc 40
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 22 1
A register() 0 14 1
1
<?php
2
3
namespace Sarala;
4
5
use Sarala\Query\Sorts;
6
use Sarala\Query\Fields;
7
use League\Fractal\Manager;
8
use Illuminate\Http\Request;
9
use Sarala\Query\QueryParamBag;
10
use Illuminate\Support\ServiceProvider;
11
use League\Fractal\Serializer\JsonApiSerializer;
12
use League\Fractal\Serializer\DataArraySerializer;
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', function () {
23
            return new QueryParamBag($this, 'filter');
0 ignored issues
show
Documentation introduced by
$this is of type this<Sarala\SaralaServiceProvider>, but the function expects a object<Illuminate\Http\Request>.

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...
24
        });
25
26
        Request::macro('includes', function () {
27
            return new QueryParamBag($this, 'include');
0 ignored issues
show
Documentation introduced by
$this is of type this<Sarala\SaralaServiceProvider>, but the function expects a object<Illuminate\Http\Request>.

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...
28
        });
29
30
        Request::macro('fields', function () {
31
            return new Fields($this);
0 ignored issues
show
Documentation introduced by
$this is of type this<Sarala\SaralaServiceProvider>, but the function expects a object<Illuminate\Http\Request>.

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...
32
        });
33
34
        Request::macro('sorts', function () {
35
            return new Sorts($this);
0 ignored issues
show
Documentation introduced by
$this is of type this<Sarala\SaralaServiceProvider>, but the function expects a object<Illuminate\Http\Request>.

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...
36
        });
37
    }
38
39
    public function register(): void
40
    {
41
        $this->app->bind(JsonApiSerializer::class, function ($app) {
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
42
            return new JsonApiSerializer(config('sarala.base_url'));
43
        });
44
45
        $this->app->bind(DataArraySerializer::class, function ($app) {
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
46
            return new DataArraySerializer();
47
        });
48
49
        $this->app->bind(Manager::class, function ($app) {
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
50
            return (new Manager())->setSerializer(Sarala::resolve()->getSerializer());
51
        });
52
    }
53
}
54