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

ExtendsConfigTrait::extendConfig()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
eloc 6
nc 4
nop 3
dl 0
loc 10
ccs 0
cts 8
cp 0
crap 20
rs 9.2
c 0
b 0
f 0
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