Completed
Branch master (d17104)
by Christian
21:20
created

AbstractXmlSitemapDataProvider   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 75
rs 10
c 0
b 0
f 0
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getKey() 0 3 1
A getLastModified() 0 10 3
A __construct() 0 9 2
A getItems() 0 3 1
1
<?php
2
declare(strict_types = 1);
3
namespace TYPO3\CMS\Seo\XmlSitemap;
4
5
use Psr\Http\Message\ServerRequestInterface;
6
use TYPO3\CMS\Core\Utility\GeneralUtility;
7
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
8
9
/**
10
 * Base class for XmlSitemapProviders to extend
11
 */
12
abstract class AbstractXmlSitemapDataProvider implements XmlSitemapDataProviderInterface
13
{
14
    /**
15
     * @var string
16
     */
17
    protected $key;
18
19
    /**
20
     * @var int
21
     */
22
    protected $lastModified;
23
24
    /**
25
     * @var array
26
     */
27
    protected $items = [];
28
29
    /**
30
     * @var array
31
     */
32
    protected $config = [];
33
34
    /**
35
     * @var ContentObjectRenderer
36
     */
37
    protected $cObj;
38
39
    /**
40
     * AbstractXmlSitemapDataProvider constructor
41
     *
42
     * @param \Psr\Http\Message\ServerRequestInterface $request
43
     * @param string $key
44
     * @param array $config
45
     * @param ContentObjectRenderer $cObj
46
     */
47
    public function __construct(ServerRequestInterface $request, string $key, array $config = [], ContentObjectRenderer $cObj = null)
48
    {
49
        $this->key = $key;
50
        $this->config = $config;
51
52
        if ($cObj === null) {
53
            $cObj = GeneralUtility::makeInstance(ContentObjectRenderer::class);
54
        }
55
        $this->cObj = $cObj;
56
    }
57
58
    /**
59
     * @return string
60
     */
61
    public function getKey(): string
62
    {
63
        return $this->key;
64
    }
65
66
    /**
67
     * @return int
68
     */
69
    public function getLastModified(): int
70
    {
71
        $lastMod = 0;
72
        foreach ($this->items as $item) {
73
            if ((int)$item['lastMod'] > $lastMod) {
74
                $lastMod = $item['lastMod'];
75
            }
76
        }
77
78
        return $lastMod;
79
    }
80
81
    /**
82
     * @return array
83
     */
84
    public function getItems(): array
85
    {
86
        return (array)$this->items;
87
    }
88
}
89