IpTrait   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 37
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __set() 0 9 2
A __get() 0 14 4
1
<?php
2
3
namespace devtoolboxuk\internetaddress;
4
5
trait IpTrait
6
{
7
    /**
8
     * @param $name
9
     * @return mixed
10
     * @throws \Exception
11
     */
12
    public function __get($name)
13
    {
14
        if (method_exists($this, $name)) {
15
            return $this->$name();
16
        }
17
18
        foreach (array('get', 'to') as $prefix) {
19
            $method = $prefix . ucfirst($name);
20
            if (method_exists($this, $method)) {
21
                return $this->$method();
22
            }
23
        }
24
25
        throw new \Exception(sprintf('%s is an undefined property', $name));
26
    }
27
28
    /**
29
     * @param $name
30
     * @param $value
31
     * @throws \Exception
32
     */
33
    public function __set($name, $value)
34
    {
35
        $method = 'set' . ucfirst($name);
36
        if (method_exists($this, $method)) {
37
            $this->$method($value);
38
            return;
39
40
        }
41
        throw new \Exception(sprintf('%s is an undefined property', $name));
42
    }
43
44
}
45