DependencyInjection   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 129
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 70
c 2
b 0
f 0
dl 0
loc 129
ccs 85
cts 85
cp 1
rs 10
wmc 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A createWriter() 0 5 1
A __construct() 0 7 1
A createReader() 0 5 1
A createPreparationProcessorCollection() 0 25 1
A createRenderer() 0 3 1
A createPropertyValidationProcessorCollection() 0 40 1
A createClassMetadataHelper() 0 3 1
A createClassPreparationProcessor() 0 3 1
A createCamelCaseProcessor() 0 3 1
A getLogger() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 *  This file is part of the Micro framework package.
7
 *
8
 *  (c) Stanislau Komar <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace Micro\Library\DTO;
15
16
use Micro\Library\DTO\Helper\CamelCaseNormalizer;
17
use Micro\Library\DTO\Helper\ClassMetadataHelper;
18
use Micro\Library\DTO\Helper\NameNormalizerInterface;
19
use Micro\Library\DTO\Merger\MergerFactory;
20
use Micro\Library\DTO\Preparation\CollectionPreparation;
21
use Micro\Library\DTO\Preparation\CollectionPreparationInterface;
22
use Micro\Library\DTO\Preparation\PreparationProcessorInterface;
23
use Micro\Library\DTO\Preparation\Processor\ClassCommentProcessor;
24
use Micro\Library\DTO\Preparation\Processor\ClassNameProcessor;
25
use Micro\Library\DTO\Preparation\Processor\ClassPropertyProcessor;
26
use Micro\Library\DTO\Preparation\Processor\MethodAttributesMetadataProcessor;
27
use Micro\Library\DTO\Preparation\Processor\MethodGetProcessor;
28
use Micro\Library\DTO\Preparation\Processor\MethodSetProcessor;
29
use Micro\Library\DTO\Preparation\Processor\Property\Assert\BicStrategy;
30
use Micro\Library\DTO\Preparation\Processor\Property\Assert\BlankStrategy;
31
use Micro\Library\DTO\Preparation\Processor\Property\Assert\CardSchemeStrategy;
32
use Micro\Library\DTO\Preparation\Processor\Property\Assert\ChoiceStrategy;
33
use Micro\Library\DTO\Preparation\Processor\Property\Assert\CurrencyStrategy;
34
use Micro\Library\DTO\Preparation\Processor\Property\Assert\DateStrategy;
35
use Micro\Library\DTO\Preparation\Processor\Property\Assert\DateTimeStrategy;
36
use Micro\Library\DTO\Preparation\Processor\Property\Assert\EmailStrategy;
37
use Micro\Library\DTO\Preparation\Processor\Property\Assert\EqualToStrategy;
38
use Micro\Library\DTO\Preparation\Processor\Property\Assert\ExpressionStrategy;
39
use Micro\Library\DTO\Preparation\Processor\Property\Assert\GreaterThanOrEqualStrategy;
40
use Micro\Library\DTO\Preparation\Processor\Property\Assert\GreaterThanStrategy;
41
use Micro\Library\DTO\Preparation\Processor\Property\Assert\HostnameStrategy;
42
use Micro\Library\DTO\Preparation\Processor\Property\Assert\IbanStrategy;
43
use Micro\Library\DTO\Preparation\Processor\Property\Assert\IdenticalToStrategy;
44
use Micro\Library\DTO\Preparation\Processor\Property\Assert\IpStrategy;
45
use Micro\Library\DTO\Preparation\Processor\Property\Assert\IsbnStrategy;
46
use Micro\Library\DTO\Preparation\Processor\Property\Assert\IsinStrategy;
47
use Micro\Library\DTO\Preparation\Processor\Property\Assert\IssnStrategy;
48
use Micro\Library\DTO\Preparation\Processor\Property\Assert\JsonStrategy;
49
use Micro\Library\DTO\Preparation\Processor\Property\Assert\LengthStrategy;
50
use Micro\Library\DTO\Preparation\Processor\Property\Assert\LessThanOrEqualStrategy;
51
use Micro\Library\DTO\Preparation\Processor\Property\Assert\LessThanStrategy;
52
use Micro\Library\DTO\Preparation\Processor\Property\Assert\LuhnStrategy;
53
use Micro\Library\DTO\Preparation\Processor\Property\Assert\NegativeOrZeroStrategy;
54
use Micro\Library\DTO\Preparation\Processor\Property\Assert\NegativeStrategy;
55
use Micro\Library\DTO\Preparation\Processor\Property\Assert\NotBlankStrategy;
56
use Micro\Library\DTO\Preparation\Processor\Property\Assert\NotEqualToStrategy;
57
use Micro\Library\DTO\Preparation\Processor\Property\Assert\NotIdenticalToStrategy;
58
use Micro\Library\DTO\Preparation\Processor\Property\Assert\PositiveOrZeroStrategy;
59
use Micro\Library\DTO\Preparation\Processor\Property\Assert\PositiveStrategy;
60
use Micro\Library\DTO\Preparation\Processor\Property\Assert\RangeStrategy;
61
use Micro\Library\DTO\Preparation\Processor\Property\Assert\RegexStrategy;
62
use Micro\Library\DTO\Preparation\Processor\Property\Assert\TimeStrategy;
63
use Micro\Library\DTO\Preparation\Processor\Property\Assert\TimeZoneStrategy;
64
use Micro\Library\DTO\Preparation\Processor\Property\Assert\UrlStrategy;
65
use Micro\Library\DTO\Preparation\Processor\Property\Assert\UuidStrategy;
66
use Micro\Library\DTO\Preparation\Processor\Property\AttributeValidationProcessor;
67
use Micro\Library\DTO\Preparation\Processor\Property\CommentProcessor;
68
use Micro\Library\DTO\Preparation\Processor\Property\DateTypeProcessor;
69
use Micro\Library\DTO\Preparation\Processor\Property\DtoPropertyProcessor;
70
use Micro\Library\DTO\Preparation\Processor\Property\NameProcessor;
71
use Micro\Library\DTO\Preparation\Processor\Property\PropertyAbstractProcessor;
72
use Micro\Library\DTO\Preparation\Processor\Property\PropertyCollectionProcessor;
73
use Micro\Library\DTO\Preparation\Processor\Property\PropertyProcessorInterface;
74
use Micro\Library\DTO\Preparation\Processor\Property\PropertyRequiredProcessor;
75
use Micro\Library\DTO\Preparation\Processor\Property\TypeProcessor;
76
use Micro\Library\DTO\Preparation\Processor\Property\ValueProcessor;
77
use Micro\Library\DTO\Reader\ReaderInterface;
78
use Micro\Library\DTO\Reader\XmlReader;
79
use Micro\Library\DTO\View\Nette\NetteRenderer;
80
use Micro\Library\DTO\View\RendererInterface;
81
use Micro\Library\DTO\Writer\WriterFilesystem;
82
use Micro\Library\DTO\Writer\WriterInterface;
83
use Psr\Log\LoggerInterface;
84
use Psr\Log\NullLogger;
85
86
class DependencyInjection implements DependencyInjectionInterface
87
{
88
    /**
89
     * @param string[] $filesSchemeCollection
90
     */
91 6
    public function __construct(
92
        private array $filesSchemeCollection,
93
        private string $namespaceGeneral,
94
        private string $classSuffix,
95
        private string $outputPath,
96
        private ?LoggerInterface $logger
97
    ) {
98 6
    }
99
100 6
    public function getLogger(): LoggerInterface
101
    {
102 6
        return $this->logger ?? new NullLogger();
103
    }
104
105 6
    public function createClassPreparationProcessor(): CollectionPreparationInterface
106
    {
107 6
        return new CollectionPreparation($this->createPreparationProcessorCollection());
108
    }
109
110 6
    public function createReader(): ReaderInterface
111
    {
112 6
        return new XmlReader(
113 6
            $this->filesSchemeCollection,
114 6
            new MergerFactory()
115 6
        );
116
    }
117
118 6
    public function createClassMetadataHelper(): ClassMetadataHelper
119
    {
120 6
        return new ClassMetadataHelper($this->namespaceGeneral, $this->classSuffix);
121
    }
122
123 6
    public function createCamelCaseProcessor(): NameNormalizerInterface
124
    {
125 6
        return new CamelCaseNormalizer();
126
    }
127
128 6
    public function createWriter(): WriterInterface
129
    {
130 6
        return new WriterFilesystem(
131 6
            $this->outputPath,
132 6
            $this->namespaceGeneral
133 6
        );
134
    }
135
136 6
    public function createRenderer(): RendererInterface
137
    {
138 6
        return new NetteRenderer(); // new TwigRenderer($twig, $this->classTemplateName);
139
    }
140
141
    /**
142
     * @return iterable<PreparationProcessorInterface>
143
     */
144 6
    protected function createPreparationProcessorCollection(): iterable
145
    {
146 6
        $classMetadataHelper = $this->createClassMetadataHelper();
147 6
        $camelCaseHelper = $this->createCamelCaseProcessor();
148
149 6
        return [
150 6
            new ClassNameProcessor($classMetadataHelper),
151 6
            new ClassCommentProcessor(),
152 6
            new ClassPropertyProcessor([
153 6
                new NameProcessor(),
154 6
                new PropertyRequiredProcessor(),
155 6
                new TypeProcessor(),
156 6
                new DateTypeProcessor(),
157 6
                new DtoPropertyProcessor($classMetadataHelper),
158 6
                new PropertyAbstractProcessor(),
159 6
                new PropertyCollectionProcessor(),
160 6
                new ValueProcessor(),
161 6
                new CommentProcessor(),
162 6
                new AttributeValidationProcessor(
163 6
                    $this->createPropertyValidationProcessorCollection(),
164 6
                ),
165 6
            ]),
166 6
            new MethodGetProcessor($camelCaseHelper),
167 6
            new MethodSetProcessor($camelCaseHelper),
168 6
            new MethodAttributesMetadataProcessor($camelCaseHelper),
169 6
        ];
170
    }
171
172
    /**
173
     * @return iterable<PropertyProcessorInterface>
174
     */
175 6
    protected function createPropertyValidationProcessorCollection(): iterable
176
    {
177 6
        return [
178 6
            new EmailStrategy(),
179 6
            new IpStrategy(),
180 6
            new HostnameStrategy(),
181 6
            new RegexStrategy(),
182 6
            new UrlStrategy(),
183 6
            new LengthStrategy(),
184 6
            new BlankStrategy(),
185 6
            new NotBlankStrategy(),
186 6
            new JsonStrategy(),
187 6
            new UuidStrategy(),
188 6
            new DateStrategy(),
189 6
            new TimeStrategy(),
190 6
            new DateTimeStrategy(),
191 6
            new TimeZoneStrategy(),
192 6
            new NegativeStrategy(),
193 6
            new NegativeOrZeroStrategy(),
194 6
            new PositiveStrategy(),
195 6
            new PositiveOrZeroStrategy(),
196 6
            new EqualToStrategy(),
197 6
            new GreaterThanStrategy(),
198 6
            new GreaterThanOrEqualStrategy(),
199 6
            new LessThanStrategy(),
200 6
            new LessThanOrEqualStrategy(),
201 6
            new NotEqualToStrategy(),
202 6
            new NotIdenticalToStrategy(),
203 6
            new IdenticalToStrategy(),
204 6
            new RangeStrategy(),
205 6
            new CardSchemeStrategy(),
206 6
            new BicStrategy(),
207 6
            new CurrencyStrategy(),
208 6
            new LuhnStrategy(),
209 6
            new IbanStrategy(),
210 6
            new IsbnStrategy(),
211 6
            new IsinStrategy(),
212 6
            new IssnStrategy(),
213 6
            new ChoiceStrategy(),
214 6
            new ExpressionStrategy(),
215 6
        ];
216
    }
217
}
218