Completed
Push — master ( cbe8ef...7fefce )
by Nasrul Hazim
02:07
created

MakeInstance::instance()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace CleaniqueCoders\OpenPayroll\Traits;
4
5
trait MakeInstance
6
{
7
    public $instance;
8
9
    public function __construct($identifier)
10
    {
11
        if (is_string($identifier) || is_int($identifier)) {
12
            $this->instance = $this->getModel()::query()
13
                ->with('type')
14
                ->findByHashSlugOrId($identifier);
15
        }
16
17
        if (is_object($identifier)) {
18
            $this->instance($identifier);
19
        }
20
    }
21
22
    public static function make($identifier)
23
    {
24
        return new self($identifier);
25
    }
26
27
    public function instance($instance)
28
    {
29
        $this->instance = $instance;
30
31
        return $this;
32
    }
33
34
    abstract public function getModel();
35
}
36