Completed
Pull Request — master (#12)
by
unknown
14:50
created

ServiceProvider::provides()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace RealPage\JsonApi\Lumen;
4
5
use Illuminate\Support\ServiceProvider as IlluminateServiceProvider;
6
use RealPage\JsonApi\MediaTypeGuard;
7
use RealPage\JsonApi\EncoderService;
8
use Illuminate\Support\Str;
9
use Illuminate\Http\Request;
10
11
class ServiceProvider extends IlluminateServiceProvider
12
{
13
    public function boot()
14
    {
15
        Request::macro('wantsJsonApi', function () {
16
            $acceptable = $this->getAcceptableContentTypes();
0 ignored issues
show
Bug introduced by
The method getAcceptableContentTypes() does not seem to exist on object<RealPage\JsonApi\Lumen\ServiceProvider>.

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...
17
            return isset($acceptable[0]) && Str::contains($acceptable[0], ['application/vnd.api+json']);
18
        });
19
    }
20
21
    public function register()
22
    {
23
        $this->app->configure('json-api');
24
25
        $this->mergeConfigFrom(__DIR__ . '/../../config/json-api.php', 'json-api');
26
27
        $this->app->bind(MediaTypeGuard::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...
28
            return new MediaTypeGuard(config('json-api.media-type'));
29
        });
30
31
        $this->app->bind(EncoderService::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...
32
            return new EncoderService(config('json-api'));
33
        });
34
    }
35
36
    /**
37
     * @return array
38
     */
39
    public function provides()
40
    {
41
        return [MediaTypeGuard::class, EncoderService::class];
42
    }
43
}
44