Completed
Push — master ( 8cea3f...bca2c3 )
by Dmitry
03:51
created

TarantoolProvider::register()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 56
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 30
CRAP Score 3.0067

Importance

Changes 0
Metric Value
dl 0
loc 56
ccs 30
cts 33
cp 0.9091
rs 9.7251
c 0
b 0
f 0
cc 3
eloc 31
nc 1
nop 0
crap 3.0067

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Basis\Provider;
4
5
use Basis\Config;
6
use Basis\Filesystem;
7
use League\Container\ServiceProvider\AbstractServiceProvider;
8
use Tarantool\Client\Client as TarantoolClient;
9
use Tarantool\Client\Connection\Connection;
10
use Tarantool\Client\Connection\StreamConnection;
11
use Tarantool\Client\Packer\Packer;
12
use Tarantool\Client\Packer\PurePacker;
13
use Tarantool\Mapper\Bootsrap;
14
use Tarantool\Mapper\Client;
15
use Tarantool\Mapper\Mapper;
16
use Tarantool\Mapper\Plugin\Annotation;
17
use Tarantool\Mapper\Plugin\Sequence;
18
use Tarantool\Mapper\Plugin\Spy;
19
use Tarantool\Mapper\Schema;
20
21
class TarantoolProvider extends AbstractServiceProvider
22
{
23
    protected $provides = [
24
        Bootsrap::class,
25
        Client::class,
26
        Connection::class,
27
        Mapper::class,
28
        Packer::class,
29
        Schema::class,
30
        Spy::class,
31
        StreamConnection::class,
32
        TarantoolClient::class,
33
    ];
34
35 3
    public function register()
36
    {
37
        $this->container->share(Bootsrap::class, function () {
38
            return $this->container->get(Mapper::class)->getBootstrap();
39 3
        });
40
41
        $this->getContainer()->share(Client::class, function () {
42 3
            return new Client(
43 3
                $this->getContainer()->get(Connection::class),
44 3
                $this->getContainer()->get(Packer::class)
45
            );
46 3
        });
47
48
        $this->getContainer()->share(Connection::class, function () {
49 3
            return $this->getContainer()->get(StreamConnection::class);
50 3
        });
51
52
        $this->getContainer()->share(Mapper::class, function () {
53 3
            $mapper = new Mapper($this->getContainer()->get(Client::class));
54
55 3
            $annotation = $mapper->addPlugin(Annotation::class);
56
57 3
            $filesystem = $this->getContainer()->get(Filesystem::class);
58 3
            foreach ($filesystem->listClasses('Entity') as $class) {
59 3
                $annotation->register($class);
60
            }
61 3
            foreach ($filesystem->listClasses('Repository') as $class) {
62 3
                $annotation->register($class);
63
            }
64
65 3
            $mapper->addPlugin(Sequence::class);
66 3
            $mapper->addPlugin(Spy::class);
67 3
            return $mapper;
68 3
        });
69
70
        $this->getContainer()->share(Spy::class, function () {
71 1
            return $this->getContainer()->get(Mapper::class)->getPlugin(Spy::class);
72 3
        });
73
74
        $this->getContainer()->share(Packer::class, function () {
75 3
            return new PurePacker();
76 3
        });
77
78
        $this->getContainer()->share(Schema::class, function () {
79
            return $this->getContainer()->get(Mapper::class)->getSchema();
80 3
        });
81
82
        $this->getContainer()->share(StreamConnection::class, function () {
83 3
            $config = $this->getContainer()->get(Config::class);
84 3
            return new StreamConnection($config['tarantool']);
85 3
        });
86
87 3
        $this->getContainer()->share(TarantoolClient::class, function () {
88
            return $this->getContainer()->get(Client::class);
89 3
        });
90 3
    }
91
}
92