Passed
Push — develop ( 5df010...37d230 )
by Brent
07:25
created

Page::current()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 2
cp 0
crap 2
rs 10
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 4
    public function __construct(PageParser $pageParser)
14
    {
15 4
        $this->pageParser = $pageParser;
16 4
    }
17
18 4
    public function name(): string
19
    {
20 4
        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