RoutingAnnotationLoader   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

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

3 Methods

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