AliasSitemapProvider   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 9
Bugs 2 Features 0
Metric Value
eloc 14
c 9
b 2
f 0
dl 0
loc 39
ccs 0
cts 18
cp 0
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A all() 0 18 2
1
<?php
2
/**
3
 * @copyright Zicht Online <http://zicht.nl>
4
 */
5
6
namespace Zicht\Bundle\UrlBundle\Url;
7
8
use Doctrine\DBAL\Connection;
9
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
10
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
11
use Zicht\Bundle\UrlBundle\Entity\UrlAlias;
12
use Zicht\Bundle\UrlBundle\Event\SitemapFilterEvent;
13
use Zicht\Bundle\UrlBundle\Events;
14
15
/**
16
 * This Provider used to be optimistic, however now has been made a bit smarter while maintaining backwards compatibility.
17
 */
18
class AliasSitemapProvider implements ListableProvider
19
{
20
    /** @var Connection  */
21
    private $connection;
22
    /** @var EventDispatcherInterface  */
23
    private $eventDispatcher;
24
25
    /**
26
     * Constructor
27
     *
28
     * @param Connection $connection
29
     */
30
    public function __construct(Connection $connection, EventDispatcherInterface $eventDispatcher)
31
    {
32
        $this->connection = $connection;
33
        $this->eventDispatcher = $eventDispatcher;
34
    }
35
36
    /**
37
     * @{inheritDoc}
38
     */
39
    public function all(AuthorizationCheckerInterface $authorizationChecker)
40
    {
41
        $query = $this->connection->prepare('SELECT * FROM url_alias WHERE mode=?');
42
        $query->execute([UrlAlias::REWRITE]);
43
        $urls = new \ArrayObject($query->fetchAll(\PDO::FETCH_ASSOC));
44
45
        /**
46
         * Hook to allow the mapping to be modified at run-time.
47
         */
48
        if ($this->eventDispatcher->hasListeners(Events::EVENT_SITEMAP_FILTER)) {
49
            $this->eventDispatcher->dispatch(Events::EVENT_SITEMAP_FILTER, new SitemapFilterEvent($urls));
50
        }
51
52
        return array_map(
53
            function ($url) {
54
                return ['value' => $url['public_url']];
55
            },
56
            $urls->getArrayCopy()
57
        );
58
    }
59
}
60