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

ElasticsearchRegistry::getDefinitionNames()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 9
rs 10
c 0
b 0
f 0
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