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

DefaultRenderer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 37
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getPattern() 0 4 2
A initPreprocessors() 0 21 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