Test Failed
Push — master ( b51ba3...2c95af )
by Alain
08:52 queued 07:06
created
src/DependencyManager.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -342,7 +342,7 @@
 block discarded – undo
342 342
 	protected function maybe_localize( $dependency, $context ) {
343 343
 		static $already_localized = [];
344 344
 		if ( ! array_key_exists( 'localize', $dependency )
345
-		     || array_key_exists( $dependency['handle'], $already_localized ) ) {
345
+			 || array_key_exists( $dependency['handle'], $already_localized ) ) {
346 346
 			return;
347 347
 		}
348 348
 
Please login to merge, or discard this patch.
Spacing   +93 added lines, -93 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,11 +247,11 @@  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
 
@@ -261,8 +261,8 @@  discard block
 block discarded – undo
261 261
 			$context
262 262
 		);
263 263
 
264
-		$this->maybe_localize( $dependency, $context );
265
-		$this->maybe_add_inline_script( $dependency, $context );
264
+		$this->maybe_localize($dependency, $context);
265
+		$this->maybe_add_inline_script($dependency, $context);
266 266
 
267 267
 		return true;
268 268
 	}
@@ -276,14 +276,14 @@  discard block
 block discarded – undo
276 276
 	 * @return array Array containing the dependency key as well as the
277 277
 	 *                       dependency array itself.
278 278
 	 */
