ConfigurationServiceProvider   B
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 16

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 1
lcom 1
cbo 16
dl 0
loc 57
ccs 27
cts 27
cp 1
rs 8.4614
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B register() 0 38 1
1
<?php
2
3
/*
4
 * This file is part of Rocketeer
5
 *
6
 * (c) Maxime Fabre <[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
13
namespace Rocketeer\Services\Config;
14
15
use League\Container\ServiceProvider\AbstractServiceProvider;
16
use Rocketeer\Services\Config\Files\ConfigurationCache;
17
use Rocketeer\Services\Config\Files\ConfigurationPublisher;
18
use Rocketeer\Services\Config\Files\Loaders\CachedConfigurationLoader;
19
use Rocketeer\Services\Config\Files\Loaders\ConfigurationLoader;
20
use Rocketeer\Services\Config\Files\Loaders\ConfigurationLoaderInterface;
21
use Rocketeer\Services\Config\Loaders\JsonLoader;
22
use Rocketeer\Services\Config\Loaders\PhpLoader;
23
use Rocketeer\Services\Config\Loaders\YamlLoader;
24
use Rocketeer\Traits\HasLocatorTrait;
25
use Symfony\Component\Config\FileLocator;
26
use Symfony\Component\Config\Loader\DelegatingLoader;
27
use Symfony\Component\Config\Loader\LoaderInterface;
28
use Symfony\Component\Config\Loader\LoaderResolver;
29
30
class ConfigurationServiceProvider extends AbstractServiceProvider
31
{
32
    use HasLocatorTrait;
33
34
    /**
35
     * @var array
36
     */
37
    protected $provides = [
38
        ConfigurationCache::class,
39
        ConfigurationLoaderInterface::class,
40
        ConfigurationPublisher::class,
41
        ContextualConfiguration::class,
42
        LoaderInterface::class,
43
    ];
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 442
    public function register()
49
    {
50
        $this->container->add(LoaderInterface::class, function () {
51 442
            $locator = new FileLocator();
52 442
            $resolver = new LoaderResolver([
53 442
                new PhpLoader($locator),
0 ignored issues
show
Unused Code introduced by Maxime Fabre
The call to PhpLoader::__construct() has too many arguments starting with $locator.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
54 442
                new JsonLoader($locator),
0 ignored issues
show
Unused Code introduced by Maxime Fabre
The call to JsonLoader::__construct() has too many arguments starting with $locator.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
55 442
                new YamlLoader($locator),
0 ignored issues
show
Unused Code introduced by Maxime Fabre
The call to YamlLoader::__construct() has too many arguments starting with $locator.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
56 442
            ]);
57
58 442
            $loader = new DelegatingLoader($resolver);
59
60 442
            return $loader;
61 442
        });
62
63
        $this->container->share(ConfigurationCache::class, function () {
64 442
            return new ConfigurationCache($this->paths->getConfigurationCachePath(), true);
0 ignored issues
show
Documentation Bug introduced by Maxime FABRE
The method getConfigurationCachePath does not exist on object<Rocketeer\Services\Environment\Pathfinder>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
65 442
        });
66
67
        $this->container->share(ConfigurationLoaderInterface::class, function () {
68 442
            $cache = $this->container->get(ConfigurationCache::class);
69 442
            $loader = $this->container->get(ConfigurationLoader::class);
70 442
            $loader->setFolders([
71 442
                realpath(__DIR__.'/../../../config'),
72 442
                $this->paths->getConfigurationPath(),
73 442
            ]);
74
75 442
            return new CachedConfigurationLoader($cache, $loader);
76 442
        });
77
78 442
        $this->container->share(ConfigurationPublisher::class)->withArgument($this->container);
79 442
        $this->container->share(ContextualConfiguration::class, function () {
80 442
            $configuration = $this->configurationLoader->getConfiguration();
81 442
            $configuration = new Configuration($configuration);
82
83 442
            return new ContextualConfiguration($this->container, $configuration);
0 ignored issues
show
Compatibility introduced by Maxime Fabre
$this->container of type object<League\Container\ContainerInterface> is not a sub-type of object<Rocketeer\Services\Container\Container>. It seems like you assume a concrete implementation of the interface League\Container\ContainerInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
84 442
        });
85 442
    }
86
}
87