HydratorContext::getProperty()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 4.128

Importance

Changes 0
Metric Value
cc 4
eloc 4
nc 3
nop 1
dl 0
loc 8
ccs 4
cts 5
cp 0.8
crap 4.128
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Sf4\Populator;
4
5
class HydratorContext implements HydratorContextInterface
6
{
7
    /**
8
     * Class to hydrate
9
     * @var string
10
     */
11
    protected $class;
12
    /**
13
     * Properties
14
     * @var array
15
     */
16
    protected $properties = array();
17
18
    /**
19
     * {@inheritDoc}
20
     */
21
    public function getClass()
22
    {
23
        return $this->class;
24
    }
25
26
    /**
27
     * Set Class
28
     *
29
     * @param string $class Class to hydrate
30
     */
31 3
    public function setClass($class)
32
    {
33 3
        $this->class = $class;
34 3
    }
35
36
    /**
37
     * Get Properties
38
     *
39
     * @return array
40
     */
41
    public function getProperties()
42
    {
43
        return $this->properties;
44
    }
45
46
    /**
47
     * {@inheritDoc}
48
     */
49 3
    public function getProperty($name): ?PropertyMetadata
50
    {
51 3
        foreach ($this->properties as $property) {
52 3
            if ($name === $property->getName() || $property->hasAlias($name)) {
53 3
                return $property;
54
            }
55
        }
56
        return null;
57
    }
58
59
    /**
60
     * Adds a property
61
     *
62
     * @param PropertyMetadata $property Property Metadata
63
     */
64 3
    public function addProperty(PropertyMetadata $property)
65
    {
66 3
        $this->properties[] = $property;
67 3
    }
68
}
69