Issues (2)

src/DependencyInjection/InjectionExtension.php (1 issue)

Labels
Severity
1
<?php declare(strict_types=1);
2
3
namespace Incompass\InjectionBundle\DependencyInjection;
4
5
use Doctrine\Common\Annotations\AnnotationReader;
6
use Incompass\InjectionBundle\InjectProcessor;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\DependencyInjection\Extension\Extension;
9
use Symfony\Component\Finder\Finder;
10
11
/**
12
 * Class InjectionExtension
13
 *
14
 * @author  Joe Mizzi <[email protected]>
15
 *
16
 * @codeCoverageIgnore
17
 */
18
class InjectionExtension extends Extension
19
{
20
    private $processor;
21
    private $finder;
22
    private $reader;
23
24
    public function load(array $configs, ContainerBuilder $container): void
25
    {
26
        $configuration = $this->getConfiguration([], $container);
27
        $config = $this->processConfiguration($configuration, $configs);
0 ignored issues
show
It seems like $configuration can also be of type null; however, parameter $configuration of Symfony\Component\Depend...:processConfiguration() does only seem to accept Symfony\Component\Config...\ConfigurationInterface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

27
        $config = $this->processConfiguration(/** @scrutinizer ignore-type */ $configuration, $configs);
Loading history...
28
        $finder = $this->getFinder();
29
        $reader = $this->getReader();
30
        $projectDir = $container->getParameter('kernel.project_dir');
31
        $container->setParameter('injection.environment_groups', $config['environment_groups']);
32
        foreach ($config['paths'] as $path => $prefix) {
33
            foreach ($finder->in($projectDir.'/'.$path)->name('*.php') as $file => $info) {
34
                $pathLen = \strlen($projectDir.'/'.$path);
35
                $classPath = str_replace('/', '\\', substr($file, $pathLen + 1, -4));
36
                $class = $prefix.$classPath;
37
                $reflectionClass = new \ReflectionClass($class);
38
                $processor = $this->getProcessor();
39
40
                foreach ($reader->getClassAnnotations($reflectionClass) as $annotation) {
41
                    $processor->process($annotation, $class, $container);
42
                }
43
            }
44
        }
45
    }
46
47
    /**
48
     * @return InjectProcessor
49
     * @codeCoverageIgnore
50
     */
51
    public function getProcessor(): InjectProcessor
52
    {
53
        if (!$this->processor) {
54
            $this->processor = new InjectProcessor();
55
        }
56
57
        return $this->processor;
58
    }
59
60
    /**
61
     * @param InjectProcessor $processor
62
     * @codeCoverageIgnore
63
     */
64
    public function setProcessor(InjectProcessor $processor): void
65
    {
66
        $this->processor = $processor;
67
    }
68
69
    /**
70
     * @return Finder
71
     * @codeCoverageIgnore
72
     */
73
    public function getFinder(): Finder
74
    {
75
        if (!$this->finder) {
76
            $this->finder = new Finder();
77
        }
78
79
        return $this->finder;
80
    }
81
82
    /**
83
     * @param Finder $finder
84
     * @codeCoverageIgnore
85
     */
86
    public function setFinder(Finder $finder): void
87
    {
88
        $this->finder = $finder;
89
    }
90
91
    /**
92
     * @return AnnotationReader
93
     * @throws \Doctrine\Common\Annotations\AnnotationException
94
     * @codeCoverageIgnore
95
     */
96
    public function getReader(): AnnotationReader
97
    {
98
        if (!$this->reader) {
99
            $this->reader = new AnnotationReader();
100
        }
101
102
        return $this->reader;
103
    }
104
105
    /**
106
     * @param AnnotationReader $reader
107
     * @codeCoverageIgnore
108
     */
109
    public function setReader(AnnotationReader $reader): void
110
    {
111
        $this->reader = $reader;
112
    }
113
}