PropertyState::isSameAs()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 4
rs 10
1
<?php
2
declare(strict_types=1);
3
4
namespace Stratadox\EntityState;
5
6
/**
7
 * Represents the state of a property.
8
 *
9
 * @author Stratadox
10
 */
11
final class PropertyState implements RepresentsProperty
12
{
13
    private $name;
14
    private $value;
15
16
    private function __construct(string $name, $value)
17
    {
18
        $this->name = $name;
19
        $this->value = $value;
20
    }
21
22
    /**
23
     * Something something with.
24
     *
25
     * @param string $name
26
     * @param mixed  $value
27
     * @return RepresentsProperty
28
     */
29
    public static function with(string $name, $value): RepresentsProperty
30
    {
31
        return new self($name, $value);
32
    }
33
34
    /** @inheritdoc */
35
    public function name(): string
36
    {
37
        return $this->name;
38
    }
39
40
    /** @inheritdoc */
41
    public function value()
42
    {
43
        return $this->value;
44
    }
45
46
    /** @inheritdoc */
47
    public function isSameAs(RepresentsProperty $otherProperty): bool
48
    {
49
        return $this->name === $otherProperty->name()
50
            && $this->value === $otherProperty->value();
51
    }
52
53
    /** @inheritdoc */
54
    public function isDifferentInThe(ListsPropertyStates $otherProperties): bool
55
    {
56
        foreach ($otherProperties as $otherProperty) {
57
            if ($this->isSameAs($otherProperty)) {
58
                return false;
59
            }
60
        }
61
        return true;
62
    }
63
}
64