Model_Base   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 9
eloc 23
c 2
b 0
f 0
dl 0
loc 66
ccs 24
cts 24
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A set() 0 11 3
A __construct() 0 7 2
A __call() 0 18 4
1
<?php
2
3
namespace Clubdeuce\WPGoogleMaps;
4
5
/**
6
 * Class Model_Base
7
 * @package Clubdeuce\WPGoogleMaps
8
 *
9
 * @method array extra_args()
10
 */
11
class Model_Base {
12
13
	/**
14
	 * @var array
15
	 */
16
	protected $_extra_args;
17
18
	/**
19
	 * Model_Base constructor.
20
	 *
21
	 * @param array $args
22
	 */
23 10
	public function __construct( $args = array() ) {
24
25 10
		$args = wp_parse_args( $args );
26
27 10
		foreach ( $args as $key => $value ) {
28
29 9
			$this->set( $key, $value );
30
31
		}
32
33 10
	}
34
35
	/**
36
	 * @param string $property
37
	 * @param mixed  $value
38
	 */
39 3
	public function set( $property, $value ) {
40
41
		do {
42 3
			if ( property_exists( get_called_class(), "_{$property}" ) ) {
43 1
				$property = "_{$property}";
44 1
				$this->{$property} = $value;
45 1
				break;
46
			}
47
48 3
			$this->_extra_args[ $property ] = $value;
49 3
		} while ( false );
50
51 3
	}
52
53
	/**
54
	 * @param string $method_name
55
	 * @param array  $args
56
	 *
57
	 * @return mixed|null
58
	 */
59 16
	public function __call( $method_name, $args ) {
60
61 16
		$value = null;
62
63
		do {
64 16
			if ( property_exists( $this, "_{$method_name}" ) ) {
65 16
				$property = "_{$method_name}";
66 16
				$value    = $this->{$property};
67 16
				break;
68
			}
69
70 3
			if ( isset( $this->extra_args()[ $method_name ] ) ) {
71 2
				$value = $this->extra_args()[ $method_name ];
72 2
				break;
73
			}
74 1
		} while ( false );
75
76 16
		return $value;
77
78
	}
79
80
}
81