CanBuild   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 10
c 1
b 0
f 0
dl 0
loc 33
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setBuild() 0 3 1
A isBuild() 0 3 1
A build() 0 4 2
A checkBuild() 0 7 2
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
}