Completed
Push — master ( c62de5...a864f4 )
by Johnny
02:23
created

EntityAbstract   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
c 1
b 0
f 1
lcom 0
cbo 0
dl 0
loc 55
ccs 0
cts 35
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B __call() 0 32 5
A trigger_error() 0 7 1
1
<?php
2
namespace Redbox\Twitch\Entity;
3
4
abstract class EntityAbstract
5
{
6
    /**
7
     * Generate magic functions.
8
     *
9
     * @param string $name
10
     * @param array $args
11
     * @return null
12
     */
13
    public function __call($name = '', $args = [])
14
    {
15
        $action   = strtolower(substr($name,0, 3));
16
        $trace    = debug_backtrace();
17
18
        switch($action) {
19
            case 'get':
20
                $name   = substr($name, 3);
21
                $param  = lcfirst($name);
22
23
                if (property_exists($this, $param) === true){
24
                    return $this->$param;
25
                } else {
26
                    $this->trigger_error($name, $trace);
27
                }
28
                break;
29
30
            case 'set':
31
                $name   = substr($name, 3);
32
                $param = lcfirst($name);
33
34
                if (property_exists($this, $param) === true){
35
                    $this->$param = $args[0];
36
                } else {
37
                    $this->trigger_error($name, $trace);
38
                }
39
            break;
40
            default:
41
                $this->trigger_error($name, $trace);
42
                break;
43
        }
44
    }
45
46
    /**
47
     * @param string $name
48
     * @param array $trace
49
     */
50
    private function trigger_error($name = '', $trace = array()) {
51
        trigger_error(
52
            'Call to undefined method: '.$name.
53
            ' in '.$trace[0]['file'].
54
            ' on line '.$trace[0]['line'],
55
            E_USER_ERROR);
56
    }
57
58
}