Passed
Push — develop ( 640e2a...1d775a )
by Aristeides
04:02
created

Kirki_Output_Field_Background   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 10
c 0
b 0
f 0
wmc 7

1 Method

Rating   Name   Duplication   Size   Complexity  
B process_output() 0 21 7
1
<?php
2
/**
3
 * Handles CSS output for background fields.
4
 *
5
 * @package     Kirki
6
 * @subpackage  Controls
7
 * @copyright   Copyright (c) 2017, Aristeides Stathopoulos
8
 * @license     http://opensource.org/licenses/https://opensource.org/licenses/MIT
9
 * @since       3.0.0
10
 */
11
12
/**
13
 * Output overrides.
14
 */
15
class Kirki_Output_Field_Background extends Kirki_Output {
16
17
	/**
18
	 * Processes a single item from the `output` array.
19
	 *
20
	 * @access protected
21
	 * @param array $output The `output` item.
22
	 * @param array $value  The field's value.
23
	 */
24
	protected function process_output( $output, $value ) {
25
26
		$output = wp_parse_args(
27
			$output,
28
			array(
29
				'media_query' => 'global',
30
				'element'     => 'body',
31
				'prefix'      => '',
32
				'suffix'      => '',
33
			)
34
		);
35
36
		foreach ( array( 'background-image', 'background-color', 'background-repeat', 'background-position', 'background-size', 'background-attachment' ) as $property ) {
37
38
			// See https://github.com/aristath/kirki/issues/1808.
39
			if ( 'background-color' === $property && ( ! isset( $value['background-image'] ) || empty( $value['background-image'] ) ) ) {
40
				$this->styles[ $output['media_query'] ][ $output['element'] ]['background'] = $output['prefix'] . $this->process_property_value( $property, $value[ $property ] ) . $output['suffix'];
0 ignored issues
show
Bug introduced by
Are you sure $this->process_property_...rty, $value[$property]) of type array can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

40
				$this->styles[ $output['media_query'] ][ $output['element'] ]['background'] = $output['prefix'] . /** @scrutinizer ignore-type */ $this->process_property_value( $property, $value[ $property ] ) . $output['suffix'];
Loading history...
41
			}
42
43
			if ( isset( $value[ $property ] ) && ! empty( $value[ $property ] ) ) {
44
				$this->styles[ $output['media_query'] ][ $output['element'] ][ $property ] = $output['prefix'] . $this->process_property_value( $property, $value[ $property ] ) . $output['suffix'];
45
			}
46
		}
47
	}
48
}
49