Passed
Pull Request — master (#79)
by Mohannad
11:37
created

Bootable::isBooted()   A

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 BeyondCode\QueryDetector\Concerns;
4
5
trait Bootable
6
{
7
    /** @var bool */
8
    protected $booted = false;
9
10
    /**
11
     * Safely boot if wasn't booted before
12
     *
13
     * @return void
14
     */
15
    public function bootIfNotBooted() : void
16
    {
17
        if ($this->isBooted()) {
18
            return;
19
        }
20
21
        $this->boot();
22
        $this->booted();
23
    }
24
25
    /**
26
     * Runs after "boot"
27
     *
28
     * @return void
29
     */
30
    protected function booted() : void
31
    {
32
        $this->booted = true;
33
    }
34
35
    /**
36
     * Determine if already booted
37
     *
38
     * @return bool
39
     */
40
    public function isBooted()
41
    {
42
        return $this->booted;
43
    }
44
45
    protected function boot() : void
46
    {
47
    }
48
}