Completed
Push — master ( 8b8c0c...ed931d )
by Pavel
02:40
created

DestinationMatcher   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 31
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A match() 0 10 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 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