Passed
Push — master ( 896e22...61bd56 )
by Dāvis
03:36
created

PropelProvider   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A populate() 0 12 3
A getQuery() 0 3 1
1
<?php
2
3
namespace Sludio\HelperBundle\Sitemap\Provider;
4
5
use Symfony\Component\Routing\RouterInterface;
6
use Sludio\HelperBundle\Sitemap\Sitemap;
7
8
class PropelProvider extends AbstractProvider
9
{
10
    protected $router = null;
11
12
    protected $options = [
13
        'model' => null,
14
        'loc' => [],
15
        'filters' => [],
16
        'lastmod' => null,
17
        'priority' => null,
18
        'changefreq' => null,
19
    ];
20
21
    /**
22
     * Constructor
23
     *
24
     * @param RouterInterface $router  The application router.
25
     * @param array           $options The options (see the class comment).
26
     */
27
    public function __construct(RouterInterface $router, array $options)
28
    {
29
        parent::__construct($router, $options);
30
31
        if (!class_exists($options['model'])) {
32
            throw new \LogicException('Can\'t find class '.$options['model']);
33
        }
34
    }
35
36
    /**
37
     * Populate a sitemap using a Propel model.
38
     *
39
     * @param Sitemap $sitemap The current sitemap.
40
     */
41
    public function populate(Sitemap $sitemap)
42
    {
43
        $query = $this->getQuery($this->options['model']);
44
45
        // apply filters on the query
46
        foreach ($this->options['filters'] as $filter) {
47
            $query->$filter();
48
        }
49
50
        // and populate the sitemap!
51
        foreach ($query->find() as $result) {
52
            $sitemap->add($this->resultToUrl($result));
53
        }
54
    }
55
56
    protected function getQuery($model)
57
    {
58
        return \PropelQuery::from($model)->setFormatter('PropelOnDemandFormatter');
0 ignored issues
show
Bug introduced by
The type PropelQuery was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
59
    }
60
}