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

MakeInstance   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 30
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A make() 0 3 1
A instance() 0 5 1
A __construct() 0 10 4
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