Generator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 6
c 2
b 0
f 0
dl 0
loc 23
ccs 8
cts 8
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A generate() 0 9 2
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\Generator;
15
16
use Micro\Library\DTO\ClassDef\ClassDefinition;
17
use Micro\Library\DTO\Preparation\CollectionPreparationInterface;
18
use Micro\Library\DTO\Reader\ReaderInterface;
19
use Micro\Library\DTO\View\RendererInterface;
20
use Micro\Library\DTO\Writer\WriterInterface;
21
use Psr\Log\LoggerInterface;
22
23
class Generator
24
{
25 6
    public function __construct(
26
        private ReaderInterface $reader,
27
        private WriterInterface $writer,
28
        private RendererInterface $renderer,
29
        private CollectionPreparationInterface $classCollectionPreparation,
30
        private LoggerInterface $logger
31
    ) {
32 6
    }
33
34
    /**
35
     * @return void
36
     */
37 6
    public function generate(): void
38
    {
39
        /** @var ClassDefinition $classDef */
40 6
        foreach ($this->classCollectionPreparation->process($this->reader) as $classDef) {
41 1
            $classRendered = $this->renderer->render($classDef);
42 1
            $classname = $classDef->getNamespace().'\\'.$classDef->getName();
43
44 1
            $this->writer->write($classname, $classRendered);
45 1
            $this->logger->debug(sprintf('Generated class "%s"', $classname));
46
        }
47
    }
48
}
49