Completed
Push — master ( 85472e...46e0b8 )
by Yann
9s
created

SecurityVoterBuilder::buildDefinitions()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 24
Code Lines 14

Duplication

Lines 24
Ratio 100 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 24
loc 24
rs 8.9713
cc 3
eloc 14
nc 3
nop 0
1
<?php
2
3
namespace Knp\Rad\AutoRegistration\DefinitionBuilder;
4
5
use Knp\Rad\AutoRegistration\DefinitionBuilder;
6
use Knp\Rad\AutoRegistration\Finder\BundleFinder;
7
use Knp\Rad\AutoRegistration\Kernel\KernelWrapper;
8
use Knp\Rad\AutoRegistration\Reflection\ClassAnalyzer;
9
use Symfony\Component\DependencyInjection\Definition;
10
11 View Code Duplication
class SecurityVoterBuilder implements DefinitionBuilder
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
12
{
13
    /**
14
     * @var KernelWrapper
15
     */
16
    private $kernel;
17
18
    /**
19
     * @var BundleFinder
20
     */
21
    private $finder;
22
23
    /**
24
     * @var ClassAnalyzer
25
     */
26
    private $analyzer;
27
28
    /**
29
     * @param KernelWrapper $kernel
30
     * @param BundleFinder  $finder
31
     * @param ClassAnalyzer $analyzer
32
     */
33
    public function __construct(KernelWrapper $kernel, BundleFinder $finder, ClassAnalyzer $analyzer)
34
    {
35
        $this->kernel   = $kernel;
36
        $this->finder   = $finder;
37
        $this->analyzer = $analyzer;
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function buildDefinitions()
44
    {
45
        $definitions = [];
46
47
        $voters = $this->finder->findClasses(
48
            $this->kernel->getBundles(),
49
            'Security',
50
            'Symfony\Component\Security\Core\Authorization\Voter\VoterInterface'
51
        );
52
53
        foreach ($voters as $voter) {
54
            if (true === $this->analyzer->needConstruction($voter)) {
55
                continue;
56
            }
57
58
            $definitions[$voter] = (new Definition())
59
                ->setClass($voter)
60
                ->setPublic(false)
61
                ->addTag('security.voter')
62
            ;
63
        }
64
65
        return $definitions;
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71
    public function getName()
72
    {
73
        return 'security_voter';
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79
    public function isActive()
80
    {
81
        return true;
82
    }
83
}
84