Completed
Push — master ( 28a99d...1ea8a7 )
by Nassif
07:46
created

Presenter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
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
    public function __construct($model)
20
    {
21
        $this->model = $model;
22
    }
23
24
    /**
25
     * Get model attribute.
26
     *
27
     * @param $key
28
     * @return mixed
29
     */
30
    public function getAttribute($key)
31
    {
32
        return $this->model->getAttribute($key);
33
    }
34
35
    /**
36
     * Allow for property-style retrieval.
37
     *
38
     * @param $property
39
     * @return mixed
40
     */
41
    public function __get($property)
42
    {
43
        if (method_exists($this, $property)) {
44
            return $this->{$property}();
45
        }
46
47
        return $this->model->{$property};
48
    }
49
}
50