Passed
Push — master ( 7b7e33...6ff579 )
by Tomasz
04:38
created

DomainRepository::getById()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 8
rs 9.4285
c 1
b 0
f 1
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
/**
3
 * Copyright
4
 */
5
namespace Helpers\Repository;
6
7
8
use Hexarchium\CoreDomain\Model\Domain\DomainId;
9
use Hexarchium\CoreDomain\Model\Domain\Entity\Domain;
10
use Hexarchium\CoreDomain\Model\Domain\Exception\DomainNotFoundException;
11
use Hexarchium\CoreDomain\Model\Domain\Repository\DomainRepositoryInterface;
12
13
class DomainRepository extends \ArrayObject implements DomainRepositoryInterface
14
{
15
    public function add(Domain $domain)
16
    {
17
        $this->offsetSet($domain->getId()->getId(), $domain);
18
    }
19
20
    public function getById(DomainId $domainId): Domain
21
    {
22
        if (!$this->offsetExists($domainId->getId())) {
23
            throw new DomainNotFoundException(sprintf("Domain with id '%s' not found", $domainId->getId()));
24
        }
25
26
        return $this->offsetGet($domainId->getId());
27
    }
28
}