Completed
Push — master ( 5bf305...2d7c2d )
by Dominik
01:49
created

PropertyAccessor::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chubbyphp\Deserialization\Accessor;
6
7
final class PropertyAccessor implements AccessorInterface
8
{
9
    /**
10
     * @var string
11
     */
12
    private $property;
13
14
    /**
15
     * @param string $property
16
     */
17 4
    public function __construct(string $property)
18
    {
19 4
        $this->property = $property;
20 4
    }
21
22
    /**
23
     * @param object $object
24
     * @param mixed  $value
25
     */
26 2 View Code Duplication
    public function setValue($object, $value)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
27
    {
28 2
        $class = get_class($object);
29
30
        try {
31 2
            $reflectionProperty = new \ReflectionProperty($class, $this->property);
32 1
        } catch (\ReflectionException $e) {
33 1
            throw AccessorException::createMissingProperty($class, $this->property);
34
        }
35
36 1
        $reflectionProperty->setAccessible(true);
37 1
        $reflectionProperty->setValue($object, $value);
38 1
    }
39
40
    /**
41
     * @param object $object
42
     *
43
     * @return mixed
44
     */
45 2 View Code Duplication
    public function getValue($object)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
46
    {
47 2
        $class = get_class($object);
48
49
        try {
50 2
            $reflectionProperty = new \ReflectionProperty($class, $this->property);
51 1
        } catch (\ReflectionException $e) {
52 1
            throw AccessorException::createMissingProperty($class, $this->property);
53
        }
54
55 1
        $reflectionProperty->setAccessible(true);
56
57 1
        return $reflectionProperty->getValue($object);
58
    }
59
}
60