| @@ -48,7 +48,7 @@ discard block | ||
| 48 | 48 | * | 
| 49 | 49 | * @var array; | 
| 50 | 50 | */ | 
| 51 | - protected $dependencies = [ ]; | |
| 51 | + protected $dependencies = []; | |
| 52 | 52 | |
| 53 | 53 | /** | 
| 54 | 54 | * Hold the handlers. | 
| @@ -57,7 +57,7 @@ discard block | ||
| 57 | 57 | * | 
| 58 | 58 | * @var array | 
| 59 | 59 | */ | 
| 60 | - protected $handlers = [ ]; | |
| 60 | + protected $handlers = []; | |
| 61 | 61 | |
| 62 | 62 | /** | 
| 63 | 63 | * Instantiate DependencyManager object. | 
| @@ -70,8 +70,8 @@ discard block | ||
| 70 | 70 | * @throws InvalidArgumentException If no dependency handlers were | 
| 71 | 71 | * specified. | 
| 72 | 72 | */ | 
| 73 | -	public function __construct( ConfigInterface $config ) { | |
| 74 | - $this->processConfig( $config ); | |
| 73 | +	public function __construct(ConfigInterface $config) { | |
| 74 | + $this->processConfig($config); | |
| 75 | 75 | $this->init_handlers(); | 
| 76 | 76 | $this->init_dependencies(); | 
| 77 | 77 | } | 
| @@ -82,10 +82,10 @@ discard block | ||
| 82 | 82 | * @since 0.1.0 | 
| 83 | 83 | */ | 
| 84 | 84 |  	protected function init_handlers() { | 
| 85 | - $keys = [ self::KEY_SCRIPTS, self::KEY_STYLES ]; | |
| 86 | -		foreach ( $keys as $key ) { | |
| 87 | -			if ( $this->hasConfigKey( $key ) ) { | |
| 88 | - $this->add_handler( $key ); | |
| 85 | + $keys = [self::KEY_SCRIPTS, self::KEY_STYLES]; | |
| 86 | +		foreach ($keys as $key) { | |
| 87 | +			if ($this->hasConfigKey($key)) { | |
| 88 | + $this->add_handler($key); | |
| 89 | 89 | } | 
| 90 | 90 | } | 
| 91 | 91 | } | 
| @@ -97,13 +97,13 @@ discard block | ||
| 97 | 97 | * | 
| 98 | 98 | * @param string $dependency The dependency type for which to add a handler. | 
| 99 | 99 | */ | 
| 100 | -	protected function add_handler( $dependency ) { | |
| 101 | -		if ( $this->hasConfigKey( $dependency ) ) { | |
| 102 | - $handler = $this->hasConfigKey( self::KEY_HANDLERS, $dependency ) | |
| 103 | - ? $this->getConfigKey( self::KEY_HANDLERS, $dependency ) | |
| 104 | - : $this->get_default_handler( $dependency ); | |
| 105 | -			if ( $handler ) { | |
| 106 | - $this->handlers[ $dependency ] = $handler; | |
| 100 | +	protected function add_handler($dependency) { | |
| 101 | +		if ($this->hasConfigKey($dependency)) { | |
| 102 | + $handler = $this->hasConfigKey(self::KEY_HANDLERS, $dependency) | |
| 103 | + ? $this->getConfigKey(self::KEY_HANDLERS, $dependency) | |
| 104 | + : $this->get_default_handler($dependency); | |
| 105 | +			if ($handler) { | |
| 106 | + $this->handlers[$dependency] = $handler; | |
| 107 | 107 | } | 
| 108 | 108 | } | 
| 109 | 109 | } | 
| @@ -116,8 +116,8 @@ discard block | ||
| 116 | 116 | * @param string $dependency The dependency that needs a handler. | 
| 117 | 117 | * @return string|null Class name of the handler. Null if none. | 
| 118 | 118 | */ | 
| 119 | -	protected function get_default_handler( $dependency ) { | |
| 120 | -		switch ( $dependency ) { | |
| 119 | +	protected function get_default_handler($dependency) { | |
| 120 | +		switch ($dependency) { | |
| 121 | 121 | case self::KEY_STYLES: | 
| 122 | 122 | return self::DEFAULT_STYLE_HANDLER; | 
| 123 | 123 | case self::KEY_SCRIPTS: | 
| @@ -133,10 +133,10 @@ discard block | ||
| 133 | 133 | * @since 0.1.0 | 
| 134 | 134 | */ | 
| 135 | 135 |  	protected function init_dependencies() { | 
| 136 | - array_walk( $this->handlers, | |
| 137 | -			function ( $handler, $dependency_type ) { | |
| 138 | -				if ( $this->hasConfigKey( $dependency_type ) ) { | |
| 139 | - $this->dependencies[ $dependency_type ] = $this->getConfigKey( $dependency_type ); | |
| 136 | + array_walk($this->handlers, | |
| 137 | +			function($handler, $dependency_type) { | |
| 138 | +				if ($this->hasConfigKey($dependency_type)) { | |
| 139 | + $this->dependencies[$dependency_type] = $this->getConfigKey($dependency_type); | |
| 140 | 140 | } | 
| 141 | 141 | } ); | 
| 142 | 142 | } | 
| @@ -148,10 +148,10 @@ discard block | ||
| 148 | 148 | * | 
| 149 | 149 | * @param mixed $context Optional. The context to pass to the dependencies. | 
| 150 | 150 | */ | 
| 151 | -	public function register( $context = null ) { | |
| 152 | - $context = $this->validate_context( $context ); | |
| 153 | - array_walk( $this->dependencies, | |
| 154 | - [ $this, 'register_dependency_type' ], $context ); | |
| 151 | +	public function register($context = null) { | |
| 152 | + $context = $this->validate_context($context); | |
| 153 | + array_walk($this->dependencies, | |
| 154 | + [$this, 'register_dependency_type'], $context); | |
| 155 | 155 | } | 
| 156 | 156 | |
| 157 | 157 | /** | 
| @@ -162,9 +162,9 @@ discard block | ||
| 162 | 162 | * @param mixed $context The context as passed in by WordPress. | 
| 163 | 163 | * @return array Validated context. | 
| 164 | 164 | */ | 
| 165 | -	protected function validate_context( $context ) { | |
| 166 | -		if ( is_string( $context ) ) { | |
| 167 | - return [ 'wp_context' => $context ]; | |
| 165 | +	protected function validate_context($context) { | |
| 166 | +		if (is_string($context)) { | |
| 167 | + return ['wp_context' => $context]; | |
| 168 | 168 | } | 
| 169 | 169 | return (array) $context; | 
| 170 | 170 | } | 
| @@ -176,10 +176,10 @@ discard block | ||
| 176 | 176 | * | 
| 177 | 177 | * @param mixed $context Optional. The context to pass to the dependencies. | 
| 178 | 178 | */ | 
| 179 | -	public function enqueue( $context = null ) { | |
| 180 | - $context = $this->validate_context( $context ); | |
| 181 | - array_walk( $this->dependencies, | |
| 182 | - [ $this, 'enqueue_dependency_type' ], $context ); | |
| 179 | +	public function enqueue($context = null) { | |
| 180 | + $context = $this->validate_context($context); | |
| 181 | + array_walk($this->dependencies, | |
| 182 | + [$this, 'enqueue_dependency_type'], $context); | |
| 183 | 183 | } | 
| 184 | 184 | |
| 185 | 185 | /** | 
| @@ -192,9 +192,9 @@ discard block | ||
| 192 | 192 | * @param mixed $context Optional. The context to pass to the | 
| 193 | 193 | * dependencies. | 
| 194 | 194 | */ | 
| 195 | -	protected function enqueue_dependency_type( $dependencies, $dependency_type, $context = null ) { | |
| 195 | +	protected function enqueue_dependency_type($dependencies, $dependency_type, $context = null) { | |
| 196 | 196 | $context['dependency_type'] = $dependency_type; | 
| 197 | - array_walk( $dependencies, [ $this, 'enqueue_dependency' ], $context ); | |
| 197 | + array_walk($dependencies, [$this, 'enqueue_dependency'], $context); | |
| 198 | 198 | } | 
| 199 | 199 | |
| 200 | 200 | /** | 
| @@ -207,9 +207,9 @@ discard block | ||
| 207 | 207 | * @param mixed $context Optional. The context to pass to the | 
| 208 | 208 | * dependencies. | 
| 209 | 209 | */ | 
| 210 | -	protected function register_dependency_type( $dependencies, $dependency_type, $context = null ) { | |
| 210 | +	protected function register_dependency_type($dependencies, $dependency_type, $context = null) { | |
| 211 | 211 | $context['dependency_type'] = $dependency_type; | 
| 212 | - array_walk( $dependencies, [ $this, 'register_dependency' ], $context ); | |
| 212 | + array_walk($dependencies, [$this, 'register_dependency'], $context); | |
| 213 | 213 | } | 
| 214 | 214 | |
| 215 | 215 | /** | 
| @@ -224,16 +224,16 @@ discard block | ||
| 224 | 224 | * dependency at key | 
| 225 | 225 | * 'dependency_type'. | 
| 226 | 226 | */ | 
| 227 | -	protected function register_dependency( $dependency, $dependency_key, $context = null ) { | |
| 227 | +	protected function register_dependency($dependency, $dependency_key, $context = null) { | |
| 228 | 228 | /** @var \BrightNucleus\Contract\Registerable $handler */ | 
| 229 | 229 | $handler = new $this->handlers[$context['dependency_type']]; | 
| 230 | - $handler->register( $dependency ); | |
| 231 | - \add_action( 'wp_enqueue_scripts', | |
| 232 | - [ $this, 'enqueue' ] ); | |
| 233 | - \add_action( 'admin_enqueue_scripts', | |
| 234 | - [ $this, 'enqueue' ] ); | |
| 235 | -		if ( array_key_exists( 'localize', $dependency ) ) { | |
| 236 | - $this->localize( $dependency, $context ); | |
| 230 | + $handler->register($dependency); | |
| 231 | +		\add_action('wp_enqueue_scripts', | |
| 232 | + [$this, 'enqueue']); | |
| 233 | +		\add_action('admin_enqueue_scripts', | |
| 234 | + [$this, 'enqueue']); | |
| 235 | +		if (array_key_exists('localize', $dependency)) { | |
| 236 | + $this->localize($dependency, $context); | |
| 237 | 237 | } | 
| 238 | 238 | } | 
| 239 | 239 | |
| @@ -247,13 +247,13 @@ discard block | ||
| 247 | 247 | * Contains the type of the dependency at key | 
| 248 | 248 | * 'dependency_type'. | 
| 249 | 249 | */ | 
| 250 | -	protected function localize( $dependency, $context ) { | |
| 250 | +	protected function localize($dependency, $context) { | |
| 251 | 251 | $localize = $dependency['localize']; | 
| 252 | 252 | $data = $localize['data']; | 
| 253 | -		if ( is_callable( $data ) ) { | |
| 254 | - $data = $data( $context ); | |
| 253 | +		if (is_callable($data)) { | |
| 254 | + $data = $data($context); | |
| 255 | 255 | } | 
| 256 | - \wp_localize_script( $dependency['handle'], $localize['name'], $data ); | |
| 256 | + \wp_localize_script($dependency['handle'], $localize['name'], $data); | |
| 257 | 257 | } | 
| 258 | 258 | |
| 259 | 259 | /** | 
| @@ -268,13 +268,13 @@ discard block | ||
| 268 | 268 | * dependency at key | 
| 269 | 269 | * 'dependency_type'. | 
| 270 | 270 | */ | 
| 271 | -	protected function enqueue_dependency( $dependency, $dependency_key, $context = null ) { | |
| 272 | -		if ( ! $this->is_needed( $dependency, $context ) ) { | |
| 271 | +	protected function enqueue_dependency($dependency, $dependency_key, $context = null) { | |
| 272 | +		if ( ! $this->is_needed($dependency, $context)) { | |
| 273 | 273 | return; | 
| 274 | 274 | } | 
| 275 | 275 | /** @var \BrightNucleus\Contract\Enqueueable $handler */ | 
| 276 | 276 | $handler = new $this->handlers[$context['dependency_type']]; | 
| 277 | - $handler->enqueue( $dependency ); | |
| 277 | + $handler->enqueue($dependency); | |
| 278 | 278 | } | 
| 279 | 279 | |
| 280 | 280 | /** | 
| @@ -288,15 +288,15 @@ discard block | ||
| 288 | 288 | * 'dependency_type'. | 
| 289 | 289 | * @return bool Whether it is needed or not. | 
| 290 | 290 | */ | 
| 291 | -	protected function is_needed( $dependency, $context ) { | |
| 292 | - $is_needed = array_key_exists( 'is_needed', $dependency ) | |
| 291 | +	protected function is_needed($dependency, $context) { | |
| 292 | +		$is_needed = array_key_exists('is_needed', $dependency) | |
| 293 | 293 | ? $dependency['is_needed'] | 
| 294 | 294 | : null; | 
| 295 | 295 | |
| 296 | -		if ( null === $is_needed ) { | |
| 296 | +		if (null === $is_needed) { | |
| 297 | 297 | return true; | 
| 298 | 298 | } | 
| 299 | 299 | |
| 300 | - return is_callable( $is_needed ) && $is_needed( $context ); | |
| 300 | + return is_callable($is_needed) && $is_needed($context); | |
| 301 | 301 | } | 
| 302 | 302 | } |