Test Failed
Push — master ( 1c8415...9f6059 )
by Julien
04:01
created

ServiceProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 1 Features 1
Metric Value
wmc 3
eloc 11
c 3
b 1
f 1
dl 0
loc 38
ccs 0
cts 10
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 29 3
1
<?php
2
/**
3
 * This file is part of the Zemit Framework.
4
 *
5
 * (c) Zemit Team <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE.txt
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Zemit\Provider\Config;
12
13
use Phalcon\Di\DiInterface;
14
use Zemit\Bootstrap;
15
use Zemit\Bootstrap\Config;
16
use Zemit\Provider\AbstractServiceProvider;
17
18
/**
19
 * Class ServiceProvider
20
 *
21
 * @author Julien Turbide <[email protected]>
22
 * @copyright Zemit Team <[email protected]>
23
 *
24
 * @since 1.0
25
 * @version 1.0
26
 *
27
 * @package Zemit\Provider\Config
28
 */
29
class ServiceProvider extends AbstractServiceProvider
30
{
31
    protected $serviceName = 'config';
32
    
33
    /**
34
     * {@inheritdoc}
35
     *
36
     * @param DiInterface $di
37
     */
38
    public function register(DiInterface $di = null): void
39
    {
40
        // Set shared service in DI
41
        $di->setShared($this->getName(), function() use ($di) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
42
            
43
            /** @var Bootstrap $bootstrap */
44
            $bootstrap = $di->get('bootstrap');
0 ignored issues
show
Bug introduced by
The method get() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

44
            /** @scrutinizer ignore-call */ 
45
            $bootstrap = $di->get('bootstrap');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
45
            
46
            $config = $bootstrap->config ?? new Config();
47
            if (is_string($config) && class_exists($config)) {
0 ignored issues
show
introduced by
The condition is_string($config) is always false.
Loading history...
48
                $config = new $config();
49
            }
50
            
51
            // Inject some dynamic variables
52
            $config->mode = $di->get('bootstrap')->getMode();
0 ignored issues
show
Bug Best Practice introduced by
The property mode does not exist on Zemit\Bootstrap\Config. Since you implemented __set, consider adding a @property annotation.
Loading history...
53
            
54
            // Merge config with current environment
55
            $config->mergeEnvConfig();
56
            
57
            // Launch bootstrap prepare raw php configs
58
            $bootstrap->prepare->php($config->path('app'));
59
            
60
            // Register other providers
61
//            foreach ($config->providers as $provider) {
62
//                $di->register(new $provider($di));
63
//            }
64
            
65
            // Set the config
66
            return $config;
67
        });
68
    }
69
}
70