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

Bootable   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 8
c 1
b 0
f 0
dl 0
loc 42
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A booted() 0 3 1
A isBooted() 0 3 1
A bootIfNotBooted() 0 8 2
A boot() 0 2 1
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
}