Completed
Push — master ( 99f6c2...5bcbf0 )
by Pavel
05:52
created

RestServiceProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 93.33%

Importance

Changes 0
Metric Value
dl 0
loc 46
ccs 28
cts 30
cp 0.9333
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 4 1
A registerResponses() 0 5 1
A registerDefaultRequests() 0 21 1
1
<?php namespace Pz\LaravelDoctrine\Rest;
2
3
use Illuminate\Support\ServiceProvider;
4
5
use Pz\Doctrine\Rest\Request\CreateRequestInterface;
6
use Pz\Doctrine\Rest\Request\DeleteRequestInterface;
7
use Pz\Doctrine\Rest\Request\IndexRequestInterface;
8
use Pz\Doctrine\Rest\Request\ShowRequestInterface;
9
use Pz\Doctrine\Rest\Request\UpdateRequestInterface;
10
use Pz\Doctrine\Rest\Response\FractalResponse;
11
use Pz\Doctrine\Rest\RestResponseFactory;
12
use Pz\LaravelDoctrine\Rest\Request\CreateRestRequest;
13
use Pz\LaravelDoctrine\Rest\Request\DeleteRestRequest;
14
use Pz\LaravelDoctrine\Rest\Request\IndexRestRequest;
15
use Pz\LaravelDoctrine\Rest\Request\ShowRestRequest;
16
use Pz\LaravelDoctrine\Rest\Request\UpdateRestRequest;
17
18
class RestServiceProvider extends ServiceProvider
19
{
20
    /**
21
     * Register laravel doctrine rest application.
22
     */
23 5
    public function register()
24
    {
25 5
        $this->registerDefaultRequests();
26 5
        $this->registerResponses();
27 5
    }
28
29
    /**
30
     * Register application requests.
31
     */
32 5
    protected function registerResponses()
33
    {
34 5
        $this->app->bind(RestResponseFactory::class, RestResponse::class);
35 5
        $this->app->bind(RestResponse::class, function() {
36 4
            return new RestResponse($this->app->make('url')->to('/rest'));
0 ignored issues
show
Unused Code introduced by
The call to Pz\LaravelDoctrine\Rest\...Response::__construct() has too many arguments starting with $this->app->make('url')->to('/rest'). ( Ignorable by Annotation )

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

36
            return /** @scrutinizer ignore-call */ new RestResponse($this->app->make('url')->to('/rest'));

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
37 5
        });
38 5
    }
39
40
    /**
41
     * Register default laravel requests.
42
     */
43 5
    protected function registerDefaultRequests()
44
    {
45 5
        $this->app->bind(IndexRequestInterface::class, IndexRestRequest::class);
46 5
        $this->app->bind(IndexRestRequest::class, function() {
47 1
            return new IndexRestRequest();
48 5
        });
49 5
        $this->app->bind(ShowRequestInterface::class, ShowRestRequest::class);
50 5
        $this->app->bind(ShowRestRequest::class, function() {
51 1
            return new ShowRestRequest();
52 5
        });
53 5
        $this->app->bind(DeleteRequestInterface::class, DeleteRestRequest::class);
54 5
        $this->app->bind(DeleteRestRequest::class, function() {
55 1
            return new DeleteRestRequest();
56 5
        });
57 5
        $this->app->bind(CreateRequestInterface::class, CreateRestRequest::class);
58 5
        $this->app->bind(CreateRestRequest::class, function() {
59
            return new CreateRestRequest();
60 5
        });
61 5
        $this->app->bind(UpdateRequestInterface::class, UpdateRestRequest::class);
62 5
        $this->app->bind(UpdateRestRequest::class, function() {
63
            return new UpdateRestRequest();
64 5
        });
65
    }
66
}
67