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

PropertyAccessor   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 50.94 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 27
loc 53
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setValue() 13 13 2
A getValue() 14 14 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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