Completed
Pull Request — master (#13)
by Peter
06:35
created

PlainTextSitemapIndexRender   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 46
rs 10
c 0
b 0
f 0
ccs 9
cts 9
cp 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A end() 0 4 1
A __construct() 0 4 1
A start() 0 5 1
A sitemap() 0 7 2
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * GpsLab component.
6
 *
7
 * @author    Peter Gribanov <[email protected]>
8
 * @copyright Copyright (c) 2011-2019, 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 3
     * @var string
18
     */
19 3
    private $host = '';
20 3
21
    /**
22
     * @param string $host
23
     */
24
    public function __construct(string $host)
25
    {
26 3
        $this->host = $host;
27
    }
28 3
29
    /**
30
     * @return string
31
     */
32
    public function start(): string
33
    {
34
        return '<?xml version="1.0" encoding="utf-8"?>'.PHP_EOL.
35
            '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
36
    }
37 4
38
    /**
39
     * @return string
40 4
     */
41 4
    public function end(): string
42 4
    {
43
        return '</sitemapindex>'.PHP_EOL;
44
    }
45
46
    /**
47
     * @param string                  $path
48
     * @param \DateTimeInterface|null $last_mod
49
     *
50
     * @return string
51
     */
52
    public function sitemap(string $path, \DateTimeInterface $last_mod = null): string
53
    {
54
        return '<sitemap>'.
55
            '<loc>'.$this->host.$path.'</loc>'.
56
            ($last_mod ? sprintf('<lastmod>%s</lastmod>', $last_mod->format('c')) : '').
57
        '</sitemap>';
58
    }
59
}
60