ValueObjectTrait::equals()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 9
ccs 3
cts 4
cp 0.75
rs 9.6666
cc 2
eloc 4
nc 2
nop 1
crap 2.0625
1
<?php
2
3
namespace Wambo\Core\ValueObject;
4
5
use Wambo\Core\Immutable\ImmutableTrait;
6
use Wambo\Core\ValueObject\Exception\ValueObjectException;
7
8
/**
9
 * Class ValueObjectTrait
10
 *
11
 * @package Wambo\Core\ValueObject
12
 */
13
trait ValueObjectTrait
14
{
15
    use ImmutableTrait;
16
    /**
17
     * Disable clone function to prevent clone Value Objects
18
     */
19 1
    final public function __clone()
20
    {
21 1
        throw new ValueObjectException('ValueObjects are not cloneable');
22
    }
23
    /**
24
     * @param ValueObjectInterface $obj
25
     * @return bool
26
     */
27 3
    public function equals(ValueObjectInterface $obj)
28
    {
29 3
        if (get_called_class() !== get_class($obj)) {
30
            return false;
31
        }
32
33
        /** @var ValueObjectInterface $this */
34 3
        return $this->getValue() === $obj->getValue();
35
    }
36
}