RoutingAnnotationLoader   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A supports() 0 3 1
A load() 0 14 3
A __construct() 0 4 1
1
<?php
2
3
namespace DH\DoctrineAuditBundle\Routing;
4
5
use DH\DoctrineAuditBundle\Controller\ViewerController;
6
use RuntimeException;
7
use Symfony\Bundle\FrameworkBundle\Routing\AnnotatedRouteControllerLoader;
8
use Symfony\Component\Config\Loader\Loader;
9
use Symfony\Component\Routing\RouteCollection;
10
11
class RoutingAnnotationLoader extends Loader
12
{
13
    /**
14
     * @var AnnotatedRouteControllerLoader
15
     */
16
    private $annotatedRouteControllerLoader;
17
18
    /**
19
     * @var bool
20
     */
21
    private $isLoaded = false;
22
23
    /**
24
     * @var array
25
     */
26
    private $configuration;
27
28
    public function __construct(AnnotatedRouteControllerLoader $annotatedRouteController, array $configuration)
29
    {
30
        $this->annotatedRouteControllerLoader = $annotatedRouteController;
31
        $this->configuration = $configuration;
32
    }
33
34
    public function load($resource, ?string $type = null): RouteCollection
35
    {
36
        if (true === $this->isLoaded) {
37
            throw new RuntimeException('Do not add the "audit" loader twice');
38
        }
39
40
        $routeCollection = new RouteCollection();
41
        if (true === $this->configuration['enabled_viewer']) {
42
            $routeCollection = $this->annotatedRouteControllerLoader->load(ViewerController::class);
43
        }
44
45
        $this->isLoaded = true;
46
47
        return $routeCollection;
48
    }
49
50
    public function supports($resource, ?string $type = null): bool
51
    {
52
        return 'audit' === $type;
53
    }
54
}
55