CanBuild::isBuild()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace ByTIC\Models\SmartProperties\Definitions\Definition;
4
5
/**
6
 * Trait CanBuild
7
 * @package ByTIC\Models\SmartProperties\Definitions\Traits
8
 */
9
trait CanBuild
10
{
11
    protected $build = false;
12
13
    protected function checkBuild()
14
    {
15
        if ($this->isBuild()) {
16
           return;
17
        }
18
        $this->build();
19
        $this->build = true;
20
    }
21
22
    /**
23
     * @return bool
24
     */
25
    public function isBuild(): bool
26
    {
27
        return $this->build === true;
28
    }
29
30
    /**
31
     * @param bool $build
32
     */
33
    public function setBuild(\Closure $build)
34
    {
35
        $this->build = $build;
36
    }
37
38
    protected function build()
39
    {
40
        if ($this->build instanceof \Closure) {
0 ignored issues
show
introduced by
$this->build is never a sub-type of Closure.
Loading history...
41
            call_user_func($this->build);
42
        }
43
    }
44
}