CollectionPreparation::createClassList()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 2
rs 10
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\Preparation;
15
16
use Micro\Library\DTO\ClassDef\ClassDefinition;
17
use Micro\Library\DTO\Reader\ReaderInterface;
18
19
class CollectionPreparation implements CollectionPreparationInterface
20
{
21
    /**
22
     * @param iterable<PreparationProcessorInterface> $preparationProcessor
23
     */
24 6
    public function __construct(private iterable $preparationProcessor)
25
    {
26 6
    }
27
28
    /**
29
     * {@inheritDoc}
30
     */
31 6
    public function process(ReaderInterface $reader): iterable
32
    {
33 6
        $classCollection = $reader->read();
34 4
        if ($classCollection instanceof \Traversable) {
35 4
            $classCollection = iterator_to_array($classCollection);
36
        }
37
38 3
        $classList = $this->createClassList($classCollection);
0 ignored issues
show
Bug introduced by
It seems like $classCollection can also be of type iterable; however, parameter $classes of Micro\Library\DTO\Prepar...tion::createClassList() does only seem to accept array, 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

38
        $classList = $this->createClassList(/** @scrutinizer ignore-type */ $classCollection);
Loading history...
39
40 3
        foreach ($classCollection as $classDef) {
41 3
            $classDefObj = new ClassDefinition();
42 3
            foreach ($this->preparationProcessor as $processor) {
43 3
                $processor->process($classDef, $classDefObj, $classList);
44
            }
45
46 1
            yield $classDefObj;
47
        }
48
    }
49
50
    /**
51
     * @param array<string, mixed> $classes
52
     *
53
     * @return array<class-string>
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<class-string> at position 2 could not be parsed: Unknown type name 'class-string' at position 2 in array<class-string>.
Loading history...
54
     */
55 3
    protected function createClassList(array $classes): array
56
    {
57 3
        $result = [];
58 3
        foreach ($classes as $classDef) {
59 3
            $result[] = $classDef[PreparationProcessorInterface::CLASS_NAME];
60
        }
61
62 3
        return $result;
63
    }
64
}
65