SitemapDefinition   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Importance

Changes 0
Metric Value
wmc 10
lcom 2
cbo 0
dl 0
loc 57
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A __toString() 0 4 1
A toString() 0 4 2
A getType() 0 4 1
A setSettings() 0 4 1
A getSettings() 0 4 1
A getSetting() 0 4 1
A getTtl() 0 8 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * (c) Christian Gripp <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Core23\SitemapBundle\Definition;
13
14
final class SitemapDefinition implements SitemapDefinitionInterface
15
{
16
    /**
17
     * @var array
18
     */
19
    private $settings;
20
21
    /**
22
     * @var string
23
     */
24
    private $type;
25
26
    public function __construct(string $type, array $settings = [])
27
    {
28
        $this->settings = $settings;
29
        $this->type     = $type;
30
    }
31
32
    public function __toString()
33
    {
34
        return $this->toString();
35
    }
36
37
    public function toString(): string
38
    {
39
        return $this->getType() ?: 'n/a';
40
    }
41
42
    public function getType(): string
43
    {
44
        return $this->type;
45
    }
46
47
    public function setSettings(array $settings = []): void
48
    {
49
        $this->settings = $settings;
50
    }
51
52
    public function getSettings(): array
53
    {
54
        return $this->settings;
55
    }
56
57
    public function getSetting(string $name, $default = null)
58
    {
59
        return $this->settings[$name] ?? $default;
60
    }
61
62
    public function getTtl(): int
63
    {
64
        if (true !== $this->getSetting('use_cache', true)) {
65
            return 0;
66
        }
67
68
        return (int) $this->getSetting('ttl', 0);
69
    }
70
}
71