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

Page   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 77.14%

Importance

Changes 0
Metric Value
dl 0
loc 74
ccs 27
cts 35
cp 0.7714
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 1

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A make() 0 7 1
A meta() 0 4 1
A setMeta() 0 22 1
A id() 0 4 1
A template() 0 4 1
A variables() 0 4 1
A variable() 0 4 1
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