Completed
Push — develop ( a03475...8ba485 )
by Aristeides
02:49
created

Kirki_Output_Field_Background::process_output()   F

Complexity

Conditions 18
Paths 2048

Size

Total Lines 38
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 18
eloc 18
nc 2048
nop 2
dl 0
loc 38
rs 2.7087
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Handles CSS output for background fields.
4
 *
5
 * @package     Kirki
6
 * @subpackage  Controls
7
 * @copyright   Copyright (c) 2016, Aristeides Stathopoulos
8
 * @license     http://opensource.org/licenses/https://opensource.org/licenses/MIT
9
 * @since       3.0.0
10
 */
11
12
if ( ! class_exists( 'Kirki_Output_Field_Background' ) ) {
13
14
	/**
15
	 * Output overrides.
16
	 */
17
	class Kirki_Output_Field_Background extends Kirki_Output {
18
19
		/**
20
		 * Processes a single item from the `output` array.
21
		 *
22
		 * @access protected
23
		 * @param array $output The `output` item.
24
		 * @param array $value  The field's value.
25
		 */
26
		protected function process_output( $output, $value ) {
27
28
			$output['media_query'] = ( isset( $output['media_query'] ) ) ? $output['media_query'] : 'global';
29
			$output['element']     = ( isset( $output['element'] ) ) ? $output['element'] : 'body';
30
			$output['prefix']      = ( isset( $output['prefix'] ) ) ? $output['prefix'] : '';
31
			$output['suffix']      = ( isset( $output['suffix'] ) ) ? $output['suffix'] : '';
32
			$output['media_query'] = ( isset( $output['media_query'] ) ) ? $output['media_query'] : 'global';
33
34
			// Background-image.
35
			if ( isset( $value['background-image'] ) && ! empty( $value['background-image'] ) ) {
36
				$this->styles[ $output['media_query'] ][ $output['element'] ]['background-image'] = $output['prefix'] . $this->process_property_value( 'background-image', $value['background-image'] ) . $output['suffix'];
37
			}
38
39
			// Background-color.
40
			if ( isset( $value['background-color'] ) && ! empty( $value['background-color'] ) ) {
41
				$this->styles[ $output['media_query'] ][ $output['element'] ]['background-color'] = $output['prefix'] . $this->process_property_value( 'background-color', $value['background-color'] ) . $output['suffix'];
42
			}
43
44
			// Background-repeat.
45
			if ( isset( $value['background-repeat'] ) && ! empty( $value['background-repeat'] ) ) {
46
				$this->styles[ $output['media_query'] ][ $output['element'] ]['background-repeat'] = $output['prefix'] . $this->process_property_value( 'background-repeat', $value['background-repeat'] ) . $output['suffix'];
47
			}
48
49
			// Background-position.
50
			if ( isset( $value['background-position'] ) && ! empty( $value['background-position'] ) ) {
51
				$this->styles[ $output['media_query'] ][ $output['element'] ]['background-position'] = $output['prefix'] . $this->process_property_value( 'background-position', $value['background-position'] ) . $output['suffix'];
52
			}
53
54
			// Background-size.
55
			if ( isset( $value['background-size'] ) && ! empty( $value['background-size'] ) ) {
56
				$this->styles[ $output['media_query'] ][ $output['element'] ]['background-size'] = $output['prefix'] . $this->process_property_value( 'background-size', $value['background-size'] ) . $output['suffix'];
57
			}
58
59
			// Background-attachment.
60
			if ( isset( $value['background-attachment'] ) && ! empty( $value['background-attachment'] ) ) {
61
				$this->styles[ $output['media_query'] ][ $output['element'] ]['background-attachment'] = $output['prefix'] . $this->process_property_value( 'background-attachment', $value['background-attachment'] ) . $output['suffix'];
62
			}
63
		}
64
	}
65
} // End if().
66