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.

PHPUnitValueComparer::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace Isolate\UnitOfWork\Entity\Property;
4
5
use Isolate\UnitOfWork\Object\PropertyAccessor;
6
use Isolate\UnitOfWork\Entity\Definition\Property;
7
use Isolate\UnitOfWork\Exception\InvalidArgumentException;
8
use SebastianBergmann\Comparator\ComparisonFailure;
9
use SebastianBergmann\Comparator\Factory;
10
11
final class PHPUnitValueComparer implements ValueComparer
12
{
13
    /**
14
     * @var PropertyAccessor
15
     */
16
    private $propertyAccessor;
17
18
    /**
19
     * @var Factory
20
     */
21
    private $comparatorFactory;
22
    
23
    public function __construct()
24
    {
25
        $this->comparatorFactory = new Factory();
26
        $this->propertyAccessor = new PropertyAccessor();
27
    }
28
29
    /**
30
     * @param Property $property
31
     * @param $firstObject
32
     * @param $secondObject
33
     * @return bool
34
     * @throws InvalidArgumentException
35
     */
36
    public function hasDifferentValue(Property $property, $firstObject, $secondObject)
37
    {
38
        $this->validaObjects($firstObject, $secondObject);
39
40
        $firstValue = $this->propertyAccessor->getValue($firstObject, $property->getName());
41
        $secondValue = $this->propertyAccessor->getValue($secondObject, $property->getName());
42
43
        
44
        $comparator = $this->comparatorFactory->getComparatorFor($firstValue, $secondValue);
45
46
        try {
47
            $comparator->assertEquals($firstValue, $secondValue);
48
            return false;
49
        } catch (ComparisonFailure $exception) {
50
            return true;   
51
        }
52
    }
53
54
    /**
55
     * @param $firstObject
56
     * @param $secondObject
57
     * @throws InvalidArgumentException
58
     */
59 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...
60
    {
61
        if (!is_object($firstObject) || !is_object($secondObject)) {
62
            throw new InvalidArgumentException("Compared values need to be a valid objects.");
63
        }
64
65
        if (get_class($firstObject) !== get_class($secondObject)) {
66
            throw new InvalidArgumentException("Compared values need to be an instances of the same class.");
67
        }
68
    }
69
}
70