Completed
Push — master ( 823d1d...222144 )
by Michal
06:22
created

DefaultRenderer::initPreprocessors()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 20
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 20
cts 20
cp 1
rs 9.584
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace SeoHelper\Renderer;
4
5
class DefaultRenderer extends AbstractRenderer
6
{
7
    protected $types = [
8
        'default' => '<meta name="{$key}" content="{$value}">',
9
        'title' => '<title>{$value}</title>',
10
        'canonical' => '<link rel="canonical" href="{$value}">',
11
        'next' => '<link rel="next" href="{$value}">',
12
        'prev' => '<link rel="prev" href="{$value}">',
13
    ];
14
15 27
    protected function getPattern($type)
16
    {
17 27
        return parent::getPattern($type) ?: $this->types['default'];
18
    }
19
20 9
    protected function initPreprocessors()
21
    {
22 18
        $this->setPreprocessor('title', function ($value) {
23 9
            return strip_tags(implode(' | ', array_reverse($value)));
24 27
        });
25 18
        $this->setPreprocessor('description', function ($value) {
26 9
            return htmlspecialchars(strip_tags(implode(' ', $value)));
27 27
        });
28 18
        $this->setPreprocessor('keywords', function ($value) {
29 3
            return htmlspecialchars(strip_tags(implode(', ', array_unique($value))));
30 27
        });
31 18
        $this->setPreprocessor('canonical', function ($value) {
32 3
            return htmlspecialchars(strip_tags(implode($value)));
33 27
        });
34 18
        $this->setPreprocessor('next', function ($value) {
35 3
            return htmlspecialchars(strip_tags(implode($value)));
36 27
        });
37 27
        $this->setPreprocessor('prev', function ($value) {
38 3
            return htmlspecialchars(strip_tags(implode($value)));
39 27
        });
40 9
    }
41
}
42