Test Failed
Push — master ( 22b809...326de4 )
by Brent
05:15 queued 39s
created

Page::isCurrent()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 10
ccs 0
cts 5
cp 0
crap 6
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
namespace Stitcher\Renderer\Extension;
4
5
use Stitcher\Page\Page as SitePage;
6
use Stitcher\Page\PageParser;
7
use Stitcher\Renderer\Extension;
8
9
class Page implements Extension
10
{
11
    private $pageParser;
12
13
    public function __construct(PageParser $pageParser)
14
    {
15
        $this->pageParser = $pageParser;
16
    }
17
18
    public function name(): string
19
    {
20
        return '_page';
21
    }
22
23
    public function isActive(string $part): bool
24
    {
25
        return $this->isCurrent($part);
26
    }
27
28
    public function isCurrent(string $part): bool
29
    {
30
        $currentPage = $this->pageParser->getCurrentPage();
31
32
        if (!$currentPage) {
33
            return false;
34
        }
35
36
        return strpos($currentPage->id(), $part) !== false;
37
    }
38
39
    public function current(): ?SitePage
40
    {
41
        return $this->pageParser->getCurrentPage();
42
    }
43
}
44