ElasticsearchDependencyProvider   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 68
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A handleDependencies() 0 6 1
A setClient() 0 7 1
A getClient() 0 6 1
A setIndexProvider() 0 9 1
A getIndexProvider() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Xervice\Elasticsearch;
5
6
7
use Elastica\Client;
8
use Xervice\Core\Business\Model\Dependency\Provider\AbstractDependencyProvider;
9
use Xervice\Core\Business\Model\Dependency\DependencyContainerInterface;
10
use Xervice\Elasticsearch\Business\Collection\IndexCollection;
11
12
/**
13
 * @method \Xervice\Core\Locator\Locator getLocator()
14
 * @method \Xervice\Elasticsearch\ElasticsearchConfig getConfig()
15
 */
16
class ElasticsearchDependencyProvider extends AbstractDependencyProvider
17
{
18
    public const CLIENT = 'elasticsearch.client';
19
20
    public const INDEX_PROVIDER = 'elasticsearch.index.provider';
21
22
    /**
23
     * @param \Xervice\Core\Business\Model\Dependency\DependencyContainerInterface $container
24
     *
25
     * @return \Xervice\Core\Business\Model\Dependency\DependencyContainerInterface
26
     */
27 1
    public function handleDependencies(DependencyContainerInterface $container): DependencyContainerInterface
28
    {
29 1
        $container = $this->setClient($container);
30 1
        $container = $this->setIndexProvider($container);
31
32 1
        return $container;
33
    }
34
35
    /**
36
     * @param \Xervice\Core\Business\Model\Dependency\DependencyContainerInterface $container
37
     *
38
     * @return \Xervice\Core\Business\Model\Dependency\DependencyContainerInterface
39
     */
40 1
    protected function setClient(DependencyContainerInterface $container): DependencyContainerInterface
41
    {
42
        $container[self::CLIENT] = function (DependencyContainerInterface $container) {
0 ignored issues
show
Unused Code introduced by
The parameter $container is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

42
        $container[self::CLIENT] = function (/** @scrutinizer ignore-unused */ DependencyContainerInterface $container) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
43 1
            return $this->getClient();
44
        };
45
46 1
        return $container;
47
    }
48
49
    /**
50
     * @param \Xervice\Core\Business\Model\Dependency\DependencyContainerInterface $container
51
     *
52
     * @return \Xervice\Core\Business\Model\Dependency\DependencyContainerInterface
53
     */
54 1
    protected function setIndexProvider(DependencyContainerInterface $container): DependencyContainerInterface
55
    {
56
        $container[self::INDEX_PROVIDER] = function (DependencyContainerInterface $container) {
0 ignored issues
show
Unused Code introduced by
The parameter $container is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

56
        $container[self::INDEX_PROVIDER] = function (/** @scrutinizer ignore-unused */ DependencyContainerInterface $container) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
57 1
            return new IndexCollection(
58 1
                $this->getIndexProvider()
59
            );
60
        };
61
62 1
        return $container;
63
    }
64
65
    /**
66
     * @return \Elastica\Client
67
     */
68 1
    protected function getClient()
69
    {
70 1
        return new Client(
71
            [
72 1
                'host' => $this->getConfig()->getHost(),
73 1
                'port' => $this->getConfig()->getPort()
74
            ]
75
        );
76
    }
77
78
    /**
79
     * @return \Xervice\Elasticsearch\Dependency\Plugin\IndexProviderInterface[]
80
     */
81 1
    protected function getIndexProvider(): array
82
    {
83 1
        return [];
84
    }
85
}
86