Passed
Push — feature/initial-implementation ( 88960a...869acf )
by Fike
02:03
created

DefaultClientFactory::setLogger()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace AmaTeam\ElasticSearch\API;
4
5
use Elasticsearch\Client;
6
use Elasticsearch\ClientBuilder;
7
use Psr\Log\LoggerInterface;
8
use Psr\Log\NullLogger;
9
10
class DefaultClientFactory implements ClientFactoryInterface
11
{
12
    /**
13
     * @var string[]
14
     */
15
    private $hosts;
16
    /**
17
     * @var LoggerInterface
18
     */
19
    private $logger;
20
21
    /**
22
     * @param string[] $hosts
23
     */
24
    public function __construct($hosts = ['localhost:9200'])
25
    {
26
        $this->hosts = $hosts;
27
        $this->logger = new NullLogger();
28
    }
29
30
    public function getClient(): Client
31
    {
32
        return ClientBuilder::create()->setHosts($this->hosts)->build();
33
    }
34
35
    /**
36
     * @param string[] $hosts
37
     * @return DefaultClientFactory
38
     */
39
    public function setHosts(string ...$hosts): DefaultClientFactory
40
    {
41
        $this->hosts = $hosts;
42
        return $this;
43
    }
44
45
    /**
46
     * @param LoggerInterface $logger
47
     * @return DefaultClientFactory
48
     */
49
    public function setLogger(LoggerInterface $logger): DefaultClientFactory
50
    {
51
        $this->logger = $logger;
52
        return $this;
53
    }
54
}
55