Passed
Push — main ( ec6948...9b9c4a )
by Michael
04:01
created

ValueObject::equals()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MichaelRubel\ValueObjects;
6
7
class ValueObject
8
{
9
    /**
10
     * Convenient method to create a value object statically.
11
     *
12
     * @param  mixed  $values
13
     *
14
     * @return static
15
     */
16 19
    public static function make(...$values): static
17
    {
18 19
        return new static(...$values);
0 ignored issues
show
Unused Code introduced by
The call to MichaelRubel\ValueObject...ueObject::__construct() has too many arguments starting with $values. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

18
        return /** @scrutinizer ignore-call */ new static(...$values);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
19
    }
20
21
    /**
22
     * @param  string  $name
23
     * @param mixed $value
24
     *
25
     * @return void
26
     */
27 4
    public function __set(string $name, mixed $value): void
28
    {
29 4
        throw new \InvalidArgumentException('Value objects are immutable. You cannot modify properties. Create a new object instead.');
30
    }
31
32
    /**
33
     * Check if objects are instances of same class
34
     * and share the same properties and values.
35
     *
36
     * @param  ValueObject  $object
37
     *
38
     * @return bool
39
     */
40 1
    public function equals(ValueObject $object): bool
41
    {
42 1
        return $this == $object;
43
    }
44
}
45