Passed
Push — 6.5.0.0 ( 14f5ba...89c3a0 )
by Christian
17:46 queued 04:24
created

DefinitionRegistryChain::has()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 1
nc 2
nop 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Core\System\SalesChannel\Entity;
4
5
use Shopware\Core\Framework\DataAbstractionLayer\DefinitionInstanceRegistry;
6
use Shopware\Core\Framework\DataAbstractionLayer\EntityDefinition;
7
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
8
use Shopware\Core\Framework\DataAbstractionLayer\Exception\DefinitionNotFoundException;
9
use Shopware\Core\Framework\DataAbstractionLayer\Exception\EntityRepositoryNotFoundException;
10
use Shopware\Core\Framework\Log\Package;
11
12
/**
13
 * @internal
14
 */
15
#[Package('core')]
16
class DefinitionRegistryChain
17
{
18
    public function __construct(
19
        private readonly DefinitionInstanceRegistry $core,
20
        private readonly SalesChannelDefinitionInstanceRegistry $salesChannel
21
    ) {
22
    }
23
24
    public function get(string $class): EntityDefinition
25
    {
26
        if ($this->salesChannel->has($class)) {
27
            return $this->salesChannel->get($class);
28
        }
29
30
        return $this->core->get($class);
31
    }
32
33
    public function getRepository(string $entity): EntityRepository
34
    {
35
        try {
36
            return $this->salesChannel->getRepository($entity);
37
        } catch (EntityRepositoryNotFoundException) {
38
            return $this->core->getRepository($entity);
39
        }
40
    }
41
42
    public function getByEntityName(string $type): EntityDefinition
43
    {
44
        try {
45
            return $this->salesChannel->getByEntityName($type);
46
        } catch (DefinitionNotFoundException) {
47
            return $this->core->getByEntityName($type);
48
        }
49
    }
50
51
    public function has(string $type): bool
52
    {
53
        return $this->salesChannel->has($type) || $this->core->has($type);
54
    }
55
}
56