MethodAttributesMetadataProcessor   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 17
c 2
b 0
f 0
dl 0
loc 29
ccs 20
cts 20
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 23 2
A __construct() 0 2 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\Preparation\Processor;
15
16
use Micro\Library\DTO\ClassDef\ClassDefinition;
17
use Micro\Library\DTO\ClassDef\MethodDefinition;
18
use Micro\Library\DTO\Helper\NameNormalizerInterface;
19
use Micro\Library\DTO\Preparation\PreparationProcessorInterface;
20
21
class MethodAttributesMetadataProcessor implements PreparationProcessorInterface
22
{
23 6
    public function __construct(private NameNormalizerInterface $nameNormalizer)
24
    {
25 6
    }
26
27 1
    public function process(array $classDef, ClassDefinition $classDefinition, array $classList): void
28
    {
29 1
        $metadataArray = [];
30 1
        foreach ($classDefinition->getProperties() as $property) {
31 1
            $meta = [];
32 1
            $meta[PreparationProcessorInterface::PROP_TYPE] = $property->getTypes();
33 1
            $meta[PreparationProcessorInterface::PROP_REQUIRED] = $property->isRequired();
34 1
            $meta[PreparationProcessorInterface::PROP_ACTION_NAME] = $this->nameNormalizer->normalize(ucfirst($property->getName()));
35
36 1
            $propertyName = $property->getName();
37 1
            $metadataArray[$propertyName] = $meta;
38
        }
39
40 1
        $attributesMetaMethod = new MethodDefinition();
41 1
        $attributesMetaMethod->setIsStatic(true);
42 1
        $attributesMetaMethod->setName('attributesMetadata');
43 1
        $attributesMetaMethod->setTypesReturn(['array']);
44 1
        $attributesMetaMethod->setVisibility('protected');
45 1
        $attributesMetaMethod->setBody(
46 1
            'return '.var_export($metadataArray, true).';'
47 1
        );
48
49 1
        $classDefinition->addMethod($attributesMetaMethod);
50
    }
51
}
52