Completed
Push — master ( 46a5ae...471255 )
by Dmitry
03:58 queued 37s
created

TarantoolProvider::register()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 57
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 28
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 57
ccs 28
cts 28
cp 1
rs 9.6818
c 0
b 0
f 0
cc 3
eloc 31
nc 1
nop 0
crap 3

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\Providers;
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\Plugins\Annotation;
17
use Tarantool\Mapper\Plugins\Sequence;
18
use Tarantool\Mapper\Plugins\Spy;
19
use Tarantool\Mapper\Schema;
20
21
22
class TarantoolProvider extends AbstractServiceProvider
23
{
24
    protected $provides = [
25
        Bootsrap::class,
26
        Client::class,
27
        Connection::class,
28
        Mapper::class,
29
        Packer::class,
30
        Schema::class,
31
        Spy::class,
32
        StreamConnection::class,
33
        TarantoolClient::class,
34
    ];
35
36 1
    public function register()
37
    {
38
        $this->container->share(Bootsrap::class, function() {
39
            return $this->container->get(Mapper::class)->getBootstrap();
40 1
        });
41
42
        $this->getContainer()->share(Client::class, function () {
43 1
            return new Client(
44 1
                $this->getContainer()->get(Connection::class),
45 1
                $this->getContainer()->get(Packer::class)
46
            );
47 1
        });
48
49
        $this->getContainer()->share(Connection::class, function () {
50 1
            return $this->getContainer()->get(StreamConnection::class);
51 1
        });
52
53
        $this->getContainer()->share(Mapper::class, function () {
54 1
            $mapper = new Mapper($this->getContainer()->get(Client::class));
55
56 1
            $annotation = $mapper->addPlugin(Annotation::class);
57
58 1
            $filesystem = $this->getContainer()->get(Filesystem::class);
59 1
            foreach($filesystem->listClasses('Entities') as $class) {
60 1
                $annotation->register($class);
61
            }
62 1
            foreach($filesystem->listClasses('Repositories') as $class) {
63
                $annotation->register($class);
64
            }
65
66 1
            $mapper->addPlugin(Sequence::class);
67 1
            $mapper->addPlugin(Spy::class);
68 1
            return $mapper;
69 1
        });
70
71
        $this->getContainer()->share(Spy::class, function () {
72
            return $this->getContainer()->get(Mapper::class)->getPlugin(Spy::class);
73 1
        });
74
75
        $this->getContainer()->share(Packer::class, function () {
76 1
            return new PurePacker();
77 1
        });
78
79
        $this->getContainer()->share(Schema::class, function () {
80
            return $this->getContainer()->get(Mapper::class)->getSchema();
81 1
        });
82
83
        $this->getContainer()->share(StreamConnection::class, function () {
84 1
            $config = $this->getContainer()->get(Config::class);
85 1
            return new StreamConnection($config['tarantool']);
86 1
        });
87
88 1
        $this->getContainer()->share(TarantoolClient::class, function() {
89
            return $this->getContainer()->get(Client::class);
90 1
        });
91
92 1
    }
93
}
94