Completed
Push — master ( 5db87b...2ca7c0 )
by Stephen
02:42
created

Model   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 90%
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 35
ccs 9
cts 10
cp 0.9
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A with() 0 8 3
A __get() 0 8 2
1
<?php
2
namespace StarCitizen\Models;
3
4
/**
5
 * Class BaseModel
6
 *
7
 * @package StarCitizen\Models;
8
 */
9
abstract class Model
10
{
11
    /**
12
     * @var array
13
     */
14
    protected $magicProperties = [];
15
16
    /**
17
     * @param array ...$types
18
     *
19
     * @return $this
20
     */
21 1
    public function with(...$types) {
22 1
        foreach ($types as $type) {
23 1
            if (method_exists($this, strtolower($type)))
24 1
                call_user_func([$this, $type]);
25 1
        }
26
27 1
        return $this;
28
    }
29
30
    /**
31
     * @param $name
32
     * @return mixed
33
     * @throws \Exception
34
     */
35 2
    public function __get($name)
36
    {
37 2
        if (in_array($name, $this->magicProperties)) {
38 2
            return call_user_func([$this, $name]);
39
        }
40
41
        throw new \Exception('Property ' . $name . ' does not exist in this class');
42
    }
43
}