Completed
Push — master ( fa3c04...692093 )
by Vitaly
02:57
created

toPropertyMetadata()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 12
rs 9.2
cc 4
eloc 5
nc 3
nop 1
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 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 ($propertyMetadata->typeHint === null || $propertyMetadata->typeHint === '') {
34
            throw new TypeHintDoesNotExists('Cannot configure property "' . $propertyMetadata->name . '" injection');
35
        }
36
37
        // Check if specified type hint exists
38
        if (!class_exists($propertyMetadata->typeHint)) {
39
            throw new ClassDoesNotExists('Cannot configure property "' . $propertyMetadata->name . '" with "' . $propertyMetadata->typeHint . '"');
40
        }
41
    }
42
}
43