Passed
Push — hotfix/fix-counts ( 87b43a...93ec32 )
by Paul
06:17
created

Field::merge()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 1
dl 0
loc 9
ccs 0
cts 9
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Modules\Html\Fields;
4
5
use GeminiLabs\SiteReviews\Modules\Html\Builder;
6
7
abstract class Field
8
{
9
	/**
10
	 * @var Builder
11
	 */
12
	protected $builder;
13
14
	public function __construct( Builder $builder )
15
	{
16
		$this->builder = $builder;
17
	}
18
19
	/**
20
	 * @return string|void
21
	 */
22
	public function build()
23
	{
24
		glsr_log()->error( 'Build method is not implemented for '.get_class( $this ));
25
	}
26
27
	/**
28
	 * @return array
29
	 */
30
	public static function defaults()
31
	{
32
		return [];
33
	}
34
35
	/**
36
	 * @return array
37
	 */
38
	public static function merge( array $args )
39
	{
40
		$merged = array_merge(
41
			wp_parse_args( $args, static::defaults() ),
42
			static::required()
43
		);
44
		$merged['class'] = implode( ' ', static::mergedAttribute( 'class', ' ', $args ));
0 ignored issues
show
Bug introduced by
static::mergedAttribute('class', ' ', $args) of type void is incompatible with the type array expected by parameter $pieces of implode(). ( Ignorable by Annotation )

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

44
		$merged['class'] = implode( ' ', /** @scrutinizer ignore-type */ static::mergedAttribute( 'class', ' ', $args ));
Loading history...
Bug introduced by
Are you sure the usage of static::mergedAttribute('class', ' ', $args) targeting GeminiLabs\SiteReviews\M...ield::mergedAttribute() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
45
		$merged['style'] = implode( ';', static::mergedAttribute( 'style', ';', $args ));
0 ignored issues
show
Bug introduced by
Are you sure the usage of static::mergedAttribute('style', ';', $args) targeting GeminiLabs\SiteReviews\M...ield::mergedAttribute() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
46
		return $merged;
47
	}
48
49
	/**
50
	 * @param string $delimiter
51
	 * @param string $key
52
	 * @return void
53
	 */
54
	public static function mergedAttribute( $key, $delimiter, array $args )
55
	{
56
		return array_filter( array_merge(
0 ignored issues
show
Bug Best Practice introduced by
The expression return array_filter(arra...c::required(), $key)))) returns the type array which is incompatible with the documented return type void.
Loading history...
57
			explode( $delimiter, glsr_get( $args, $key )),
58
			explode( $delimiter, glsr_get( static::defaults(), $key )),
59
			explode( $delimiter, glsr_get( static::required(), $key ))
60
		));
61
	}
62
63
	/**
64
	 * @return array
65
	 */
66
	public static function required()
67
	{
68
		return [];
69
	}
70
71
	/**
72
	 * @return void
73
	 */
74
	protected function mergeFieldArgs()
75
	{
76
		$this->builder->args = static::merge( $this->builder->args );
77
	}
78
}
79