TruckerServiceProvider   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 183
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 11
dl 0
loc 183
rs 10
c 1
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A make() 0 16 2
A registerConfig() 0 22 3
A bindPaths() 0 10 1
A provides() 0 3 1
A bindClasses() 0 56 1
A bindCoreClasses() 0 14 1
A boot() 0 2 1
A register() 0 4 1
1
<?php
2
3
namespace Trucker;
4
5
use Illuminate\Config\FileLoader;
6
use Illuminate\Config\Repository;
7
use Illuminate\Container\Container;
8
use Illuminate\Support\ServiceProvider;
9
10
/**
11
 * Service Provider for interacting with the Trucker class.
12
 *
13
 * @author Alessandro Manno <[email protected]>
14
 */
15
class TruckerServiceProvider extends ServiceProvider
16
{
17
    /**
18
     * Bootstrap the application events.
19
     */
20
    public function boot()
21
    {
22
        // Register classes
23
    }
24
25
    /**
26
     * Register the service provider.
27
     */
28
    public function register()
29
    {
30
        // done with boot()
31
        $this->app = static::make($this->app);
0 ignored issues
show
Documentation Bug introduced by
It seems like static::make($this->app) of type Illuminate\Container\Container is incompatible with the declared type Illuminate\Foundation\Application of property $app.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
32
    }
33
34
    /**
35
     * Get the services provided by the provider.
36
     *
37
     * @return array
38
     */
39
    public function provides()
40
    {
41
        return ['trucker'];
42
    }
43
44
    public static function make(Container $app = null)
45
    {
46
        if (!$app) {
47
            $app = new Container();
48
        }
49
50
        $serviceProvider = new static($app);
51
52
        //bind paths
53
        $app = $serviceProvider->bindPaths($app);
54
55
        // Bind classes
56
        $app = $serviceProvider->bindCoreClasses($app);
57
        $app = $serviceProvider->bindClasses($app);
58
59
        return $app;
60
    }
61
62
    /**
63
     * Bind the Trucker paths.
64
     *
65
     * @param Container $app
66
     *
67
     * @return Container
68
     */
69
    public function bindPaths(Container $app)
70
    {
71
        $app->bind('trucker.bootstrapper', function ($app) {
72
            return new Bootstrapper($app);
73
        });
74
75
        // Bind paths
76
        $app['trucker.bootstrapper']->bindPaths();
77
78
        return $app;
79
    }
80
81
    /**
82
     * Bind the core classes.
83
     *
84
     * @param Container $app
85
     *
86
     * @return Container
87
     */
88
    public function bindCoreClasses(Container $app)
89
    {
90
        $app->bindIf('files', 'Illuminate\Filesystem\Filesystem');
91
92
        $app->bindIf('config', function ($app) {
93
            $fileloader = new FileLoader($app['files'], __DIR__ . '/../config');
94
95
            return new Repository($fileloader, 'config');
96
        }, true);
97
98
        // Register factory and custom configurations
99
        $app = $this->registerConfig($app);
100
101
        return $app;
102
    }
103
104
    /**
105
     * Bind the ActiveResource classes to the Container.
106
     *
107
     * @param Container $app
108
     *
109
     * @return Container
110
     */
111
    public function bindClasses(Container $app)
112
    {
113
        $app->singleton('trucker.urls', function ($app) {
114
            return new Url\UrlGenerator($app);
115
        });
116
117
        $app->singleton('trucker.config-manager', function ($app) {
118
            return new Support\ConfigManager($app);
119
        });
120
121
        $app->bind('trucker.instance-finder', function ($app) {
122
            return new Finders\InstanceFinder($app);
123
        });
124
125
        $app->bind('trucker.collection-finder', function ($app) {
126
            return new Finders\CollectionFinder($app);
127
        });
128
129
        $app->bind('trucker.response', function ($app) {
130
            return new Responses\Response($app);
131
        });
132
133
        $app->bind('trucker.model', function () {
134
            return new Resource\Model();
135
        });
136
137
        //Factories
138
        $app->bind('trucker.conditions', function ($app) {
139
            return new Factories\QueryConditionFactory($app);
140
        });
141
142
        $app->bind('trucker.transporter', function ($app) {
143
            return new Factories\ApiTransporterFactory($app);
144
        });
145
146
        $app->bind('trucker.order', function ($app) {
147
            return new Factories\QueryResultOrderFactory($app);
148
        });
149
150
        $app->bind('trucker.interpreter', function ($app) {
151
            return new Factories\ResponseInterpreterFactory($app);
152
        });
153
154
        $app->bind('trucker.error-handler', function ($app) {
155
            return new Factories\ErrorHandlerFactory($app);
156
        });
157
158
        $app->bind('trucker.request-factory', function ($app) {
159
            return new Factories\RequestFactory($app);
160
        });
161
162
        $app->bind('trucker.auth', function ($app) {
163
            return new Factories\AuthFactory($app);
164
        });
165
166
        return $app;
167
    }
168
169
    /**
170
     * Register factory and custom configurations.
171
     *
172
     * @param Container $app
173
     *
174
     * @return Container
175
     */
176
    protected function registerConfig(Container $app)
177
    {
178
        // Register config file(filename)
179
        $app['config']->package('alexmanno/trucker', __DIR__ . '/../config');
0 ignored issues
show
Bug introduced by
The method package() does not exist on Illuminate\Support\Facades\Config. ( Ignorable by Annotation )

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

179
        $app['config']->/** @scrutinizer ignore-call */ 
180
                        package('alexmanno/trucker', __DIR__ . '/../config');

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...
180
        $app['config']->getLoader();
0 ignored issues
show
Bug introduced by
The method getLoader() does not exist on Illuminate\Support\Facades\Config. ( Ignorable by Annotation )

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

180
        $app['config']->/** @scrutinizer ignore-call */ 
181
                        getLoader();

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...
181
182
        // Register custom config
183
        $custom = $app['path.trucker.config'];
184
        if (file_exists($custom)) {
185
            $app['config']->afterLoading('trucker', function ($group, $items) use ($custom) {
0 ignored issues
show
Bug introduced by
The method afterLoading() does not exist on Illuminate\Support\Facades\Config. ( Ignorable by Annotation )

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

185
            $app['config']->/** @scrutinizer ignore-call */ 
186
                            afterLoading('trucker', function ($group, $items) use ($custom) {

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...
186
                $customItems = $custom . '/' . $group . '.php';
187
                if (!file_exists($customItems)) {
188
                    return $items;
189
                }
190
191
                $customItems = include $customItems;
192
193
                return array_replace_recursive($items, $customItems);
194
            });
195
        }
196
197
        return $app;
198
    }
199
}
200