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.

PropertyCloner::validaObjects()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
dl 10
loc 10
c 0
b 0
f 0
rs 9.2
cc 4
eloc 5
nc 3
nop 2
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
class PropertyCloner
12
{
13
    /**
14
     * @var PropertyAccessor
15
     */
16
    private $propertyAccessor;
17
18
    public function __construct()
19
    {
20
        $this->propertyAccessor = new PropertyAccessor();
21
    }
22
23
    /**
24
     * @param $target
25
     * @param $source
26
     * 
27
     * @api
28
     */
29
    public function cloneProperties($target, $source)
30
    {
31
        $this->validaObjects($target, $source);
32
33
        $reflection = new \ReflectionClass($target);
34
        foreach ($reflection->getProperties() as $property) {
35
36
            $this->propertyAccessor->setValue(
37
                $target,
38
                $property->getName(),
39
                $this->propertyAccessor->getValue($source, $property->getName())
40
            );
41
        }
42
    }
43
44
    /**
45
     * @param $target
46
     * @param $source
47
     * @param $propertyName
48
     * @throws InvalidArgumentException
49
     * @throws NotExistingPropertyException
50
     * 
51
     * @api
52
     */
53
    public function cloneProperty($target, $source, $propertyName)
54
    {
55
        $this->validaObjects($target, $source);
56
57
        $reflection = new \ReflectionClass($target);
58
        if (!$reflection->hasProperty($propertyName)) {
59
            throw new NotExistingPropertyException();
60
        }
61
62
        $this->propertyAccessor->setValue(
63
            $target,
64
            $propertyName,
65
            $this->propertyAccessor->getValue($source, $propertyName)
66
        );
67
    }
68
69
    /**
70
     * @param $firstObject
71
     * @param $secondObject
72
     * @throws InvalidArgumentException
73
     */
74 View Code Duplication
    private function validaObjects($firstObject, $secondObject)
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...
75
    {
76
        if (!is_object($firstObject) || !is_object($secondObject)) {
77
            throw new InvalidArgumentException("Compared values need to be a valid objects.");
78
        }
79
80
        if (get_class($firstObject) !== get_class($secondObject)) {
81
            throw new InvalidArgumentException("Compared values need to be an instances of the same class.");
82
        }
83
    }
84
}
85