Completed
Push — master ( 23871e...90b1af )
by Dmitry
11:08 queued 08:52
created

TarantoolProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 91.18%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 6
dl 0
loc 72
ccs 31
cts 34
cp 0.9118
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 57 3
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 3
            $annotation->setRepositoryPostfix('Repository');
57
58 3
            $filesystem = $this->getContainer()->get(Filesystem::class);
59 3
            foreach ($filesystem->listClasses('Entity') as $class) {
60 3
                $annotation->register($class);
61
            }
62 3
            foreach ($filesystem->listClasses('Repository') as $class) {
63 3
                $annotation->register($class);
64
            }
65
66 3
            $mapper->addPlugin(Sequence::class);
67 3
            $mapper->addPlugin(Spy::class);
68 3
            return $mapper;
69 3
        });
70
71
        $this->getContainer()->share(Spy::class, function () {
72 1
            return $this->getContainer()->get(Mapper::class)->getPlugin(Spy::class);
73 3
        });
74
75
        $this->getContainer()->share(Packer::class, function () {
76 3
            return new PurePacker();
77 3
        });
78
79
        $this->getContainer()->share(Schema::class, function () {
80
            return $this->getContainer()->get(Mapper::class)->getSchema();
81 3
        });
82
83
        $this->getContainer()->share(StreamConnection::class, function () {
84 3
            $config = $this->getContainer()->get(Config::class);
85 3
            return new StreamConnection($config['tarantool']);
86 3
        });
87
88 3
        $this->getContainer()->share(TarantoolClient::class, function () {
89
            return $this->getContainer()->get(Client::class);
90 3
        });
91 3
    }
92
}
93