Completed
Push — master ( 6b77c2...0b4fa8 )
by Andrii
04:43
created

RenderedPage   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 2
dl 0
loc 96
ccs 0
cts 48
cp 0
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 6 1
A renderMiniature() 0 12 2
A setMetaData() 0 12 3
A setSlug() 0 4 1
A setKeywords() 0 4 1
A setDescription() 0 4 1
A setFeaturedImageUrl() 0 4 1
A setCanonical() 0 4 1
1
<?php
2
3
namespace hiqdev\yii2\modules\pages\models;
4
5
class RenderedPage extends AbstractPage
6
{
7
    /** @var null|string */
8
    private $featuredImageUrl;
9
10
    /** @var null|string */
11
    private $slug;
12
13
    /** @var null|string */
14
    private $keywords;
15
16
    /** @var null|string */
17
    private $description;
18
19
    /** @var null|string */
20
    private $canonical;
21
22
    const META_DATA = ['keywords', 'description', 'canonical'];
23
24
    public function render(array $params = [])
25
    {
26
        $this->setMetaData();
27
28
        return $this->text;
29
    }
30
31
    /**
32
     * Renders miniature version of page for list
33
     * @return string
34
     */
35
    public function renderMiniature(): string
36
    {
37
        $img = $this->featuredImageUrl ?
38
               "<img src=\"$this->featuredImageUrl\" alt=\"$this->slug\">" :
39
               '';
40
41
        return <<<HTML
42
<h1 class="post-title"><a href="$this->url">$this->title</a></h1>
43
$img
44
$this->text
45
HTML;
46
    }
47
48
    private function setMetaData(): void
49
    {
50
        foreach (self::META_DATA as $tag) {
51
            if (is_null($this->{$tag})) {
52
                continue;
53
            }
54
            $this->view->registerMetaTag([
55
                'name' => $tag,
56
                'content' => $this->{$tag},
57
            ]);
58
        }
59
    }
60
61
    /**
62
     * @param null|string $slug
63
     */
64
    public function setSlug(?string $slug): void
65
    {
66
        $this->slug = $slug;
67
    }
68
69
    /**
70
     * @param null|string $keywords
71
     */
72
    public function setKeywords(?string $keywords): void
73
    {
74
        $this->keywords = $keywords;
75
    }
76
77
    /**
78
     * @param null|string $description
79
     */
80
    public function setDescription(?string $description): void
81
    {
82
        $this->description = $description;
83
    }
84
85
    /**
86
     * @param null|string $featuredImageUrl
87
     */
88
    public function setFeaturedImageUrl(?string $featuredImageUrl): void
89
    {
90
        $this->featuredImageUrl = $featuredImageUrl;
91
    }
92
93
    /**
94
     * @param null|string $canonical
95
     */
96
    public function setCanonical(?string $canonical): void
97
    {
98
        $this->canonical = $canonical;
99
    }
100
}
101