Passed
Push — master ( 8a0962...507d84 )
by Paul
03:52
created

DefaultsAbstract   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 81.82%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 35
ccs 9
cts 11
cp 0.8182
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __call() 0 8 2
A merge() 0 3 1
A restrict() 0 3 1
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Defaults;
4
5
use GeminiLabs\SiteReviews\Helper;
6
use ReflectionClass;
7
8
abstract class DefaultsAbstract
9
{
10
	/**
11
	 * @param string $name
12
	 * @return void|array
13
	 */
14 7
	public function __call( $name, array $args = [] )
15
	{
16 7
		if( !method_exists( $this, $name ))return;
17 7
		$defaults = call_user_func_array( [$this, $name], $args );
18 7
		$className = (new ReflectionClass( $this ))->getShortName();
19 7
		$className = str_replace( 'Defaults', '', $className );
20 7
		$className = glsr( Helper::class )->dashCase( $className );
21 7
		return apply_filters( 'site-reviews/defaults/'.$className, $defaults, $name );
22
	}
23
24
	/**
25
	 * @return array
26
	 */
27
	abstract protected function defaults();
28
29
	/**
30
	 * @return array
31
	 */
32
	protected function merge( array $values = [] )
33
	{
34
		return wp_parse_args( $values, $this->defaults() );
35
	}
36
37
	/**
38
	 * @return array
39
	 */
40 7
	protected function restrict( array $values = [] )
41
	{
42 7
		return shortcode_atts( $this->defaults(), $values );
43
	}
44
}
45