Passed
Push — trunk ( 544851...4bb49d )
by Christian
10:04 queued 12s
created

AdminElasticsearchHelper::getEnabled()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Elasticsearch\Admin;
4
5
/**
6
 * @package system-settings
7
 *
8
 * @internal
9
 *
10
 * @final
11
 */
12
class AdminElasticsearchHelper
13
{
14
    private bool $adminEsEnabled;
15
16
    private bool $refreshIndices;
17
18
    private string $adminIndexPrefix;
19
20
    public function __construct(bool $adminEsEnabled, bool $refreshIndices, string $adminIndexPrefix)
21
    {
22
        $this->adminEsEnabled = $adminEsEnabled;
23
        $this->refreshIndices = $refreshIndices;
24
        $this->adminIndexPrefix = $adminIndexPrefix;
25
    }
26
27
    public function getEnabled(): bool
28
    {
29
        return $this->adminEsEnabled;
30
    }
31
32
    /**
33
     * Only used for unit tests because the container parameter bag is frozen and can not be changed at runtime.
34
     * Therefore this function can be used to test different behaviours
35
     *
36
     * @internal
37
     */
38
    public function setEnabled(bool $enabled): self
39
    {
40
        $this->adminEsEnabled = $enabled;
41
42
        return $this;
43
    }
44
45
    public function getRefreshIndices(): bool
46
    {
47
        return $this->refreshIndices;
48
    }
49
50
    public function getPrefix(): string
51
    {
52
        return $this->adminIndexPrefix;
53
    }
54
55
    public function getIndex(string $name): string
56
    {
57
        return $this->adminIndexPrefix . '-' . \strtolower(\str_replace(['_', ' '], '-', $name));
58
    }
59
}
60