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

Kirki_Output_Property_Font_Family::process_value()   C

Complexity

Conditions 13
Paths 14

Size

Total Lines 42
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 13
eloc 21
nc 14
nop 0
dl 0
loc 42
rs 5.1234
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 font-family.
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_Property_Font_Family extends Kirki_Output_Property {
16
17
	/**
18
	 * Modifies the value.
19
	 *
20
	 * @access protected
21
	 */
22
	protected function process_value() {
23
24
		$google_fonts_array = Kirki_Fonts::get_google_fonts();
25
		$backup_fonts       = Kirki_Fonts::get_backup_fonts();
26
27
		$family = $this->value;
28
		$backup = '';
29
		if ( is_array( $this->value ) && isset( $this->value[0] ) && isset( $this->value[1] ) ) {
30
			$family = $this->value[0];
31
			$backup = $this->value[1];
32
		}
33
34
		// Make sure the value is a string.
35
		// If not, then early exit.
36
		if ( ! is_string( $family ) ) {
37
			return;
38
		}
39
40
		// Hack for standard fonts.
41
		$family = str_replace( '&quot;', '"', $family );
42
43
		// Add backup font.
44
		if ( Kirki_Fonts::is_google_font( $family ) ) {
45
46
			if ( '' === $backup && isset( $google_fonts_array[ $family ] ) && isset( $backup_fonts[ $google_fonts_array[ $family ]['category'] ] ) ) {
47
				$backup = $backup_fonts[ $google_fonts_array[ $family ]['category'] ];
48
			}
49
50
			// Add double quotes if needed.
51
			if ( false !== strpos( $family, ' ' ) && false === strpos( $family, '"' ) ) {
52
				$this->value = '"' . $family . '", ' . $backup;
53
				return;
54
			}
55
			$this->value = $family . ', ' . $backup;
56
			return;
57
		}
58
59
		// Add double quotes if needed.
60
		if ( false !== strpos( $family, ' ' ) && false === strpos( $family, '"' ) ) {
61
			$this->value = '"' . $family . '"';
62
		}
63
	}
64
}
65