Completed
Push — master ( 772acc...7ea003 )
by Dmitry
11:15
created

ServiceProvider::register()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 20
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3.9379

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 20
ccs 9
cts 17
cp 0.5294
rs 9.4285
cc 3
eloc 15
nc 1
nop 0
crap 3.9379
1
<?php
2
3
namespace Basis\Provider;
4
5
use Basis\Config;
6
use Basis\Dispatcher;
7
use Basis\Event;
8
use Basis\Filesystem;
9
use Basis\Service;
10
use League\Container\ServiceProvider\AbstractServiceProvider;
11
use LinkORB\Component\Etcd\Client;
12
use Tarantool\Mapper\Plugin\Spy;
13
14
class ServiceProvider extends AbstractServiceProvider
15
{
16
    protected $provides = [
17
        Client::class,
18
        Event::class,
19
        Service::class,
20
    ];
21
22
    public function register()
23
    {
24 1
        $this->getContainer()->share(Client::class, function () {
25 1
            $host = getenv('ETCD_SERVICE_HOST') ?: 'etcd';
26 1
            $port = getenv('ETCD_SERVICE_PORT') ?: 2379;
27 1
            return new Client("http://$host:$port");
28 1
        });
29 1
        $this->getContainer()->share(Event::class, function () {
30
            $dispatcher = $this->getContainer()->get(Dispatcher::class);
31
            $service = $this->getContainer()->get(Service::class);
32
            $spy = $this->getContainer()->get(Spy::class);
33
            $filesystem = $this->getContainer()->get(Filesystem::class);
34
            return new Event($dispatcher, $service, $spy, $filesystem);
35 1
        });
36 1
        $this->getContainer()->share(Service::class, function () {
37
            $client = $this->getContainer()->get(Client::class);
38
            $config = $this->getContainer()->get(Config::class);
39
            return new Service($client, $config);
40 1
        });
41
    }
42
}
43