Presenter::__get()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Tequilarapido\Presenter;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
abstract class Presenter
8
{
9
    /**
10
     * Model.
11
     *
12
     * @var Model
13
     */
14
    protected $model;
15
16
    /**
17
     * @param $model
18
     */
19 2
    public function __construct($model)
20
    {
21 2
        $this->model = $model;
22 2
    }
23
24
    /**
25
     * Get model attribute.
26
     *
27
     * @param $key
28
     * @return mixed
29
     */
30 1
    public function getAttribute($key)
31
    {
32 1
        return $this->model->getAttribute($key);
33
    }
34
35
    /**
36
     * Allow for property-style retrieval.
37
     *
38
     * @param $property
39
     * @return mixed
40
     */
41 1
    public function __get($property)
42
    {
43 1
        if (method_exists($this, $property)) {
44 1
            return $this->{$property}();
45
        }
46
47 1
        return $this->model->{$property};
48
    }
49
}
50