ProtectedPropertiesMap::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 7
cts 7
cp 1
rs 9.8333
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProxyManager\ProxyGenerator\LazyLoadingGhost\PropertyGenerator;
6
7
use Laminas\Code\Generator\Exception\InvalidArgumentException;
8
use Laminas\Code\Generator\PropertyGenerator;
9
use ProxyManager\Generator\Util\IdentifierSuffixer;
10
use ProxyManager\ProxyGenerator\Util\Properties;
11
12
/**
13
 * Property that contains the protected instance lazy-loadable properties of an object
14
 */
15
class ProtectedPropertiesMap extends PropertyGenerator
16
{
17
    public const KEY_DEFAULT_VALUE = 'defaultValue';
18
19
    /**
20
     * Constructor
21
     *
22
     * @throws InvalidArgumentException
23
     */
24
    public function __construct(Properties $properties)
25
    {
26 4
        parent::__construct(
27
            IdentifierSuffixer::getIdentifier('protectedProperties')
28 4
        );
29 4
30
        $this->setVisibility(self::VISIBILITY_PRIVATE);
31
        $this->setStatic(true);
32 4
        $this->setDocBlock(
33 4
            '@var string[][] declaring class name of defined protected properties, indexed by property name'
34 4
        );
35 4
        $this->setDefaultValue($this->getMap($properties));
36
    }
37 4
38 4
    /** @return string[] */
39
    private function getMap(Properties $properties) : array
40
    {
41 4
        $map = [];
42
43 4
        foreach ($properties->getProtectedProperties() as $property) {
44
            $map[$property->getName()] = $property->getDeclaringClass()->getName();
45 4
        }
46 3
47
        return $map;
48
    }
49
}
50