Passed
Push — master ( 863ad3...126876 )
by Enrico
02:01
created

BootManagerTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 91.67%

Importance

Changes 0
Metric Value
wmc 6
eloc 13
dl 0
loc 46
c 0
b 0
f 0
ccs 11
cts 12
cp 0.9167
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 7 1
A boot() 0 15 5
1
<?php
2
3
/*
4
 * This file is part of the uSilex framework.
5
 *
6
 * (c) Enrico Fagnoni <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace uSilex\Pimple;
13
14
use Pimple\ServiceProviderInterface;
15
16
/**
17
 * BootManager trait. Manages Bootable providers
18
 *
19
 * @author Enrico Fagnoni <[email protected]>
20
 */
21
trait BootManagerTrait
22
{
23
24
    protected $providers = [];
25
    protected $booted = false;
26
    
27
    
28
    /**
29
     * Redefine Registers a service provider.
30
     *
31
     * @param ServiceProviderInterface $provider A ServiceProviderInterface instance
32
     * @param array                    $values   An array of values that customizes the provider
33
     *
34
     * @return Application
0 ignored issues
show
Bug introduced by
The type uSilex\Pimple\Application was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
35
     */
36 1
    public function register(ServiceProviderInterface $provider, array $values = []) 
37
    {
38 1
        $this->providers[] = $provider;
39
        
40 1
        parent::register($provider, $values);
41
        
42 1
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type uSilex\Pimple\BootManagerTrait which is incompatible with the documented return type uSilex\Pimple\Application.
Loading history...
43
    }
44
45
    
46
    /**
47
     * Boots all service providers.
48
     *
49
     * This method is automatically called by handle(), but you can use it
50
     * to boot all service providers when not handling a request.
51
     */
52 3
    public function boot()
53
    {
54 3
        if ($this->booted) {
55
            return;
56
        }
57
        
58 3
        $this->booted = true;
59
        
60 3
        foreach ($this->providers as $provider) {
61 1
            if ( ($provider instanceof ServiceProviderInterface) && method_exists($provider,'boot') ) {
62 1
                $provider->boot($this);
63
            }
64
        }
65
        
66 3
        return $this;
67
    }
68
}
69