PropertyCollectionProcessor::process()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 3
eloc 11
c 2
b 0
f 0
nc 3
nop 4
dl 0
loc 21
ccs 13
cts 13
cp 1
crap 3
rs 9.9
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\Processor\Property;
15
16
use Micro\Library\DTO\ClassDef\ClassDefinition;
17
use Micro\Library\DTO\ClassDef\PropertyDefinition;
18
use Micro\Library\DTO\Object\Collection;
19
use Micro\Library\DTO\Preparation\PreparationProcessorInterface;
20
21
class PropertyCollectionProcessor implements PropertyProcessorInterface
22
{
23
    /**
24
     * @param PropertyDefinition   $propertyDefinition
25
     * @param ClassDefinition      $classDefinition
26
     * @param array<string, mixed> $propertyData
27
     * @param array<string>        $classList
28
     *
29
     * @return void
30
     */
31 1
    public function process(PropertyDefinition $propertyDefinition, ClassDefinition $classDefinition, array $propertyData, array $classList): void
32
    {
33 1
        $isCollection = $propertyData[PreparationProcessorInterface::PROP_TYPE_IS_COLLECTION] ?? false;
34 1
        $isRequired = $propertyDefinition->isRequired();
35 1
        if (!$isCollection) {
36 1
            return;
37
        }
38
39
        // $propTypes = $propertyDefinition->getTypes();
40 1
        $types = [
41 1
            'iterable',
42 1
        ];
43
44 1
        if (!$isRequired) {
45 1
            $types[] = 'null';
46
        }
47
48 1
        $propertyDefinition->setTypes($types);
49 1
        $propertyDefinition->setIsCollection(true);
50
51 1
        $classDefinition->addUseStatement(Collection::class);
52
    }
53
}
54