Completed
Push — master ( 95b8e4...b19727 )
by Dmitry
06:52
created

CoreProvider   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 46
Duplicated Lines 15.22 %

Coupling/Cohesion

Components 0
Dependencies 8

Test Coverage

Coverage 22.22%

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 8
dl 7
loc 46
ccs 6
cts 27
cp 0.2222
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B register() 7 34 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Basis\Provider;
4
5
use Basis\Application;
6
use Basis\Cache;
7
use Basis\Config;
8
use Basis\Converter;
9
use Basis\Dispatcher;
10
use Basis\Filesystem;
11
use Basis\Framework;
12
use Basis\Service;
13
use Basis\Http;
14
use GuzzleHttp\Client;
15
use League\Container\ServiceProvider\AbstractServiceProvider;
16
17
class CoreProvider extends AbstractServiceProvider
18
{
19
    protected $provides = [
20
        Cache::class,
21
        Config::class,
22
        Converter::class,
23
        Dispatcher::class,
24
        Framework::class,
25
        Http::class,
26
    ];
27
28
    public function register()
29
    {
30 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...
31
            $app = $this->getContainer()->get(Application::class);
32
            $framework = $this->getContainer()->get(Framework::class);
33
            $fs = $this->getContainer()->get(Filesystem::class);
34
            $converter = $this->getContainer()->get(Converter::class);
35
            return new Config($app, $framework, $fs, $converter);
36
        });
37
38
        $this->getContainer()->share(Cache::class, function () {
39
            $fs = $this->getContainer()->get(Filesystem::class);
40
            $converter = $this->getContainer()->get(Converter::class);
41
            return new Cache($fs, $converter);
42
        });
43
44
        $this->getContainer()->share(Converter::class, function () {
45
            return new Converter();
46
        });
47
48 1
        $this->getContainer()->share(Dispatcher::class, function () {
49 1
            $client = $this->getContainer()->get(Client::class);
50 1
            $service = $this->getContainer()->get(Service::class);
51 1
            return new Dispatcher($client, $service);
52
        });
53
54
        $this->getContainer()->share(Framework::class, function () {
55
            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...
56
        });
57
58 1
        $this->getContainer()->share(Http::class, function () {
59 1
            return new Http($this->getContainer()->get(Application::class));
60
        });
61
    }
62
}
63