Presenter::__isset()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Laracodes\Presenter;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Support\Str;
7
8
abstract class Presenter
9
{
10
    /**
11
     * @var \Illuminate\Database\Eloquent\Model
12
     */
13
    protected $model;
14
15
    /**
16
     * @param \Illuminate\Database\Eloquent\Model $model
17
     */
18
    public function __construct(Model $model)
19
    {
20
        $this->model = $model;
21
    }
22
23
    /**
24
     * @param $property
25
     * @return bool
26
     */
27
    public function __isset($property)
28
    {
29
        return method_exists($this, Str::camel($property));
30
    }
31
32
    /**
33
     * @param $property
34
     * @return mixed
35
     */
36
    public function __get($property)
37
    {
38
        $camel_property = Str::camel($property);
39
40
        if (method_exists($this, $camel_property)) {
41
            return $this->{$camel_property}();
42
        }
43
44
        return $this->model->{Str::snake($property)};
45
    }
46
}
47