Test Failed
Push — master ( 7d4916...b2ad12 )
by Alain
01:54
created
src/AbstractDependencyHandler.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@
 block discarded – undo
60 60
 	 */
61 61
 	public function enqueue( $args = null ) {
62 62
 		if ( array_key_exists( 'handle', $args )
63
-		     && $this->is_enqueued( $args['handle'] ) ) {
63
+			 && $this->is_enqueued( $args['handle'] ) ) {
64 64
 			return;
65 65
 		}
66 66
 
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -35,8 +35,8 @@  discard block
 block discarded – undo
35 35
 	 * @throws InvalidArgumentException If the register function could not be
36 36
 	 *                                  called.
37 37
 	 */
38
-	public function register( $args = null ) {
39
-		$this->invokeFunction( $this->get_register_function(), (array) $args );
38
+	public function register($args = null) {
39
+		$this->invokeFunction($this->get_register_function(), (array) $args);
40 40
 	}
41 41
 
42 42
 	/**
@@ -58,13 +58,13 @@  discard block
 block discarded – undo
58 58
 	 * @throws InvalidArgumentException If the register function could not be
59 59
 	 *                                  called.
60 60
 	 */
61
-	public function enqueue( $args = null ) {
62
-		if ( array_key_exists( 'handle', $args )
63
-		     && $this->is_enqueued( $args['handle'] ) ) {
61
+	public function enqueue($args = null) {
62
+		if (array_key_exists('handle', $args)
63
+		     && $this->is_enqueued($args['handle'])) {
64 64
 			return;
65 65
 		}
66 66
 
67
-		$this->invokeFunction( $this->get_enqueue_function(), (array) $args );
67
+		$this->invokeFunction($this->get_enqueue_function(), (array) $args);
68 68
 	}
69 69
 
70 70
 	/**
@@ -85,14 +85,14 @@  discard block
 block discarded – undo
85 85
 	 * @param string $handle Handle of the dependency to enqueue.
86 86
 	 * @return bool Whether the handle was found or not.
87 87
 	 */
88
-	public function maybe_enqueue( $handle ) {
89
-		if ( $this->is_enqueued( $handle ) ) {
88
+	public function maybe_enqueue($handle) {
89
+		if ($this->is_enqueued($handle)) {
90 90
 			return true;
91 91
 		}
92 92
 
93
-		if ( $this->is_registered( $handle ) ) {
93
+		if ($this->is_registered($handle)) {
94 94
 			$enqueue = $this->get_enqueue_function();
95
-			$enqueue( $handle );
95
+			$enqueue($handle);
96 96
 			return true;
97 97
 		}
98 98
 		return false;
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 	 * @param string $handle The handle to check
107 107
 	 * @return bool Whether it is enqueued or not.
108 108
 	 */
109
-	abstract public function is_enqueued( $handle );
109
+	abstract public function is_enqueued($handle);
110 110
 
111 111
 	/**
112 112
 	 * Check whether a specific handle has been registered.
@@ -117,5 +117,5 @@  discard block
 block discarded – undo
117 117
 	 * @param string $handle The handle to check
118 118
 	 * @return bool Whether it is registered or not.
119 119
 	 */
120
-	abstract public function is_registered( $handle );
120
+	abstract public function is_registered($handle);
121 121
 }
Please login to merge, or discard this patch.
src/DependencyManager.php 1 patch
Spacing   +98 added lines, -98 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 	 *
51 51
 	 * @var array;
52 52
 	 */
53
-	protected $dependencies = [ ];
53
+	protected $dependencies = [];
54 54
 
55 55
 	/**
56 56
 	 * Hold the handlers.
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 	 *
60 60
 	 * @var DependencyHandlerInterface[]
61 61
 	 */
62
-	protected $handlers = [ ];
62
+	protected $handlers = [];
63 63
 
64 64
 	/**
65 65
 	 * Whether to enqueue immediately upon registration.
@@ -83,8 +83,8 @@  discard block
 block discarded – undo
83 83
 	 * @throws InvalidArgumentException If no dependency handlers were
84 84
 	 *                                  specified.
85 85
 	 */
86
-	public function __construct( ConfigInterface $config, $enqueue = true ) {
87
-		$this->processConfig( $config );
86
+	public function __construct(ConfigInterface $config, $enqueue = true) {
87
+		$this->processConfig($config);
88 88
 		$this->enqueue_immediately = $enqueue;
89 89
 		$this->init_handlers();
90 90
 		$this->init_dependencies();
@@ -96,10 +96,10 @@  discard block
 block discarded – undo
96 96
 	 * @since 0.1.0
97 97
 	 */
98 98
 	protected function init_handlers() {
99
-		$keys = [ self::KEY_SCRIPTS, self::KEY_STYLES ];
100
-		foreach ( $keys as $key ) {
101
-			if ( $this->hasConfigKey( $key ) ) {
102
-				$this->add_handler( $key );
99
+		$keys = [self::KEY_SCRIPTS, self::KEY_STYLES];
100
+		foreach ($keys as $key) {
101
+			if ($this->hasConfigKey($key)) {
102
+				$this->add_handler($key);
103 103
 			}
104 104
 		}
105 105
 	}
@@ -111,13 +111,13 @@  discard block
 block discarded – undo
111 111
 	 *
112 112
 	 * @param string $dependency The dependency type for which to add a handler.
113 113
 	 */
114
-	protected function add_handler( $dependency ) {
115
-		if ( $this->hasConfigKey( $dependency ) ) {
116
-			$handler = $this->hasConfigKey( self::KEY_HANDLERS, $dependency )
117
-				? $this->getConfigKey( self::KEY_HANDLERS, $dependency )
118
-				: $this->get_default_handler( $dependency );
119
-			if ( $handler ) {
120
-				$this->handlers[ $dependency ] = new $handler;
114
+	protected function add_handler($dependency) {
115
+		if ($this->hasConfigKey($dependency)) {
116
+			$handler = $this->hasConfigKey(self::KEY_HANDLERS, $dependency)
117
+				? $this->getConfigKey(self::KEY_HANDLERS, $dependency)
118
+				: $this->get_default_handler($dependency);
119
+			if ($handler) {
120
+				$this->handlers[$dependency] = new $handler;
121 121
 			}
122 122
 		}
123 123
 	}
@@ -130,8 +130,8 @@  discard block
 block discarded – undo
130 130
 	 * @param string $dependency The dependency that needs a handler.
131 131
 	 * @return string|null Class name of the handler. Null if none.
132 132
 	 */
133
-	protected function get_default_handler( $dependency ) {
134
-		switch ( $dependency ) {
133
+	protected function get_default_handler($dependency) {
134
+		switch ($dependency) {
135 135
 			case self::KEY_STYLES:
136 136
 				return self::DEFAULT_STYLE_HANDLER;
137 137
 			case self::KEY_SCRIPTS:
@@ -147,10 +147,10 @@  discard block
 block discarded – undo
147 147
 	 * @since 0.1.0
148 148
 	 */
149 149
 	protected function init_dependencies() {
150
-		array_walk( $this->handlers,
151
-			function ( $handler, $dependency_type ) {
152
-				if ( $this->hasConfigKey( $dependency_type ) ) {
153
-					$this->dependencies[ $dependency_type ] = $this->init_dependency_type( $dependency_type );
150
+		array_walk($this->handlers,
151
+			function($handler, $dependency_type) {
152
+				if ($this->hasConfigKey($dependency_type)) {
153
+					$this->dependencies[$dependency_type] = $this->init_dependency_type($dependency_type);
154 154
 				}
155 155
 			} );
156 156
 	}
@@ -163,13 +163,13 @@  discard block
 block discarded – undo
163 163
 	 * @param string $type The type of dependency to initialize.
164 164
 	 * @return array Array of dependency configurations.
165 165
 	 */
166
-	protected function init_dependency_type( $type ) {
167
-		$array = [ ];
168
-		$data  = $this->getConfigKey( $type );
169
-		foreach ( $data as $dependency ) {
170
-			$handle           = array_key_exists( 'handle',
171
-				$dependency ) ? $dependency['handle'] : '';
172
-			$array[ $handle ] = $dependency;
166
+	protected function init_dependency_type($type) {
167
+		$array = [];
168
+		$data  = $this->getConfigKey($type);
169
+		foreach ($data as $dependency) {
170
+			$handle           = array_key_exists('handle',
171
+				$dependency) ? $dependency['handle'] : '';
172
+			$array[$handle] = $dependency;
173 173
 		}
174 174
 		return $array;
175 175
 	}
@@ -181,10 +181,10 @@  discard block
 block discarded – undo
181 181
 	 *
182 182
 	 * @param mixed $context Optional. The context to pass to the dependencies.
183 183
 	 */
184
-	public function register( $context = null ) {
185
-		$context = $this->validate_context( $context );
186
-		array_walk( $this->dependencies,
187
-			[ $this, 'register_dependency_type' ], $context );
184
+	public function register($context = null) {
185
+		$context = $this->validate_context($context);
186
+		array_walk($this->dependencies,
187
+			[$this, 'register_dependency_type'], $context);
188 188
 	}
189 189
 
190 190
 	/**
@@ -195,9 +195,9 @@  discard block
 block discarded – undo
195 195
 	 * @param mixed $context The context as passed in by WordPress.
196 196
 	 * @return array Validated context.
197 197
 	 */
198
-	protected function validate_context( $context ) {
199
-		if ( is_string( $context ) ) {
200
-			return [ 'wp_context' => $context ];
198
+	protected function validate_context($context) {
199
+		if (is_string($context)) {
200
+			return ['wp_context' => $context];
201 201
 		}
202 202
 		return (array) $context;
203 203
 	}
@@ -210,11 +210,11 @@  discard block
 block discarded – undo
210 210
 	 * @param mixed $context  Optional. The context to pass to the
211 211
 	 *                        dependencies.
212 212
 	 */
213
-	public function enqueue( $context = null ) {
214
-		$context = $this->validate_context( $context );
213
+	public function enqueue($context = null) {
214
+		$context = $this->validate_context($context);
215 215
 
216
-		array_walk( $this->dependencies,
217
-			[ $this, 'enqueue_dependency_type' ], $context );
216
+		array_walk($this->dependencies,
217
+			[$this, 'enqueue_dependency_type'], $context);
218 218
 	}
219 219
 
220 220
 	/**
@@ -229,9 +229,9 @@  discard block
 block discarded – undo
229 229
 	 *                         outside of DependencyManager. Defaults to false.
230 230
 	 * @return bool Returns whether the handle was found or not.
231 231
 	 */
232
-	public function enqueue_handle( $handle, $context = null, $fallback = false ) {
233
-		if ( ! $this->enqueue_internal_handle( $handle, $context ) ) {
234
-			return $this->enqueue_fallback_handle( $handle );
232
+	public function enqueue_handle($handle, $context = null, $fallback = false) {
233
+		if ( ! $this->enqueue_internal_handle($handle, $context)) {
234
+			return $this->enqueue_fallback_handle($handle);
235 235
 		}
236 236
 		return true;
237 237
 	}
@@ -247,18 +247,18 @@  discard block
 block discarded – undo
247 247
 	 *                         dependencies.
248 248
 	 * @return bool Returns whether the handle was found or not.
249 249
 	 */
250
-	protected function enqueue_internal_handle( $handle, $context = null ) {
251
-		list( $dependency_type, $dependency ) = $this->get_dependency_array( $handle );
250
+	protected function enqueue_internal_handle($handle, $context = null) {
251
+		list($dependency_type, $dependency) = $this->get_dependency_array($handle);
252 252
 		$context['dependency_type'] = $dependency_type;
253 253
 
254
-		if ( ! $dependency ) {
254
+		if ( ! $dependency) {
255 255
 			return false;
256 256
 		}
257 257
 
258
-		$handler = array_key_exists( $dependency_type, $this->handlers )
259
-			? $this->handlers[ $dependency_type ]
258
+		$handler = array_key_exists($dependency_type, $this->handlers)
259
+			? $this->handlers[$dependency_type]
260 260
 			: null;
261
-		if ( $handler && $handler->is_enqueued( $handle ) ) {
261
+		if ($handler && $handler->is_enqueued($handle)) {
262 262
 			return true;
263 263
 		}
264 264
 
@@ -268,8 +268,8 @@  discard block
 block discarded – undo
268 268
 			$context
269 269
 		);
270 270
 
271
-		$this->maybe_localize( $dependency, $context );
272
-		$this->maybe_add_inline_script( $dependency, $context );
271
+		$this->maybe_localize($dependency, $context);
272
+		$this->maybe_add_inline_script($dependency, $context);
273 273
 
274 274
 		return true;
275 275
 	}
@@ -283,14 +283,14 @@  discard block
 block discarded – undo
283 283
 	 * @return array Array containing the dependency key as well as the
284 284
 	 *                       dependency array itself.
285 285
 	 */
286
-	protected function get_dependency_array( $handle ) {
287
-		foreach ( $this->dependencies as $type => $dependencies ) {
288
-			if ( array_key_exists( $handle, $dependencies ) ) {
289
-				return [ $type, $dependencies[ $handle ] ];
286
+	protected function get_dependency_array($handle) {
287
+		foreach ($this->dependencies as $type => $dependencies) {
288
+			if (array_key_exists($handle, $dependencies)) {
289
+				return [$type, $dependencies[$handle]];
290 290
 			}
291 291
 		}
292 292
 		// Handle not found, return an empty array.
293
-		return [ '', null ];
293
+		return ['', null];
294 294
 	}
295 295
 
296 296
 	/**
@@ -305,19 +305,19 @@  discard block
 block discarded – undo
305 305
 	 *                               dependency at key
306 306
 	 *                               'dependency_type'.
307 307
 	 */
308
-	protected function enqueue_dependency( $dependency, $dependency_key, $context = null ) {
309
-		$handler = $this->handlers[ $context['dependency_type'] ];
310
-		$handle  = array_key_exists( 'handle', $dependency ) ? $dependency['handle'] : '';
308
+	protected function enqueue_dependency($dependency, $dependency_key, $context = null) {
309
+		$handler = $this->handlers[$context['dependency_type']];
310
+		$handle  = array_key_exists('handle', $dependency) ? $dependency['handle'] : '';
311 311
 
312
-		if ( $handle && $handler->is_enqueued( $handle ) ) {
312
+		if ($handle && $handler->is_enqueued($handle)) {
313 313
 			return;
314 314
 		}
315 315
 
316
-		if ( ! $this->is_needed( $dependency, $context ) ) {
316
+		if ( ! $this->is_needed($dependency, $context)) {
317 317
 			return;
318 318
 		}
319 319
 
320
-		$handler->enqueue( $dependency );
320
+		$handler->enqueue($dependency);
321 321
 	}
322 322
 
323 323
 	/**
@@ -331,16 +331,16 @@  discard block
 block discarded – undo
331 331
 	 *                          'dependency_type'.
332 332
 	 * @return bool Whether it is needed or not.
333 333
 	 */
334
-	protected function is_needed( $dependency, $context ) {
335
-		$is_needed = array_key_exists( 'is_needed', $dependency )
334
+	protected function is_needed($dependency, $context) {
335
+		$is_needed = array_key_exists('is_needed', $dependency)
336 336
 			? $dependency['is_needed']
337 337
 			: null;
338 338
 
339
-		if ( null === $is_needed ) {
339
+		if (null === $is_needed) {
340 340
 			return true;
341 341
 		}
342 342
 
343
-		return is_callable( $is_needed ) && $is_needed( $context );
343
+		return is_callable($is_needed) && $is_needed($context);
344 344
 	}
345 345
 
346 346
 	/**
@@ -353,21 +353,21 @@  discard block
 block discarded – undo
353 353
 	 *                          Contains the type of the dependency at key
354 354
 	 *                          'dependency_type'.
355 355
 	 */
356
-	protected function maybe_localize( $dependency, $context ) {
356
+	protected function maybe_localize($dependency, $context) {
357 357
 		static $already_localized = [];
358
-		if ( ! array_key_exists( 'localize', $dependency )
359
-		     || array_key_exists( $dependency['handle'], $already_localized ) ) {
358
+		if ( ! array_key_exists('localize', $dependency)
359
+		     || array_key_exists($dependency['handle'], $already_localized)) {
360 360
 			return;
361 361
 		}
362 362
 
363 363
 		$localize = $dependency['localize'];
364 364
 		$data     = $localize['data'];
365
-		if ( is_callable( $data ) ) {
366
-			$data = $data( $context );
365
+		if (is_callable($data)) {
366
+			$data = $data($context);
367 367
 		}
368 368
 
369
-		wp_localize_script( $dependency['handle'], $localize['name'], $data );
370
-		$already_localized[ $dependency['handle'] ] = true;
369
+		wp_localize_script($dependency['handle'], $localize['name'], $data);
370
+		$already_localized[$dependency['handle']] = true;
371 371
 	}
372 372
 
373 373
 	/**
@@ -380,18 +380,18 @@  discard block
 block discarded – undo
380 380
 	 *                          Contains the type of the dependency at key
381 381
 	 *                          'dependency_type'.
382 382
 	 */
383
-	protected function maybe_add_inline_script( $dependency, $context ) {
384
-		if ( ! array_key_exists( 'add_inline', $dependency ) ) {
383
+	protected function maybe_add_inline_script($dependency, $context) {
384
+		if ( ! array_key_exists('add_inline', $dependency)) {
385 385
 			return;
386 386
 		}
387 387
 
388 388
 		$inline_script = $dependency['add_inline'];
389 389
 
390
-		if ( is_callable( $inline_script ) ) {
391
-			$inline_script = $inline_script( $context );
390
+		if (is_callable($inline_script)) {
391
+			$inline_script = $inline_script($context);
392 392
 		}
393 393
 
394
-		wp_add_inline_script( $dependency['handle'], $inline_script );
394
+		wp_add_inline_script($dependency['handle'], $inline_script);
395 395
 	}
396 396
 
397 397
 	/**
@@ -403,10 +403,10 @@  discard block
 block discarded – undo
403 403
 	 * @param string $handle The dependency handle to enqueue.
404 404
 	 * @return bool Returns whether the handle was found or not.
405 405
 	 */
406
-	protected function enqueue_fallback_handle( $handle ) {
406
+	protected function enqueue_fallback_handle($handle) {
407 407
 		$result = false;
408
-		foreach ( $this->handlers as $handler ) {
409
-			$result = $result || $handler->maybe_enqueue( $handle );
408
+		foreach ($this->handlers as $handler) {
409
+			$result = $result || $handler->maybe_enqueue($handle);
410 410
 		}
411 411
 		return $result;
412 412
 	}
@@ -421,9 +421,9 @@  discard block
 block discarded – undo
421 421
 	 * @param mixed  $context         Optional. The context to pass to the
422 422
 	 *                                dependencies.
423 423
 	 */
424
-	protected function enqueue_dependency_type( $dependencies, $dependency_type, $context = null ) {
424
+	protected function enqueue_dependency_type($dependencies, $dependency_type, $context = null) {
425 425
 		$context['dependency_type'] = $dependency_type;
426
-		array_walk( $dependencies, [ $this, 'enqueue_dependency' ], $context );
426
+		array_walk($dependencies, [$this, 'enqueue_dependency'], $context);
427 427
 	}
428 428
 
429 429
 	/**
@@ -436,9 +436,9 @@  discard block
 block discarded – undo
436 436
 	 * @param mixed  $context         Optional. The context to pass to the
437 437
 	 *                                dependencies.
438 438
 	 */
439
-	protected function register_dependency_type( $dependencies, $dependency_type, $context = null ) {
439
+	protected function register_dependency_type($dependencies, $dependency_type, $context = null) {
440 440
 		$context['dependency_type'] = $dependency_type;
441
-		array_walk( $dependencies, [ $this, 'register_dependency' ], $context );
441
+		array_walk($dependencies, [$this, 'register_dependency'], $context);
442 442
 	}
443 443
 
444 444
 	/**
@@ -453,12 +453,12 @@  discard block
 block discarded – undo
453 453
 	 *                               dependency at key
454 454
 	 *                               'dependency_type'.
455 455
 	 */
456
-	protected function register_dependency( $dependency, $dependency_key, $context = null ) {
457
-		$handler = $this->handlers[ $context['dependency_type'] ];
458
-		$handler->register( $dependency );
456
+	protected function register_dependency($dependency, $dependency_key, $context = null) {
457
+		$handler = $this->handlers[$context['dependency_type']];
458
+		$handler->register($dependency);
459 459
 
460
-		if ( $this->enqueue_immediately ) {
461
-			$this->register_enqueue_hooks( $dependency, $context );
460
+		if ($this->enqueue_immediately) {
461
+			$this->register_enqueue_hooks($dependency, $context);
462 462
 		}
463 463
 	}
464 464
 
@@ -472,15 +472,15 @@  discard block
 block discarded – undo
472 472
 	 *                          Contains the type of the dependency at key
473 473
 	 *                          'dependency_type'.
474 474
 	 */
475
-	protected function register_enqueue_hooks( $dependency, $context = null ) {
476
-		$priority = $this->get_priority( $dependency );
475
+	protected function register_enqueue_hooks($dependency, $context = null) {
476
+		$priority = $this->get_priority($dependency);
477 477
 
478
-		foreach ( [ 'wp_enqueue_scripts', 'admin_enqueue_scripts' ] as $hook ) {
479
-			add_action( $hook, [ $this, 'enqueue' ], $priority, 1 );
478
+		foreach (['wp_enqueue_scripts', 'admin_enqueue_scripts'] as $hook) {
479
+			add_action($hook, [$this, 'enqueue'], $priority, 1);
480 480
 		}
481 481
 
482
-		$this->maybe_localize( $dependency, $context );
483
-		$this->maybe_add_inline_script( $dependency, $context );
482
+		$this->maybe_localize($dependency, $context);
483
+		$this->maybe_add_inline_script($dependency, $context);
484 484
 	}
485 485
 
486 486
 	/**
@@ -491,9 +491,9 @@  discard block
 block discarded – undo
491 491
 	 * @param array $dependency Configuration data of the dependency.
492 492
 	 * @return int Priority to use.
493 493
 	 */
494
-	protected function get_priority( $dependency ) {
495
-		if ( array_key_exists( 'priority', $dependency ) ) {
496
-			return intval( $dependency['priority'] );
494
+	protected function get_priority($dependency) {
495
+		if (array_key_exists('priority', $dependency)) {
496
+			return intval($dependency['priority']);
497 497
 		}
498 498
 		return 10;
499 499
 	}
Please login to merge, or discard this patch.