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

Page::make()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 3
dl 0
loc 7
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Stitcher\Page;
4
5
use Pageon\Html\Meta\Meta;
6
7
class Page
8
{
9
    private $id;
10
    private $template;
11
    private $variables;
12
    private $meta;
13
14 4
    public function __construct(
15
        string $id,
16
        string $template,
17
        array $variables = []
18
    ) {
19 4
        $this->id = $id;
20 4
        $this->template = $template;
21 4
        $this->variables = $variables;
22 4
        $this->setMeta();
23 4
    }
24
25 4
    public static function make(
26
        string $id,
27
        string $template,
28
        array $variables = []
29
    ): Page {
30 4
        return new self($id, $template, $variables);
31
    }
32
33
    public function id(): string
34
    {
35
        return $this->id;
36
    }
37
38
    public function template(): string
39
    {
40
        return $this->template;
41
    }
42
43
    public function variables(): array
44
    {
45
        return $this->variables;
46
    }
47
48
    public function variable(string $name)
49
    {
50
        return $this->variables[$name] ?? null;
51
    }
52
53 2
    public function meta(): Meta
54
    {
55 2
        return $this->meta;
56
    }
57
58 4
    private function setMeta(): void
59
    {
60 4
        $this->meta = Meta::create()
61 4
            ->title(
62 4
                $this->variables['meta']['title']
63 3
                ?? $this->variables['title']
64 4
                ?? null
65
            )
66 4
            ->description(
67 4
                $this->variables['meta']['description']
68 3
                ?? $this->variables['description']
69 4
                ?? null
70
            )
71 4
            ->link('next',
72 4
                $this->variables['_pagination']['next']['url']
73 4
                ?? null
74
            )
75 4
            ->link('prev',
76 4
                $this->variables['_pagination']['previous']['url']
77 4
                ?? null
78
            );
79 4
    }
80
}
81