Completed
Push — master ( 95b8e4...b19727 )
by Dmitry
06:52
created

ClickhouseProvider::register()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 1

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 17
ccs 12
cts 12
cp 1
rs 9.4285
cc 1
eloc 10
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Basis\Provider;
4
5
use Basis\Clickhouse;
6
use Basis\Config;
7
use Basis\Service;
8
use ClickHouseDB\Client;
9
use League\Container\ServiceProvider\AbstractServiceProvider;
10
11
class ClickhouseProvider extends AbstractServiceProvider
12
{
13
    protected $provides = [
14
        Client::class,
15
    ];
16
17
    public function register()
18
    {
19 3
        $this->getContainer()->share(Clickhouse::class, function () {
20 2
            return new Clickhouse($this->getContainer());
0 ignored issues
show
Compatibility introduced by
$this->getContainer() of type object<League\Container\ContainerInterface> is not a sub-type of object<Basis\Application>. It seems like you assume a concrete implementation of the interface League\Container\ContainerInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
21 3
        });
22
23 3
        $this->getContainer()->share(Client::class, function () {
24 3
            $serviceName = $this->getContainer()->get(Service::class)->getName();
25 3
            $config = $this->getContainer()->get(Config::class)['clickhouse'];
26
27 3
            $clickhouse = new Client($config);
28 3
            $clickhouse->write('create database if not exists '.$serviceName);
29 3
            $clickhouse->database($serviceName);
30
31 3
            return $clickhouse;
32 3
        });
33 3
    }
34
}
35