ElasticaServiceProvider::getServices()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.4285
cc 1
eloc 6
nc 1
nop 0
crap 1
1
<?php
2
3
namespace GBProd;
4
5
use Elastica\Client;
6
use Interop\Container\ContainerInterface;
7
use Interop\Container\ServiceProvider;
8
9
/**
10
 * Service provider for Elastica
11
 *
12
 * @author GBProd <[email protected]>
13
 */
14
class ElasticaServiceProvider implements ServiceProvider
15
{
16
    /**
17
     * @var string|null
18
     */
19
    private $suffix;
20
21
    /**
22
     * @param string|null $suffix
23
     */
24 2
    public function __construct($suffix = null)
25
    {
26 2
        $this->suffix = $suffix ? '.'.$suffix : '';
27 2
    }
28
29
    /**
30
     * {inheritdoc}
31
     */
32
    public function getServices()
33
    {
34
        return [
35 2
            Client::class.$this->suffix => function(ContainerInterface $container) {
36 2
                return new Client([
37 2
                    'host' => $container->get(Client::class.$this->suffix.'.host'),
38 2
                    'port' => $container->get(Client::class.$this->suffix.'.port')
39 2
                ]);
40
            }
41 2
        ];
42
    }
43
}
44