BaseCatalogTrait::repository()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 9
ccs 6
cts 6
cp 1
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpCfdi\SatCatalogos\Common;
6
7
use LogicException;
8
use PhpCfdi\SatCatalogos\Repository;
9
10
trait BaseCatalogTrait
11
{
12
    /**
13
     * @var Repository|null
14
     * @internal
15
     */
16
    private $repository;
17
18 124
    public function withRepository(Repository $repository): void
19
    {
20 124
        if ($repository === $this->repository) {
21 1
            return;
22
        }
23
24 124
        if (null !== $this->repository) {
25 1
            throw new LogicException(
26 1
                sprintf('This instance of %s already contains a repository', get_class($this)),
27 1
            );
28
        }
29
30 124
        $this->repository = $repository;
31
    }
32
33 119
    public function repository(): Repository
34
    {
35 119
        if (null === $this->repository) {
36 1
            throw new LogicException(
37 1
                sprintf('This instance of %s does not contains a repository', get_class($this)),
38 1
            );
39
        }
40
41 118
        return $this->repository;
42
    }
43
}
44