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

DomainRepository::add()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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