Passed
Push — 6.4 ( be76f2...e19c4d )
by Christian
14:08 queued 13s
created

AdminElasticsearchHelper::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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