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

DestinationMatcher::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace Bankiru\Seo;
4
5
use Bankiru\Seo\Exception\MatchingException;
6
use Bankiru\Seo\Exception\PageException;
7
use Bankiru\Seo\Target\TargetSorter;
8
9
final class DestinationMatcher implements DestinationMatcherInterface
10
{
11
    /** @var PageRepositoryInterface */
12
    private $pageRepository;
13
    /** @var TargetSorter */
14
    private $sorter;
15
16
    /**
17
     * DestinationMatcher constructor.
18
     *
19
     * @param TargetSorter            $sorter
20
     * @param PageRepositoryInterface $pageRepository
21
     */
22
    public function __construct(TargetSorter $sorter, PageRepositoryInterface $pageRepository)
23
    {
24
        $this->pageRepository = $pageRepository;
25
        $this->sorter         = $sorter;
26
    }
27
28
    /** {@inheritdoc} */
29
    public function match(DestinationInterface $destination)
30
    {
31
        $target = $this->sorter->getMatchingTarget($destination);
32
33
        try {
34
            return $this->pageRepository->getByTargetDestination($target, $destination);
35
        } catch (PageException $exception) {
36
            throw new MatchingException($exception->getMessage(), $exception->getCode(), $exception);
37
        }
38
    }
39
}
40