Magic   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 43
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __get() 0 2 1
A get() 0 4 2
A __set() 0 2 1
A set() 0 5 2
1
<?php
2
/**
3
 * Trait Magic
4
 *
5
 * @filesource   Magic.php
6
 * @created      13.11.2017
7
 * @package      chillerlan\Traits
8
 * @author       Smiley <[email protected]>
9
 * @copyright    2017 Smiley
10
 * @license      MIT
11
 */
12
13
namespace chillerlan\Traits;
14
15
/**
16
 * A Container that turns methods into magic properties
17
 */
18
trait Magic{
19
20
	/**
21
	 * @param string $name
22
	 *
23
	 * @return mixed|null
24
	 */
25
	public function __get(string $name){
26
		return $this->get($name);
27
	}
28
29
	/**
30
	 * @param string $name
31
	 * @param mixed  $value
32
	 *
33
	 * @return void
34
	 */
35
	public function __set(string $name, $value):void{
36
		$this->set($name, $value);
37
	}
38
39
	/**
40
	 * @param string $name
41
	 *
42
	 * @return mixed|null
43
	 */
44
	private function get(string $name){
45
		$method = 'magic_get_'.$name;
46
47
		return \method_exists($this, $method) ? $this->$method() : null;
48
	}
49
50
	/**
51
	 * @param string $name
52
	 * @param        $value
53
	 *
54
	 * @return void
55
	 */
56
	private function set(string $name, $value):void{
57
		$method = 'magic_set_'.$name;
58
59
		if(\method_exists($this, $method)){
60
			$this->$method($value);
61
		}
62
63
	}
64
65
}
66