Code

< 40 %
40-60 %
> 60 %
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 10
    public function __construct(TargetSorter $sorter, PageRepositoryInterface $pageRepository)
23
    {
24 10
        $this->pageRepository = $pageRepository;
25 10
        $this->sorter         = $sorter;
26 10
    }
27
28
    /** {@inheritdoc} */
29 9
    public function match(DestinationInterface $destination)
30
    {
31 9
        $target = $this->sorter->getMatchingTarget($destination);
32
33
        try {
34 4
            return $this->pageRepository->getByTargetDestination($target, $destination);
35 1
        } catch (PageException $exception) {
36 2
            throw new MatchingException($exception->getMessage(), $exception->getCode(), $exception);
37
        }
38
    }
39
}
40