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

RichXmlFormatter::getSitemapStart()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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
}