Test Setup Failed
Push — v2 ( 74186a...c94b75 )
by Alexander
06:56
created

LaravelServiceProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 21.43 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 12 2
A boot() 9 9 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Flugg\Responder;
4
5
use Flugg\Responder\Contracts\ErrorFactory as ErrorFactoryContract;
6
use Flugg\Responder\Contracts\ErrorSerializer as ErrorSerializerContract;
7
use Flugg\Responder\Contracts\Responder as ResponderContract;
8
use Flugg\Responder\Contracts\ResponseFactory as ResponseFactoryContract;
9
use Flugg\Responder\Contracts\Transformer as TransformerContract;
10
use Flugg\Responder\Contracts\TransformFactory;
11
use Flugg\Responder\Http\Responses\ErrorResponseBuilder;
12
use Flugg\Responder\Http\Responses\Factories\LaravelResponseFactory;
13
use Flugg\Responder\Http\Responses\SuccessResponseBuilder;
14
use Flugg\Responder\Pagination\CursorFactory;
15
use Flugg\Responder\Pagination\PaginatorFactory;
16
use Flugg\Responder\Serializers\ErrorSerializer;
17
use Illuminate\Contracts\Routing\ResponseFactory;
18
use Illuminate\Http\Request;
19
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
20
use League\Fractal\Manager;
21
22
/**
23
 * A service provider class responsible for bootstrapping the parts of the Laravel package.
24
 *
25
 * @package flugger/laravel-responder
26
 * @author  Alexander Tømmerås <[email protected]>
27
 * @license The MIT License
28
 */
29
class LaravelServiceProvider extends BaseServiceProvider
30
{
31
    /**
32
     * Indicates if loading of the provider is deferred.
33
     *
34
     * @var bool
35
     */
36
    protected $defer = false;
37
38
    /**
39
     * Register the service provider.
40
     *
41
     * @return void
42
     */
43
    public function register()
44
    {
45
        $this->app->bind(ResponseFactoryContract::class, function ($app) {
46
            $factory = new LaravelResponseFactory($app[ResponseFactory::class]);
47
48
            foreach ($this->app->config['responder.decorators'] as $decorator) {
49
                $factory = new $decorator($factory);
50
            };
51
52
            return $factory;
53
        });
54
    }
55
56
    /**
57
     * Bootstrap the application events.
58
     *
59
     * @return void
60
     */
61 View Code Duplication
    public function boot()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
62
    {
63
        $this->publishes([
64
            __DIR__ . '/../resources/config/responder.php' => config_path('responder.php')
65
        ], 'config');
66
        $this->publishes([
67
            __DIR__ . '/../resources/lang/en/errors.php' => base_path('resources/lang/en/errors.php')
68
        ], 'lang');
69
    }
70
}