Completed
Push — master ( 51af85...b489fc )
by Pavel
06:35
created

StaticPageRepository::getByTargetDestination()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 2
1
<?php
2
3
namespace Bankiru\Seo\Integration\Local;
4
5
use Bankiru\Seo\DestinationInterface;
6
use Bankiru\Seo\Exception\PageException;
7
use Bankiru\Seo\Page\SeoPageInterface;
8
use Bankiru\Seo\PageRepositoryInterface;
9
use Bankiru\Seo\TargetDefinitionInterface;
10
11
final class StaticPageRepository implements PageRepositoryInterface
12
{
13
    /** @var SeoPageInterface[] */
14
    private $pages = [];
15
16
    public function add(TargetDefinitionInterface $target, SeoPageInterface $page)
17
    {
18
        $this->pages[$target->getRoute()] = $page;
19
    }
20
21
    /** {@inheritdoc} */
22
    public function getByTargetDestination(TargetDefinitionInterface $target, DestinationInterface $destination = null)
23
    {
24
        if (!array_key_exists($target->getRoute(), $this->pages)) {
25
            throw PageException::notFound($target);
26
        }
27
28
        return $this->pages[$target->getRoute()];
29
    }
30
}
31