Passed
Push — master ( eb2b9c...2ce42f )
by Dāvis
05:18 queued 02:31
created

SimpleProvider::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 2
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
namespace Sludio\HelperBundle\Sitemap\Provider;
4
5
use Sludio\HelperBundle\Sitemap\Sitemap;
6
use Sludio\HelperBundle\Sitemap\Entity\Url;
7
use Symfony\Component\Routing\RouterInterface;
8
9
class SimpleProvider extends AbstractProvider
10
{
11
    protected $defaultRoute = [
12
        'params' => [],
13
        'priority' => null,
14
        'changefreq' => null,
15
        'lastmod' => null,
16
    ];
17
18
    public function populate(Sitemap $sitemap)
19
    {
20
        foreach ($this->options['routes'] as $route) {
21
            $route = array_merge($this->defaultRoute, $route);
22
23
            $url = new Url();
24
            $url->setLoc($this->router->generate($route['name'], $route['params']));
25
            $url->setChangefreq($route['changefreq'] ?: $this->options['changefreq']);
26
            $url->setLastmod($route['lastmod'] ?: $this->options['lastmod']);
27
            $url->setPriority($route['priority'] ?: $this->options['priority']);
28
            $sitemap->add($url);
29
        }
30
    }
31
32
    public function __construct(RouterInterface $router, array $options)
33
    {
34
        parent::__construct($router, $options);
35
36
        $this->options = [
37
            'routes' => [],
38
            'lastmod' => null,
39
            'priority' => null,
40
            'changefreq' => null,
41
        ];
42
    }
43
}
44