Passed
Push — master ( 73fc8e...cf59c6 )
by Atanas
02:03
created

ExtendsConfigTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 0
cts 8
cp 0
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A extendConfig() 0 10 4
1
<?php
2
3
namespace WPEmerge\ServiceProviders;
4
5
/**
6
 * Allows objects to extend the config.
7
 */
8
trait ExtendsConfigTrait {
9
	/**
10
	 * Extends the WP Emerge config in the container with a new key.
11
	 *
12
	 * @param  \Pimple\Container $container
13
	 * @param  string            $key
14
	 * @param  mixed             $default
15
	 * @return void
16
	 */
17
	protected function extendConfig( $container, $key, $default ) {
18
		$config = isset( $container[ WPEMERGE_CONFIG_KEY ][ $key ] ) ? $container[ WPEMERGE_CONFIG_KEY ][ $key ] : $default;
19
20
		if ( is_array( $default ) && is_array( $config ) ) {
21
			$config = array_replace_recursive( $default, $config );
22
		}
23
24
		$container[ WPEMERGE_CONFIG_KEY ] = array_merge(
25
			$container[ WPEMERGE_CONFIG_KEY ],
26
			[ $key => $config ]
27
		);
28
	}
29
}
30