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

RichXmlFormatter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A formatBody() 0 11 3
A getSitemapStart() 0 3 1
1
<?php
2
3
namespace Sludio\HelperBundle\Sitemap\Formatter;
4
5
use Sludio\HelperBundle\Sitemap\Entity\RichUrl;
6
use Sludio\HelperBundle\Sitemap\Entity\Url;
7
8
class RichXmlFormatter extends XmlFormatter
9
{
10
    public function getSitemapStart()
11
    {
12
        return '<?xml version="1.0" encoding="UTF-8"?>'."\n".'<urlset '.'xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" '.'xmlns:xhtml="http://www.w3.org/1999/xhtml" '.'xmlns:video="http://www.google.com/schemas/sitemap-video/1.1" '.'xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">'."\n";
13
    }
14
15
    protected function formatBody(Url $url)
16
    {
17
        $buffer = parent::formatBody($url);
18
19
        if ($url instanceof RichUrl) {
20
            foreach ($url->getAlternateUrls() as $locale => $link) {
21
                $buffer .= "\t".'<xhtml:link rel="alternate" hreflang="'.$this->escape($locale).'" href="'.$this->escape($link).'" />'."\n";
22
            }
23
        }
24
25
        return $buffer;
26
    }
27
}