BaseCatalogTrait::withRepository()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 6
c 0
b 0
f 0
nc 3
nop 1
dl 0
loc 13
ccs 8
cts 8
cp 1
crap 3
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