Passed
Push — trunk ( a4e569...0674cc )
by Christian
14:29 queued 12s
created

ElasticsearchRegistry   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 54
rs 10
c 0
b 0
f 0
wmc 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A getDefinitions() 0 3 1
A has() 0 9 3
A get() 0 9 3
A getDefinitionNames() 0 9 2
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Elasticsearch\Framework;
4
5
use Shopware\Core\Framework\Log\Package;
6
7
#[Package('core')]
8
class ElasticsearchRegistry
9
{
10
    /**
11
     * @internal
12
     *
13
     * @param AbstractElasticsearchDefinition[] $definitions
14
     */
15
    public function __construct(private readonly iterable $definitions)
16
    {
17
    }
18
19
    /**
20
     * @return AbstractElasticsearchDefinition[]
21
     */
22
    public function getDefinitions(): iterable
23
    {
24
        return $this->definitions;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->definitions returns the type iterable which is incompatible with the documented return type Shopware\Elasticsearch\F...asticsearchDefinition[].
Loading history...
25
    }
26
27
    /**
28
     * @return iterable<string>
29
     */
30
    public function getDefinitionNames(): iterable
31
    {
32
        $names = [];
33
34
        foreach ($this->getDefinitions() as $definition) {
35
            $names[] = $definition->getEntityDefinition()->getEntityName();
36
        }
37
38
        return $names;
39
    }
40
41
    public function get(string $entityName): ?AbstractElasticsearchDefinition
42
    {
43
        foreach ($this->getDefinitions() as $definition) {
44
            if ($definition->getEntityDefinition()->getEntityName() === $entityName) {
45
                return $definition;
46
            }
47
        }
48
49
        return null;
50
    }
51
52
    public function has(string $entityName): bool
53
    {
54
        foreach ($this->getDefinitions() as $definition) {
55
            if ($definition->getEntityDefinition()->getEntityName() === $entityName) {
56
                return true;
57
            }
58
        }
59
60
        return false;
61
    }
62
}
63