GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

PropertyAccessor   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 73
Duplicated Lines 27.4 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 20
loc 73
c 0
b 0
f 0
wmc 6
lcom 1
cbo 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getValue() 10 10 1
A setValue() 10 10 1
A validateObject() 0 9 2
A validateProperty() 0 10 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
namespace Isolate\UnitOfWork\Object;
4
5
use Isolate\UnitOfWork\Exception\InvalidArgumentException;
6
use Isolate\UnitOfWork\Exception\NotExistingPropertyException;
7
8
/**
9
 * @api
10
 */
11
final class PropertyAccessor
12
{
13
    /**
14
     * @param $object
15
     * @param $propertyName
16
     * @return mixed
17
     * @throws InvalidArgumentException
18
     * @throws NotExistingPropertyException
19
     * 
20
     * @api
21
     */
22 View Code Duplication
    public function getValue($object, $propertyName)
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...
23
    {
24
        $this->validateObject($object);
25
        $reflection = new \ReflectionClass($object);
26
        $this->validateProperty($reflection, $object, $propertyName);
27
        $property = $reflection->getProperty($propertyName);
28
        $property->setAccessible(true);
29
30
        return $property->getValue($object);
31
    }
32
33
    /**
34
     * @param $object
35
     * @param $propertyName
36
     * @param $value
37
     * @throws InvalidArgumentException
38
     * @throws NotExistingPropertyException
39
     * 
40
     * @api
41
     */
42 View Code Duplication
    public function setValue($object, $propertyName, $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...
43
    {
44
        $this->validateObject($object);
45
        $reflection = new \ReflectionClass($object);
46
        $this->validateProperty($reflection, $object, $propertyName);
47
        $property = $reflection->getProperty($propertyName);
48
        $property->setAccessible(true);
49
50
        $property->setValue($object, $value);
51
    }
52
53
    /**
54
     * @param $value
55
     * @throws InvalidArgumentException
56
     */
57
    private function validateObject($value)
58
    {
59
        if (!is_object($value)) {
60
            throw new InvalidArgumentException(sprintf(
61
                "PropertyAccessor require object to access property, \"%s\" passed.",
62
                gettype($value)
63
            ));
64
        }
65
    }
66
67
    /**
68
     * @param \ReflectionClass $reflection
69
     * @param $object
70
     * @param $propertyName
71
     * @throws NotExistingPropertyException
72
     */
73
    private function validateProperty(\ReflectionClass $reflection, $object, $propertyName)
74
    {
75
        if (!$reflection->hasProperty($propertyName)) {
76
            throw new NotExistingPropertyException(sprintf(
77
                "Property \"%s\" does not exists in \"%s\" class.",
78
                $propertyName,
79
                get_class($object)
80
            ));
81
        }
82
    }
83
}
84