Test Failed
Push — master ( c6b6d3...528954 )
by Dan Michael O.
03:21
created

Model   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 68
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A make() 0 3 1
A init() 0 6 1
A getData() 0 4 1
A __get() 0 17 3
1
<?php
2
3
namespace Scriptotek\Alma;
4
5
abstract class Model
6
{
7
    /* @var Client */
8
    protected $client;
9
10
    /* @var \stdClass */
11
    protected $data;
12
13
    public function __construct(Client $client, $data = null)
14
    {
15
        $this->client = $client;
16
        $this->data = $data;
17
    }
18
19
    /**
20
     * @param Client $client
21
     * @param array ...$params
22
     * @return static
23
     */
24
	static function make($client, ...$params) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
25
		return new static($client, ...$params);
26
	}
27
28
    /**
29
     * Load data onto this object. Chainable method.
30
     *
31
     * @param \stdClass $data
32
     *
33
     * @return self
34
     */
35
    public function init($data = null)
36
    {
37
        $this->data = $data;
38
39
        return $this;
40
    }
41
42
    /**
43
     * Get the raw data object.
44
     */
45
    public function getData()
46
    {
47
        return $this->data;
48
    }
49
50
    /**
51
     * Magic!
52
     * @param string $key
53
     * @return mixed
54
     */
55
    public function __get($key)
56
    {
57
        // If there's a getter method, call it.
58
        $method = 'get' . ucfirst($key);
59
        if (method_exists($this, $method)) {
60
            return $this->$method();
61
        }
62
63
        $this->init();
64
65
        // If the property is defined in our data object, return it.
66
        if (isset($this->data->{$key})) {
67
            return $this->data->{$key};
68
        }
69
70
        return null;
71
    }
72
}