InjectablePropertyConfigurator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 30
rs 10
c 3
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A toPropertyMetadata() 0 16 4
1
<?php declare(strict_types = 1);
2
/**
3
 * Created by Vitaly Iegorov <[email protected]>.
4
 * on 14.08.16 at 20:33
5
 */
6
namespace samsonframework\container\configurator;
7
8
use samsonframework\container\configurator\expection\ClassDoesNotExists;
9
use samsonframework\container\configurator\expection\TypeHintDoesNotExists;
10
use samsonframework\container\metadata\PropertyMetadata;
11
12
/**
13
 * Property injection configurator.
14
 *
15
 * @author Vitaly Egorov <[email protected]>
16
 */
17
class InjectablePropertyConfigurator extends InjectableAbstractConfigurator implements PropertyConfiguratorInterface
18
{
19
    /**
20
     * Convert to class property metadata.
21
     *
22
     * @param PropertyMetadata $propertyMetadata Input metadata
23
     *
24
     * @return PropertyMetadata Annotation conversion to metadata
25
     *
26
     * @throws TypeHintDoesNotExists
27
     * @throws ClassDoesNotExists
28
     *
29
     */
30
    public function toPropertyMetadata(PropertyMetadata $propertyMetadata)
31
    {
32
        // Check if there is no type hint - we cannot inject without it
33
        if ($this->argumentType === null || $this->argumentType === '') {
34
            throw new TypeHintDoesNotExists('Cannot configure property "' . $propertyMetadata->name . '" injection');
35
        }
36
37
        // Check if specified type hint exists
38
        if (!class_exists($this->argumentType)) {
39
            throw new ClassDoesNotExists('Cannot configure property "' . $this->argumentName . '" with "' . $this->argumentType . '"');
40
        }
41
42
        // Store property metadata
43
        $propertyMetadata->typeHint = $this->argumentType;
44
        $propertyMetadata->name = $this->argumentName;
45
    }
46
}
47