Completed
Push — master ( 073c6d...49d4ca )
by Dmitry
06:07
created

CoreProvider::register()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 44

Duplication

Lines 7
Ratio 15.91 %

Code Coverage

Tests 9
CRAP Score 1.41

Importance

Changes 0
Metric Value
dl 7
loc 44
ccs 9
cts 35
cp 0.2571
rs 9.216
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1.41
1
<?php
2
3
namespace Basis\Provider;
4
5
use Basis\Application;
6
use Basis\Cache;
7
use Basis\Config;
8
use Basis\Context;
9
use Basis\Converter;
10
use Basis\Dispatcher;
11
use Basis\Filesystem;
12
use Basis\Framework;
13
use Basis\Http;
14
use Basis\Lock;
15
use Basis\Service;
16
use GuzzleHttp\Client as GuzzleHttpClient;
17
use League\Container\ServiceProvider\AbstractServiceProvider;
18
use Predis\Client as PredisClient;
19
20
class CoreProvider extends AbstractServiceProvider
21
{
22
    protected $provides = [
23
        Cache::class,
24
        Config::class,
25
        Converter::class,
26
        Dispatcher::class,
27
        Framework::class,
28
        Http::class,
29
        Lock::class,
30
    ];
31
32
    public function register()
33
    {
34 View Code Duplication
        $this->getContainer()->share(Config::class, function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
35
            $app = $this->getContainer()->get(Application::class);
36
            $framework = $this->getContainer()->get(Framework::class);
37
            $fs = $this->getContainer()->get(Filesystem::class);
38
            $converter = $this->getContainer()->get(Converter::class);
39
            return new Config($app, $framework, $fs, $converter);
40
        });
41
42
        $this->getContainer()->share(Cache::class, function () {
43
            $fs = $this->getContainer()->get(Filesystem::class);
44
            $converter = $this->getContainer()->get(Converter::class);
45
            return new Cache($fs, $converter);
46
        });
47
48
        $this->getContainer()->share(Lock::class, function () {
49
            $redis = $this->getContainer()->get(PredisClient::class);
50
            return new Lock($redis);
51
        });
52
53
        $this->getContainer()->share(Converter::class, function () {
54
            return new Converter();
55
        });
56
57 1
        $this->getContainer()->share(Dispatcher::class, function () {
58 1
            $context = $this->getContainer()->get(Context::class);
59 1
            $client = $this->getContainer()->get(GuzzleHttpClient::class);
60 1
            $service = $this->getContainer()->get(Service::class);
61 1
            return new Dispatcher($client, $context, $service);
62
        });
63
64
        $this->getContainer()->share(Framework::class, function () {
65
            return new Framework($this->getContainer(), dirname(dirname(__DIR__)));
0 ignored issues
show
Compatibility introduced by
$this->getContainer() of type object<League\Container\ContainerInterface> is not a sub-type of object<Basis\Application>. 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...
66
        });
67
68 1
        $this->getContainer()->share(Http::class, function () {
69 1
            return new Http($this->getContainer()->get(Application::class));
70
        });
71
72 1
        $this->getContainer()->share(Context::class, function () {
73 1
            return new Context($this->getContainer()->get(Application::class));
0 ignored issues
show
Unused Code introduced by
The call to Context::__construct() has too many arguments starting with $this->getContainer()->g...sis\Application::class).

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...
74
        });
75
    }
76
}
77