Passed
Push — master ( ca367b...309dd5 )
by Damien
03:01
created

DoctrineAuditRoutingLoader   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 29
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 8 2
A setConfiguration() 0 3 1
A setRoutingLoaderAnnotation() 0 3 1
A supports() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DH\DoctrineAuditBundle\Routing;
6
7
use Symfony\Bundle\FrameworkBundle\Routing\AnnotatedRouteControllerLoader;
8
use Symfony\Component\Config\Loader\Loader;
9
use Symfony\Component\Config\Loader\LoaderInterface;
10
use Symfony\Component\Routing\RouteCollection;
11
12
class DoctrineAuditRoutingLoader extends Loader implements LoaderInterface
13
{
14
    private $annotationLoader;
15
16
    private $configuration;
17
18
    public function load($resource, ?string $type = null): RouteCollection
19
    {
20
        $routeCollection = new RouteCollection();
21
        if (true === $this->configuration['enabled_viewer']) {
22
            $routeCollection = $this->annotationLoader->load('DH\DoctrineAuditBundle\Controller\AuditController');
23
        }
24
25
        return $routeCollection;
26
    }
27
28
    public function supports($resource, ?string $type = null): bool
29
    {
30
        return 'audit_loader' === $type;
31
    }
32
33
    public function setRoutingLoaderAnnotation(AnnotatedRouteControllerLoader $loader): void
34
    {
35
        $this->annotationLoader = $loader;
36
    }
37
38
    public function setConfiguration(iterable $configuration): void
39
    {
40
        $this->configuration = $configuration;
41
    }
42
}
43