Passed
Push — master ( 896e22...61bd56 )
by Dāvis
03:36
created

SpacelessFormatter   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 58
rs 10
c 0
b 0
f 0
wmc 11

8 Methods

Rating   Name   Duplication   Size   Complexity  
A formatSitemapIndex() 0 7 2
A getSitemapIndexStart() 0 7 2
A getSitemapStart() 0 3 1
A formatUrl() 0 3 1
A getSitemapIndexEnd() 0 7 2
A getSitemapEnd() 0 3 1
A __construct() 0 3 1
A stripSpaces() 0 7 1
1
<?php
2
3
namespace Sludio\HelperBundle\Sitemap\Formatter;
4
5
use Sludio\HelperBundle\Sitemap\Entity\Url;
6
use Sludio\HelperBundle\Sitemap\Entity\SitemapIndex;
7
8
class SpacelessFormatter implements SitemapIndexFormatterInterface
9
{
10
    protected $formatter;
11
12
    public function __construct(FormatterInterface $formatter)
13
    {
14
        $this->formatter = $formatter;
15
    }
16
17
    public function getSitemapStart()
18
    {
19
        return $this->stripSpaces($this->formatter->getSitemapStart());
20
    }
21
22
    public function getSitemapEnd()
23
    {
24
        return $this->stripSpaces($this->formatter->getSitemapEnd());
25
    }
26
27
    public function formatUrl(Url $url)
28
    {
29
        return $this->stripSpaces($this->formatter->formatUrl($url));
30
    }
31
32
    public function getSitemapIndexStart()
33
    {
34
        if (!$this->formatter instanceof SitemapIndexFormatterInterface) {
35
            return '';
36
        }
37
38
        return $this->stripSpaces($this->formatter->getSitemapIndexStart());
39
    }
40
41
    public function getSitemapIndexEnd()
42
    {
43
        if (!$this->formatter instanceof SitemapIndexFormatterInterface) {
44
            return '';
45
        }
46
47
        return $this->stripSpaces($this->formatter->getSitemapIndexEnd());
48
    }
49
50
    public function formatSitemapIndex(SitemapIndex $sitemapIndex)
51
    {
52
        if (!$this->formatter instanceof SitemapIndexFormatterInterface) {
53
            return '';
54
        }
55
56
        return $this->stripSpaces($this->formatter->formatSitemapIndex($sitemapIndex));
57
    }
58
59
    protected function stripSpaces($string)
60
    {
61
        return str_replace([
62
            "\t",
63
            "\r",
64
            "\n",
65
        ], '', $string);
66
    }
67
}