Completed
Push — master ( 246fd0...e32f5d )
by Dmitry
03:42
created

TarantoolProvider::register()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 80
Code Lines 44

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 49
CRAP Score 1.0007

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 80
ccs 49
cts 54
cp 0.9074
rs 8.8387
cc 1
eloc 44
nc 1
nop 0
crap 1.0007

1 Method

Rating   Name   Duplication   Size   Complexity  
A TarantoolProvider.php$0 ➔ afterInstantiate() 0 4 1

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\Bootstrap;
14
use Tarantool\Mapper\Client;
15
use Tarantool\Mapper\Entity;
16
use Tarantool\Mapper\Mapper;
17
use Tarantool\Mapper\Plugin;
18
use Tarantool\Mapper\Plugin\Annotation;
19
use Tarantool\Mapper\Plugin\Sequence;
20
use Tarantool\Mapper\Plugin\Spy;
21
use Tarantool\Mapper\Plugin\Temporal;
22
use Tarantool\Mapper\Schema;
23
24
class TarantoolProvider extends AbstractServiceProvider
25
{
26
    protected $provides = [
27
        Bootstrap::class,
28
        Client::class,
29
        Connection::class,
30
        Mapper::class,
31
        Packer::class,
32
        Pool::class,
33
        Schema::class,
34
        Spy::class,
35
        StreamConnection::class,
36
        TarantoolClient::class,
37
        Temporal::class,
38
    ];
39
40
    public function register()
41
    {
42 38
        $this->container->share(Bootstrap::class, function () {
43 38
            return $this->container->get(Mapper::class)->getBootstrap();
44 38
        });
45
46 38
        $this->getContainer()->share(Client::class, function () {
47 38
            return new Client(
48 38
                $this->getContainer()->get(Connection::class),
49 38
                $this->getContainer()->get(Packer::class)
50
            );
51 38
        });
52
53 38
        $this->getContainer()->share(Connection::class, function () {
54 38
            return $this->getContainer()->get(StreamConnection::class);
55 38
        });
56
57 38
        $this->getContainer()->share(Mapper::class, function () {
58 38
            $mapper = new Mapper($this->getContainer()->get(Client::class));
59 38
            $filesystem = $this->getContainer()->get(Filesystem::class);
60
61 38
            $mapperCache = $filesystem->getPath('.cache/mapper-meta.php');
62 38
            if (file_exists($mapperCache)) {
63
                $meta = include $mapperCache;
64
                $mapper->setMeta($meta);
65
            }
66
67 38
            $annotation = $mapper->getPlugin(Annotation::class);
68
69 38
            foreach ($filesystem->listClasses('Entity') as $class) {
70 38
                $annotation->register($class);
71
            }
72 38
            foreach ($filesystem->listClasses('Repository') as $class) {
73 38
                $annotation->register($class);
74
            }
75
76 38
            $mapper->getPlugin(Sequence::class);
77 38
            $mapper->getPlugin(Spy::class);
78
79 38
            $mapper->getPlugin(Temporal::class)
80 38
                ->getAggregator()
81 38
                ->setReferenceAggregation(false);
82
83 38
            $mapper->application = $this->getContainer();
0 ignored issues
show
Bug introduced by
The property application does not seem to exist in Tarantool\Mapper\Mapper.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
84
85
            $mapper->getPlugin(new class($mapper) extends Plugin {
86 38
                public function afterInstantiate(Entity $entity)
87
                {
88 38
                    $entity->app = $this->mapper->application;
0 ignored issues
show
Bug introduced by
The property app does not seem to exist in Tarantool\Mapper\Entity.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
Bug introduced by
The property application does not seem to exist in Tarantool\Mapper\Mapper.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
89 38
                }
90
            });
91
92 38
            return $mapper;
93 38
        });
94
95 38
        $this->getContainer()->share(Packer::class, function () {
96 38
            return new PurePacker();
97 38
        });
98
99 38
        $this->getContainer()->share(Schema::class, function () {
100
            return $this->getContainer()->get(Mapper::class)->getSchema();
101 38
        });
102
103 38
        $this->getContainer()->share(Spy::class, function () {
104
            return $this->getContainer()->get(Mapper::class)->getPlugin(Spy::class);
105 38
        });
106
107 38
        $this->getContainer()->share(StreamConnection::class, function () {
108 38
            $config = $this->getContainer()->get(Config::class);
109 38
            return new StreamConnection($config['tarantool.connection'], $config['tarantool.params']);
110 38
        });
111
112 38
        $this->getContainer()->share(TarantoolClient::class, function () {
113 30
            return $this->getContainer()->get(Client::class);
114 38
        });
115
116 38
        $this->getContainer()->share(Temporal::class, function () {
117
            return $this->getContainer()->get(Mapper::class)->getPlugin(Temporal::class);
118 38
        });
119 38
    }
120
}
121