GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 95f6f3...524104 )
by Shea
02:32
created

Modules   A

Complexity

Total Complexity 31

Size/Duplication

Total Lines 339
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 7.14%

Importance

Changes 31
Bugs 6 Features 6
Metric Value
wmc 31
c 31
b 6
f 6
lcom 1
cbo 1
dl 0
loc 339
ccs 4
cts 56
cp 0.0714
rs 9.8

28 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A register() 0 10 1
A registerServiceProvider() 0 8 1
A autoloadFiles() 0 11 3
A all() 0 4 1
A slugs() 0 4 1
A where() 0 4 1
A sortBy() 0 4 1
A sortByDesc() 0 4 1
A exists() 0 4 1
A count() 0 4 1
A getPath() 0 4 1
A setPath() 0 4 1
A getModulePath() 0 4 1
A getNamespace() 0 4 1
A getProperties() 0 4 1
A getProperty() 0 4 1
A setProperty() 0 4 1
A enabled() 0 4 1
A disabled() 0 4 1
A isEnabled() 0 4 1
A isDisabled() 0 4 1
A enable() 0 4 1
A disable() 0 4 1
A cache() 0 4 1
A getCache() 0 4 1
A setCache() 0 4 1
A resolveNamespace() 0 7 2
1
<?php
2
namespace Caffeinated\Modules;
3
4
use Caffeinated\Modules\Contracts\RepositoryInterface;
5
use Illuminate\Foundation\Application;
6
7
class Modules implements RepositoryInterface
8
{
9
	/**
10
	 * @var Application
11
	 */
12
	protected $app;
13
14
	/**
15
	 * @var RepositoryInterface
16
	 */
17
	protected $repository;
18
19
	/**
20
	 * Create a new Modules instance.
21
	 *
22
	 * @param Application  $app
23
	 * @param RepositoryInterface  $repository
24 1
	 */
25
	public function __construct(Application $app, RepositoryInterface $repository)
26 1
	{
27 1
		$this->app        = $app;
28 1
		$this->repository = $repository;
29
	}
30
31
	/**
32
	 * Register the module service provider file from all modules.
33
	 *
34
	 * @return mixed
35
	 */
36
	public function register()
37
	{
38
		$modules = $this->repository->enabled();
39
40
		$modules->each(function($properties, $slug) {
0 ignored issues
show
Unused Code introduced by
The parameter $slug 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...
41
			$this->registerServiceProvider($properties);
42
43
			$this->autoloadFiles($properties);
44
		});
45
	}
46
47
	/**
48
	 * Register the module service provider.
49
	 *
50
	 * @param  string $properties
51
	 * @return string
52
	 * @throws \Caffeinated\Modules\Exception\FileMissingException
53
	 */
54
	protected function registerServiceProvider($properties)
55
	{
56
		$namespace       = $this->resolveNamespace($properties);
0 ignored issues
show
Documentation introduced by
$properties is of type string, but the function expects a array.

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...
57
		$file            = $this->repository->getPath()."/{$namespace}/Providers/{$namespace}ServiceProvider.php";
0 ignored issues
show
Unused Code introduced by
$file is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
58
		$serviceProvider = $this->repository->getNamespace()."\\".$namespace."\\Providers\\{$namespace}ServiceProvider";
59
60
		$this->app->register($serviceProvider);
61
	}
62
63
	/**
64
	 * Autoload custom module files.
65
	 *
66
	 * @param array  $properties
67
	 * @return void
68
	 */
69
	protected function autoloadFiles($properties)
70
	{
71
		if (isset($properties['autoload'])) {
72
			$namespace = $this->resolveNamespace($properties);
73
			$path      = $this->repository->getPath()."/{$namespace}/";
74
75
			foreach ($properties['autoload'] as $file) {
76
				include($path.$file);
77
			}
78
		}
79
	}
80
81
	/**
82
	 * Get all modules.
83
	 *
84
	 * @return Collection
85
	 */
86
	public function all()
87
	{
88
		return $this->repository->all();
89
	}
90
91
	/**
92
	 * Get all module slugs.
93
	 *
94
	 * @return array
95
	 */
96
	public function slugs()
97
	{
98
		return $this->repository->slugs();
99
	}
100
101
	/**
102
	 * Get modules based on where clause.
103
	 *
104
	 * @param  string  $key
105
	 * @param  mixed   $value
106
	 * @return Collection
107
	 */
108
	public function where($key, $value)
109
	{
110
		return $this->repository->where($key, $value);
111
	}
112
113
	/**
114
	 * Sort modules by given key in ascending order.
115
	 *
116
	 * @param  string  $key
117
	 * @return Collection
118
	 */
119
	public function sortBy($key)
120
	{
121
		return $this->repository->sortBy($key);
122
	}
123
124
	/**
125
	 * Sort modules by given key in ascending order.
126
	 *
127
	 * @param  string  $key
128
	 * @return Collection
129
	 */
130
	public function sortByDesc($key)
131
	{
132
		return $this->repository->sortByDesc($key);
133
	}
134
135
	/**
136
	 * Check if the given module exists.
137
	 *
138
	 * @param  string  $slug
139
	 * @return bool
140
	 */
141
	public function exists($slug)
142
	{
143
		return $this->repository->exists($slug);
144
	}
145
146
	/**
147
	 * Returns count of all modules.
148
	 *
149
	 * @return int
150
	 */
151
	public function count()
152
	{
153
		return $this->repository->count();
154
	}
155
156
	/**
157
	 * Get modules path.
158
	 *
159
	 * @return string
160
	 */
161
	public function getPath()
162
	{
163
		return $this->repository->getPath();
164
	}
165
166
	/**
167
	 * Set modules path in "RunTime" mode.
168
	 *
169
	 * @param  string $path
170
	 * @return object $this
171
	 */
172
	public function setPath($path)
173
	{
174
		return $this->repository->setPath($path);
175
	}
176
177
	/**
178
	* Get path for the specified module.
179
	*
180
	* @param  string $slug
181
	* @return string
182
	*/
183
	public function getModulePath($slug)
184
	{
185
		return $this->repository->getModulePath($slug);
186
	}
187
188
	/**
189
	* Get modules namespace.
190
	*
191
	* @return string
192
	*/
193
	public function getNamespace()
194
	{
195
		return $this->repository->getNamespace();
196
	}
197
198
	/**
199
	 * Get a module's properties.
200
	 *
201
	 * @param  string $slug
202
	 * @return mixed
203
	 */
204
	public function getProperties($slug)
205
	{
206
		return $this->repository->getProperties($slug);
207
	}
208
209
	/**
210
	 * Get a module property value.
211
	 *
212
	 * @param  string $property
213
	 * @param  mixed  $default
214
	 * @return mixed
215
	 */
216
	public function getProperty($property, $default = null)
217
	{
218
		return $this->repository->getProperty($property, $default);
219
	}
220
221
	/**
222
	 * Set a module property value.
223
	 *
224
	 * @param  string $property
225
	 * @param  mixed  $value
226
	 * @return bool
227
	 */
228
	public function setProperty($property, $value)
229
	{
230
		return $this->repository->setProperty($property, $value);
231
	}
232
233
	/**
234
	 * Gets all enabled modules.
235
	 *
236
	 * @return array
237
	 */
238
	public function enabled()
239
	{
240
		return $this->repository->enabled();
241
	}
242
243
	/**
244
	 * Gets all disabled modules.
245
	 *
246
	 * @return array
247
	 */
248
	public function disabled()
249
	{
250
		return $this->repository->disabled();
251
	}
252
253
	/**
254
	 * Check if specified module is enabled.
255
	 *
256
	 * @param  string $slug
257
	 * @return bool
258
	 */
259
	public function isEnabled($slug)
260
	{
261
		return $this->repository->isEnabled($slug);
262
	}
263
264
	/**
265
	 * Check if specified module is disabled.
266
	 *
267
	 * @param  string $slug
268
	 * @return bool
269
	 */
270
	public function isDisabled($slug)
271
	{
272
		return $this->repository->isDisabled($slug);
273
	}
274
275
	/**
276
	 * Enables the specified module.
277
	 *
278
	 * @param  string $slug
279
	 * @return bool
280
	 */
281
	public function enable($slug)
282
	{
283
		return $this->repository->enable($slug);
284
	}
285
286
	/**
287
	 * Disables the specified module.
288
	 *
289
	 * @param  string $slug
290
	 * @return bool
291
	 */
292
	public function disable($slug)
293
	{
294
		return $this->repository->disable($slug);
295
	}
296
297
	/**
298
     * Refresh the cache with any newly found modules.
299
     *
300
     * @return bool
301
     */
302
    public function cache()
303
    {
304
        return $this->repository->cache();
305
    }
306
307
	/**
308
     * Get the contents of the cache file.
309
     *
310
     * The cache file lists all module slugs and their
311
     * enabled or disabled status. This can be used to
312
     * filter out modules depending on their status.
313
     *
314
     * @return Collection
315
     */
316
    public function getCache()
317
	{
318
		return $this->repository->getCache();
319
	}
320
321
	/**
322
     * Set the given cache key value.
323
     *
324
     * @param  string  $key
325
     * @param  mixed  $value
326
     * @return int
327
     */
328
    public function setCache($key, $value)
329
	{
330
		return $this->repository->setCache($key, $value);
331
	}
332
333
	/**
334
	 * Resolve the correct module namespace.
335
	 *
336
	 * @param array  $properties
337
	 */
338
	private function resolveNamespace($properties)
339
	{
340
		return (isset($properties['namespace'])
341
			? $properties['namespace']
342
			: studly_case($properties['slug'])
343
		);
344
	}
345
}
346