GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

BootstrapAwareTrait::initBootstrappers()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Nip\Application\Bootstrap;
4
5
use Nip\Application\Bootstrap\Bootstrapers\AbstractBootstraper;
6
use Nip\Container\ContainerInterface;
7
8
/**
9
 * Class BootstrapAwareTrait
10
 * @package Nip\Application\Bootstrap
11
 */
12
trait BootstrapAwareTrait
13
{
14
15
    /**
16
     * Indicates if the application has been bootstrapped before.
17
     *
18
     * @var bool
19
     */
20
    protected $hasBeenBootstrapped = false;
21
22
    /**
23
     * The bootstrap classes for the application.
24
     *
25
     * @var null|AbstractBootstraper[]
26
     */
27
    protected $bootstrappers = null;
28
29
    /**
30
     * Bootstrap the application for HTTP requests.
31
     *
32
     * @return void
33
     */
34
    public function bootstrap()
35
    {
36
        if (!$this->hasBeenBootstrapped()) {
37
            $this->bootstrapWith($this->bootstrappers());
38
        }
39
    }
40
41
    /**
42
     * Determine if the application has been bootstrapped before.
43
     *
44
     * @return bool
45
     */
46
    public function hasBeenBootstrapped()
47
    {
48
        return $this->hasBeenBootstrapped;
49
    }
50
51
    /**
52
     * Run the given array of bootstrap classes.
53
     *
54
     * @param  array $bootstrappers
55
     * @return void
56
     */
57
    public function bootstrapWith(array $bootstrappers)
58
    {
59
        $this->hasBeenBootstrapped = true;
60
        foreach ($bootstrappers as $bootstrapper) {
61
            $this->getBootstrap($bootstrapper)->bootstrap($this);
62
        }
63
    }
64
65
    /**
66
     * @param $bootstrapper
67
     * @return AbstractBootstraper
68
     */
69
    public function getBootstrap($bootstrapper)
70
    {
71
        if ($this->getContainer() instanceof ContainerInterface) {
0 ignored issues
show
Bug introduced by
It seems like getContainer() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
72
            return $this->get($bootstrapper);
0 ignored issues
show
Bug introduced by
It seems like get() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
73
        }
74
        return new $bootstrapper;
75
    }
76
77
    /**
78
     * Get the bootstrap classes for the application.
79
     *
80
     * @return array
81
     */
82
    protected function bootstrappers()
83
    {
84
        if ($this->bootstrappers === null) {
85
            $this->initBootstrappers();
86
        }
87
        return $this->bootstrappers;
88
    }
89
90
    /**
91
     * @param AbstractBootstraper $bootstrapper
92
     */
93
    protected function addBootstrapper($bootstrapper)
94
    {
95
        $this->bootstrappers[] = $bootstrapper;
96
    }
97
98
    protected function initBootstrappers()
99
    {
100
        $this->bootstrappers = $this->getDefaultBootstrappers();
101
    }
102
103
    /**
104
     * @return AbstractBootstraper[]
105
     */
106
    protected function getDefaultBootstrappers()
107
    {
108
        return [];
109
    }
110
}
111