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

SimpleProvider   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 32
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
B populate() 0 11 5
A __construct() 0 9 1
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