Completed
Push — develop ( 1afbdc...5783f5 )
by Aristeides
03:25
created

Kirki_Output_Field_Typography   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 54
rs 10
c 0
b 0
f 0
wmc 15
lcom 1
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
D process_output() 0 44 15
1
<?php
2
/**
3
 * Handles CSS output for typography 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_Typography 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['media_query'] = ( isset( $output['media_query'] ) ) ? $output['media_query'] : 'global';
27
		$output['element']     = ( isset( $output['element'] ) ) ? $output['element'] : 'body';
28
		$output['prefix']      = ( isset( $output['prefix'] ) ) ? $output['prefix'] : '';
29
		$output['suffix']      = ( isset( $output['suffix'] ) ) ? $output['suffix'] : '';
30
31
		if ( ! isset( $value['variant'] ) || ! isset( $value['font-weight'] ) || ! isset( $value['font-style'] ) ) {
32
			$value = Kirki_Field_Typography::sanitize( $value );
33
			$this->value = $value;
34
		}
35
36
		$properties = array(
37
			'font-family',
38
			'font-size',
39
			'font-weight',
40
			'font-style',
41
			'letter-spacing',
42
			'word-spacing',
43
			'line-height',
44
			'text-align',
45
			'text-transform',
46
			'color',
47
		);
48
49
		foreach ( $properties as $property ) {
50
			if ( ! isset( $value[ $property ] ) || '' === $value[ $property ] ) {
51
				continue;
52
			}
53
			if ( isset( $output['choice'] ) && $output['choice'] !== $property ) {
54
				continue;
55
			}
56
57
			$property_value = $this->process_property_value( $property, $value[ $property ] );
58
			if ( 'font-family' === $property ) {
59
				$value['font-backup'] = ( isset( $value['font-backup'] ) ) ? $value['font-backup'] : '';
60
				$property_value = $this->process_property_value( $property, array(
0 ignored issues
show
Documentation introduced by
array($value['font-famil... $value['font-backup']) is of type array<integer,?,{"0":"?","1":"?"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
61
					$value['font-family'],
62
					$value['font-backup'],
63
				) );
64
			}
65
			$this->styles[ $output['media_query'] ][ $output['element'] ][ $property ] = $output['prefix'] . $property_value . $output['suffix'];
66
		}
67
	}
68
}
69