SiteMap   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
dl 0
loc 42
ccs 18
cts 20
cp 0.9
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A make() 0 4 1
A addPath() 0 8 1
A render() 0 17 2
1
<?php
2
3
namespace Pageon\Html;
4
5
class SiteMap
6
{
7
    private $urls = [];
8
    private $hostname;
9
10 1
    public function __construct(string $hostname)
11
    {
12 1
        $this->hostname = trim($hostname, '/');
13 1
    }
14
15
    public static function make(string $hostname): SiteMap
16
    {
17
        return new self($hostname);
18
    }
19
20 1
    public function addPath(string $path): SiteMap
21
    {
22 1
        $path = trim($path, '/');
23
24 1
        $this->urls[] = "{$this->hostname}/{$path}";
25
26 1
        return $this;
27
    }
28
29 1
    public function render(): string
30
    {
31 1
        $xml = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
32 1
        $xml .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";
33 1
        $dateModified = date('c');
34
35 1
        foreach ($this->urls as $url) {
36 1
            $xml .= "\t<url>\n";
37 1
            $xml .= "\t\t<loc>{$url}</loc>\n";
38 1
            $xml .= "\t\t<lastmod>{$dateModified}</lastmod>\n";
39 1
            $xml .= "\t</url>\n";
40
        }
41
42 1
        $xml .= '</urlset>';
43
44 1
        return $xml;
45
    }
46
}
47