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 ( b5125b...c08d10 )
by Shea
06:09
created

Modules::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 8
Bugs 1 Features 2
Metric Value
c 8
b 1
f 2
dl 0
loc 5
rs 9.4285
ccs 3
cts 3
cp 1
cc 1
eloc 3
nc 1
nop 2
crap 1
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
	public function optimize()
82
	{
83
		return $this->repository->optimize();
84
	}
85
86
	/**
87
	 * Get all modules.
88
	 *
89
	 * @return Collection
90
	 */
91
	public function all()
92
	{
93
		return $this->repository->all();
94
	}
95
96
	/**
97
	 * Get all module slugs.
98
	 *
99
	 * @return array
100
	 */
101
	public function slugs()
102
	{
103
		return $this->repository->slugs();
104
	}
105
106
	/**
107
	 * Get modules based on where clause.
108
	 *
109
	 * @param  string  $key
110
	 * @param  mixed   $value
111
	 * @return Collection
112
	 */
113
	public function where($key, $value)
114
	{
115
		return $this->repository->where($key, $value);
116
	}
117
118
	/**
119
	 * Sort modules by given key in ascending order.
120
	 *
121
	 * @param  string  $key
122
	 * @return Collection
123
	 */
124
	public function sortBy($key)
125
	{
126
		return $this->repository->sortBy($key);
127
	}
128
129
	/**
130
	 * Sort modules by given key in ascending order.
131
	 *
132
	 * @param  string  $key
133
	 * @return Collection
134
	 */
135
	public function sortByDesc($key)
136
	{
137
		return $this->repository->sortByDesc($key);
138
	}
139
140
	/**
141
	 * Check if the given module exists.
142
	 *
143
	 * @param  string  $slug
144
	 * @return bool
145
	 */
146
	public function exists($slug)
147
	{
148
		return $this->repository->exists($slug);
149
	}
150
151
	/**
152
	 * Returns count of all modules.
153
	 *
154
	 * @return int
155
	 */
156
	public function count()
157
	{
158
		return $this->repository->count();
159
	}
160
161
	/**
162
	 * Get modules path.
163
	 *
164
	 * @return string
165
	 */
166
	public function getPath()
167
	{
168
		return $this->repository->getPath();
169
	}
170
171
	/**
172
	 * Set modules path in "RunTime" mode.
173
	 *
174
	 * @param  string $path
175
	 * @return object $this
176
	 */
177
	public function setPath($path)
178
	{
179
		return $this->repository->setPath($path);
180
	}
181
182
	/**
183
	* Get path for the specified module.
184
	*
185
	* @param  string $slug
186
	* @return string
187
	*/
188
	public function getModulePath($slug)
189
	{
190
		return $this->repository->getModulePath($slug);
191
	}
192
193
	/**
194
	* Get modules namespace.
195
	*
196
	* @return string
197
	*/
198
	public function getNamespace()
199
	{
200
		return $this->repository->getNamespace();
201
	}
202
203
	/**
204
	 * Get a module's properties.
205
	 *
206
	 * @param  string $slug
207
	 * @return mixed
208
	 */
209
	public function getManifest($slug)
210
	{
211
		return $this->repository->getManifest($slug);
212
	}
213
214
	/**
215
	 * Get a module property value.
216
	 *
217
	 * @param  string $property
218
	 * @param  mixed  $default
219
	 * @return mixed
220
	 */
221
	public function get($property, $default = null)
222
	{
223
		return $this->repository->get($property, $default);
224
	}
225
226
	/**
227
	 * Set a module property value.
228
	 *
229
	 * @param  string $property
230
	 * @param  mixed  $value
231
	 * @return bool
232
	 */
233
	public function set($property, $value)
234
	{
235
		return $this->repository->set($property, $value);
236
	}
237
238
	/**
239
	 * Gets all enabled modules.
240
	 *
241
	 * @return array
242
	 */
243
	public function enabled()
244
	{
245
		return $this->repository->enabled();
246
	}
247
248
	/**
249
	 * Gets all disabled modules.
250
	 *
251
	 * @return array
252
	 */
253
	public function disabled()
254
	{
255
		return $this->repository->disabled();
256
	}
257
258
	/**
259
	 * Check if specified module is enabled.
260
	 *
261
	 * @param  string $slug
262
	 * @return bool
263
	 */
264
	public function isEnabled($slug)
265
	{
266
		return $this->repository->isEnabled($slug);
267
	}
268
269
	/**
270
	 * Check if specified module is disabled.
271
	 *
272
	 * @param  string $slug
273
	 * @return bool
274
	 */
275
	public function isDisabled($slug)
276
	{
277
		return $this->repository->isDisabled($slug);
278
	}
279
280
	/**
281
	 * Enables the specified module.
282
	 *
283
	 * @param  string $slug
284
	 * @return bool
285
	 */
286
	public function enable($slug)
287
	{
288
		return $this->repository->enable($slug);
289
	}
290
291
	/**
292
	 * Disables the specified module.
293
	 *
294
	 * @param  string $slug
295
	 * @return bool
296
	 */
297
	public function disable($slug)
298
	{
299
		return $this->repository->disable($slug);
300
	}
301
302
	/**
303
	 * Resolve the correct module namespace.
304
	 *
305
	 * @param array  $properties
306
	 */
307
	private function resolveNamespace($properties)
308
	{
309
		return (isset($properties['namespace'])
310
			? $properties['namespace']
311
			: studly_case($properties['slug'])
312
		);
313
	}
314
}
315