Test Failed
Push — master ( 62e8aa...e74fb5 )
by Julien
04:23
created

ServiceProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 25 3
1
<?php
2
3
/**
4
 * This file is part of the Zemit Framework.
5
 *
6
 * (c) Zemit Team <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE.txt
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Zemit\Provider\Config;
13
14
use Phalcon\Di\DiInterface;
15
use Zemit\Bootstrap;
16
use Zemit\Bootstrap\Config;
17
use Zemit\Provider\AbstractServiceProvider;
18
19
class ServiceProvider extends AbstractServiceProvider
20
{
21
    protected string $serviceName = 'config';
22
    
23
    public function register(DiInterface $di = null): void
24
    {
25
        // Set shared service in DI
26
        $di->setShared($this->getName(), function () use ($di) {
27
            
28
            $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

28
            /** @scrutinizer ignore-call */ 
29
            $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...
29
            assert($bootstrap instanceof Bootstrap);
30
            
31
            $config = $bootstrap->config ?? new Config();
32
            
33
            if (is_string($config) && class_exists($config)) {
0 ignored issues
show
introduced by
The condition is_string($config) is always false.
Loading history...
34
                $config = new $config();
35
            }
36
            
37
            // Set bootstrap mode into config
38
            $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...
Bug Best Practice introduced by
The property mode does not exist on Zemit\Config\ConfigInterface. Since you implemented __set, consider adding a @property annotation.
Loading history...
39
            
40
            // Merge config with current environment
41
            $config->mergeEnvConfig();
0 ignored issues
show
Bug introduced by
The method mergeEnvConfig() does not exist on Zemit\Config\ConfigInterface. It seems like you code against a sub-type of Zemit\Config\ConfigInterface such as Zemit\Bootstrap\Config. ( Ignorable by Annotation )

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

41
            $config->/** @scrutinizer ignore-call */ 
42
                     mergeEnvConfig();
Loading history...
42
            
43
            // Launch bootstrap prepare raw php configs
44
            $bootstrap->prepare->php($config->pathToArray('app') ?? []);
0 ignored issues
show
Bug introduced by
The property prepare does not seem to exist on Zemit\Bootstrap.
Loading history...
45
            
46
            // Set the config
47
            return $config;
48
        });
49
    }
50
}
51