Completed
Push — develop ( 5e223c...186db0 )
by Aristeides
02:51
created

Kirki_Output_Field_Dimensions   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 43
rs 10
c 0
b 0
f 0
wmc 10
lcom 1
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
D process_output() 0 33 10
1
<?php
2
/**
3
 * Handles CSS output for dimensions 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       2.2.0
10
 */
11
12
/**
13
 * Output overrides.
14
 */
15
class Kirki_Output_Field_Dimensions 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( $output, array(
27
			'element'     => '',
28
			'property'    => '',
29
			'media_query' => 'global',
30
			'prefix'      => '',
31
			'suffix'      => '',
32
		) );
33
34
		if ( is_array( $value ) ) {
35
			foreach ( $value as $key => $sub_value ) {
36
37
				$property = ( empty( $output['property'] ) ) ? $key : $output['property'] . '-' . $key;
38
				if ( isset( $output['choice'] ) && $output['property'] ) {
39
					if ( $key === $output['choice'] ) {
40
						$property = $output['property'];
41
					} else {
42
						continue;
43
					}
44
				}
45
				if ( false !== strpos( $output['property'], '%%' ) ) {
46
					$property = str_replace( '%%', $key, $output['property'] );
47
				}
48
				$this->styles[ $output['media_query'] ][ $output['element'] ][ $property ] = $output['prefix'] . $this->process_property_value( $property, $value[ $key ] ) . $output['suffix'];
49
			}
50
		} elseif ( isset( $output['choice'] ) ) {
51
			if ( false !== strpos( $output['property'], '%%' ) ) {
52
				$output['property'] = str_replace( '%%', $key, $output['property'] );
0 ignored issues
show
Bug introduced by
The variable $key seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
53
			}
54
			$this->styles[ $output['media_query'] ][ $output['element'] ][ $output['property'] ] = $output['prefix'] . $this->process_property_value( $output['property'], $value ) . $output['suffix'];
55
		}
56
	}
57
}
58