Presentable::present()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 4
nc 3
nop 0
1
<?php
2
3
namespace Laracodes\Presenter\Traits;
4
5
use Laracodes\Presenter\Exceptions\PresenterException;
6
7
trait Presentable
8
{
9
    /**
10
     * @var \Laracodes\Presenter\Presenter
11
     */
12
    protected $presenterInstance;
13
14
    /**
15
     * @return mixed
16
     * @throws PresenterException
17
     */
18
    public function present()
19
    {
20
        if (is_object($this->presenterInstance)) {
21
            return $this->presenterInstance;
22
        }
23
24
        if (property_exists($this, 'presenter') && class_exists($this->presenter)) {
25
            return $this->presenterInstance = new $this->presenter($this);
26
        }
27
28
        throw new PresenterException('Property $presenter was not set correctly in ' . get_class($this));
29
    }
30
}
31