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.

ValueObject::equals()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 9
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 16
ccs 10
cts 10
cp 1
crap 2
rs 9.9666
1
<?php
2
3
declare(strict_types=1);
4
5
6
namespace DBUnt1tled\VO\VObjects;
7
8
use DBUnt1tled\VO\Exception\InvalidVOArgumentException;
9
10
abstract class ValueObject implements ValueObjectInterface
11
{
12
    /** @var mixed */
13
    protected $value;
14
15
    /**
16
     * ValueObject constructor.
17
     * @param $value
18
     * @throws \ReflectionException
19
     */
20 41
    public function __construct($value)
21
    {
22 41
        $this->guard($value);
23 35
        $this->value = $value;
24 35
    }
25
26
    /**
27
     * @return mixed
28
     */
29 32
    public function getValue()
30
    {
31 32
        return $this->value;
32
    }
33
34
    /**
35
     * @return string
36
     */
37 2
    public function __toString(): string
38
    {
39 2
        if (is_scalar($this->value)) {
40 1
            return (string)$this->value;
41
        }
42 1
        return (string)json_encode($this->value, 320);
43
    }
44
45
    /**
46
     * @param \DBUnt1tled\VO\VObjects\ValueObjectInterface $other
47
     * @return bool
48
     */
49 4
    public function equals(ValueObjectInterface $other): bool
50
    {
51 4
        if (get_class($this) !== get_class($other)) {
52 1
            throw new InvalidVOArgumentException(
53 1
                sprintf(
54 1
                    'A Value Object of type %s can not be compared to another of type %s',
55 1
                    get_class($this),
56 1
                    get_class($other)
57
                ),
58
                [
59 1
                    'original' => $this,
60 1
                    'destination' => $other
61
                ]
62
            );
63
        }
64 3
        return $this->getValue() === $other->getValue();
65
    }
66
67
    /**
68
     * @param mixed $value
69
     * @param mixed ...$other
70
     * @throws \ReflectionException
71
     */
72 40
    public function guard($value, ...$other): void
73
    {
74 40
        if ($value === null) {
75 1
            throw new InvalidVOArgumentException(sprintf('%s cannot be empty.', $this->getReflection()->getShortName()), $this->value);
76
        }
77 40
    }
78
79
    /**
80
     * @return \ReflectionClass
81
     * @throws \ReflectionException
82
     */
83 2
    protected function getReflection(): \ReflectionClass
84
    {
85 2
        return new \ReflectionClass(static::class);
86
    }
87
}
88