Test Setup Failed
Push — master ( b50703...9d91c5 )
by Dominik
06:16
created

PropertyAccessor   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 35 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 14
loc 40
c 0
b 0
f 0
wmc 3
lcom 1
cbo 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setValue() 7 7 1
A getValue() 7 7 1

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
    public function __construct(string $property)
18
    {
19
        $this->property = $property;
20
    }
21
22
    /**
23
     * @param object $object
24
     * @param mixed  $value
25
     */
26 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
        $reflectionProperty = new \ReflectionProperty(get_class($object), $this->property);
29
        $reflectionProperty->setAccessible(true);
30
31
        $reflectionProperty->setValue($object, $value);
32
    }
33
34
    /**
35
     * @param object $object
36
     *
37
     * @return mixed
38
     */
39 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...
40
    {
41
        $reflectionProperty = new \ReflectionProperty(get_class($object), $this->property);
42
        $reflectionProperty->setAccessible(true);
43
44
        return $reflectionProperty->getValue($object);
45
    }
46
}
47