Model::with()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
cc 3
eloc 5
nc 3
nop 1
crap 3
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 2
    public function with(...$types) {
22 2
        foreach ($types as $type) {
23 2
            if (method_exists($this, strtolower($type)))
24 2
                call_user_func([$this, $type]);
25
        }
26
27 2
        return $this;
28
    }
29
30
    /**
31
     * @param $name
32
     * @return mixed
33
     * @throws \Exception
34
     */
35 4
    public function __get($name)
36
    {
37 4
        if (in_array($name, $this->magicProperties)) {
38 4
            return call_user_func([$this, $name]);
39
        }
40
41 1
        throw new \Exception('Property ' . $name . ' does not exist in this class');
42
    }
43
}