Completed
Pull Request — master (#13)
by Peter
03:12
created

PlainTextSitemapIndexRender::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * GpsLab component.
6
 *
7
 * @author    Peter Gribanov <[email protected]>
8
 * @copyright Copyright (c) 2011, Peter Gribanov
9
 * @license   http://opensource.org/licenses/MIT
10
 */
11
12
namespace GpsLab\Component\Sitemap\Render;
13
14
class PlainTextSitemapIndexRender implements SitemapIndexRender
15
{
16
    /**
17
     * @var string
18
     */
19
    private $host = '';
20
21
    /**
22
     * @param string $host
23
     */
24 6
    public function __construct(string $host)
25
    {
26 6
        $this->host = $host;
27 6
    }
28
    /**
29
     * @return string
30
     */
31 3
    public function start(): string
32
    {
33 3
        return '<?xml version="1.0" encoding="utf-8"?>'.PHP_EOL.
34 3
            '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
35
    }
36
37
    /**
38
     * @return string
39
     */
40 3
    public function end(): string
41
    {
42 3
        return '</sitemapindex>'.PHP_EOL;
43
    }
44
45
    /**
46
     * @param string                  $path
47
     * @param \DateTimeInterface|null $last_mod
48
     *
49
     * @return string
50
     */
51 4
    public function sitemap(string $path, \DateTimeInterface $last_mod = null): string
52
    {
53
        return '<sitemap>'.
54 4
            '<loc>'.$this->host.$path.'</loc>'.
55 4
            ($last_mod ? sprintf('<lastmod>%s</lastmod>', $last_mod->format('c')) : '').
56 4
        '</sitemap>';
57
    }
58
}
59