279
-	protected function get_dependency_array( $handle ) {
280
-		foreach ( $this->dependencies as $type => $dependencies ) {
281
-			if ( array_key_exists( $handle, $dependencies ) ) {
282
-				return [ $type, $dependencies[ $handle ] ];
279
+	protected function get_dependency_array($handle) {
280
+		foreach ($this->dependencies as $type => $dependencies) {
281
+			if (array_key_exists($handle, $dependencies)) {
282
+				return [$type, $dependencies[$handle]];
283 283
 			}
284 284
 		}
285 285
 		// Handle not found, return an empty array.
286
-		return [ '', null ];
286
+		return ['', null];
287 287
 	}
288 288
 
289 289
 	/**
@@ -298,12 +298,12 @@  discard block
 block discarded – undo
298 298
 	 *                               dependency at key
299 299
 	 *                               'dependency_type'.
300 300
 	 */
301
-	protected function enqueue_dependency( $dependency, $dependency_key, $context = null ) {
302
-		if ( ! $this->is_needed( $dependency, $context ) ) {
301
+	protected function enqueue_dependency($dependency, $dependency_key, $context = null) {
302
+		if ( ! $this->is_needed($dependency, $context)) {
303 303
 			return;
304 304
 		}
305
-		$handler = $this->handlers[ $context['dependency_type'] ];
306
-		$handler->enqueue( $dependency );
305
+		$handler = $this->handlers[$context['dependency_type']];
306
+		$handler->enqueue($dependency);
307 307
 	}
308 308
 
309 309
 	/**
@@ -317,16 +317,16 @@  discard block
 block discarded – undo
317 317
 	 *                          'dependency_type'.
318 318
 	 * @return bool Whether it is needed or not.
319 319
 	 */
320
-	protected function is_needed( $dependency, $context ) {
321
-		$is_needed = array_key_exists( 'is_needed', $dependency )
320
+	protected function is_needed($dependency, $context) {
321
+		$is_needed = array_key_exists('is_needed', $dependency)
322 322
 			? $dependency['is_needed']
323 323
 			: null;
324 324
 
325
-		if ( null === $is_needed ) {
325
+		if (null === $is_needed) {
326 326
 			return true;
327 327
 		}
328 328
 
329
-		return is_callable( $is_needed ) && $is_needed( $context );
329
+		return is_callable($is_needed) && $is_needed($context);
330 330
 	}
331 331
 
332 332
 	/**
@@ -339,21 +339,21 @@  discard block
 block discarded – undo
339 339
 	 *                          Contains the type of the dependency at key
340 340
 	 *                          'dependency_type'.
341 341
 	 */
342
-	protected function maybe_localize( $dependency, $context ) {
342
+	protected function maybe_localize($dependency, $context) {
343 343
 		static $already_localized = [];
344
-		if ( ! array_key_exists( 'localize', $dependency )
345
-		     || array_key_exists( $dependency['handle'], $already_localized ) ) {
344
+		if ( ! array_key_exists('localize', $dependency)
345
+		     || array_key_exists($dependency['handle'], $already_localized)) {
346 346
 			return;
347 347
 		}
348 348
 
349 349
 		$localize = $dependency['localize'];
350 350
 		$data     = $localize['data'];
351
-		if ( is_callable( $data ) ) {
352
-			$data = $data( $context );
351
+		if (is_callable($data)) {
352
+			$data = $data($context);
353 353
 		}
354 354
 
355
-		wp_localize_script( $dependency['handle'], $localize['name'], $data );
356
-		$already_localized[ $dependency['handle'] ] = true;
355
+		wp_localize_script($dependency['handle'], $localize['name'], $data);
356
+		$already_localized[$dependency['handle']] = true;
357 357
 	}
358 358
 
359 359
 	/**
@@ -366,18 +366,18 @@  discard block
 block discarded – undo
366 366
 	 *                          Contains the type of the dependency at key
367 367
 	 *                          'dependency_type'.
368 368
 	 */
369
-	protected function maybe_add_inline_script( $dependency, $context ) {
370
-		if ( ! array_key_exists( 'add_inline', $dependency ) ) {
369
+	protected function maybe_add_inline_script($dependency, $context) {
370
+		if ( ! array_key_exists('add_inline', $dependency)) {
371 371
 			return;
372 372
 		}
373 373
 
374 374
 		$inline_script = $dependency['add_inline'];
375 375
 
376
-		if ( is_callable( $inline_script ) ) {
377
-			$inline_script = $inline_script( $context );
376
+		if (is_callable($inline_script)) {
377
+			$inline_script = $inline_script($context);
378 378
 		}
379 379
 
380
-		wp_add_inline_script( $dependency['handle'], $inline_script );
380
+		wp_add_inline_script($dependency['handle'], $inline_script);
381 381
 	}
382 382
 
383 383
 	/**
@@ -389,10 +389,10 @@  discard block
 block discarded – undo
389 389
 	 * @param string $handle The dependency handle to enqueue.
390 390
 	 * @return bool Returns whether the handle was found or not.
391 391
 	 */
392
-	protected function enqueue_fallback_handle( $handle ) {
392
+	protected function enqueue_fallback_handle($handle) {
393 393
 		$result = false;
394
-		foreach ( $this->handlers as $handler ) {
395
-			$result = $result || $handler->maybe_enqueue( $handle );
394
+		foreach ($this->handlers as $handler) {
395
+			$result = $result || $handler->maybe_enqueue($handle);
396 396
 		}
397 397
 		return $result;
398 398
 	}
@@ -407,9 +407,9 @@  discard block
 block discarded – undo
407 407
 	 * @param mixed  $context         Optional. The context to pass to the
408 408
 	 *                                dependencies.
409 409
 	 */
410
-	protected function enqueue_dependency_type( $dependencies, $dependency_type, $context = null ) {
410
+	protected function enqueue_dependency_type($dependencies, $dependency_type, $context = null) {
411 411
 		$context['dependency_type'] = $dependency_type;
412
-		array_walk( $dependencies, [ $this, 'enqueue_dependency' ], $context );
412
+		array_walk($dependencies, [$this, 'enqueue_dependency'], $context);
413 413
 	}
414 414
 
415 415
 	/**
@@ -422,9 +422,9 @@  discard block
 block discarded – undo
422 422
 	 * @param mixed  $context         Optional. The context to pass to the
423 423
 	 *                                dependencies.
424 424
 	 */
425
-	protected function register_dependency_type( $dependencies, $dependency_type, $context = null ) {
425
+	protected function register_dependency_type($dependencies, $dependency_type, $context = null) {
426 426
 		$context['dependency_type'] = $dependency_type;
427
-		array_walk( $dependencies, [ $this, 'register_dependency' ], $context );
427
+		array_walk($dependencies, [$this, 'register_dependency'], $context);
428 428
 	}
429 429
 
430 430
 	/**
@@ -439,12 +439,12 @@  discard block
 block discarded – undo
439 439
 	 *                               dependency at key
440 440
 	 *                               'dependency_type'.
441 441
 	 */
442
-	protected function register_dependency( $dependency, $dependency_key, $context = null ) {
443
-		$handler = $this->handlers[ $context['dependency_type'] ];
444
-		$handler->register( $dependency );
442
+	protected function register_dependency($dependency, $dependency_key, $context = null) {
443
+		$handler = $this->handlers[$context['dependency_type']];
444
+		$handler->register($dependency);
445 445
 
446
-		if ( $this->enqueue_immediately ) {
447
-			$this->register_enqueue_hooks( $dependency, $context );
446
+		if ($this->enqueue_immediately) {
447
+			$this->register_enqueue_hooks($dependency, $context);
448 448
 		}
449 449
 	}
450 450
 
@@ -458,15 +458,15 @@  discard block
 block discarded – undo
458 458
 	 *                          Contains the type of the dependency at key
459 459
 	 *                          'dependency_type'.
460 460
 	 */
461
-	protected function register_enqueue_hooks( $dependency, $context = null ) {
462
-		$priority = $this->get_priority( $dependency );
461
+	protected function register_enqueue_hooks($dependency, $context = null) {
462
+		$priority = $this->get_priority($dependency);
463 463
 
464
-		foreach ( [ 'wp_enqueue_scripts', 'admin_enqueue_scripts' ] as $hook ) {
465
-			add_action( $hook, [ $this, 'enqueue' ], $priority, 1 );
464
+		foreach (['wp_enqueue_scripts', 'admin_enqueue_scripts'] as $hook) {
465
+			add_action($hook, [$this, 'enqueue'], $priority, 1);
466 466
 		}
467 467
 
468
-		$this->maybe_localize( $dependency, $context );
469
-		$this->maybe_add_inline_script( $dependency, $context );
468
+		$this->maybe_localize($dependency, $context);
469
+		$this->maybe_add_inline_script($dependency, $context);
470 470
 	}
471 471
 
472 472
 	/**
@@ -477,9 +477,9 @@  discard block
 block discarded – undo
477 477
 	 * @param array $dependency Configuration data of the dependency.
478 478
 	 * @return int Priority to use.
479 479
 	 */
480
-	protected function get_priority( $dependency ) {
481
-		if ( array_key_exists( 'priority', $dependency ) ) {
482
-			return intval( $dependency['priority'] );
480
+	protected function get_priority($dependency) {
481
+		if (array_key_exists('priority', $dependency)) {
482
+			return intval($dependency['priority']);
483 483
 		}
484 484
 		return 10;
485 485
 	}
Please login to merge, or discard this patch.