DiffableEntityTrait::diff()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Equip\Data\Traits;
4
5
/**
6
 * Intended to be used by classes implementing Equip\Data\EntityInterface that
7
 * also need to implement Equip\Data\DiffableInterface.
8
 */
9
trait DiffableEntityTrait /* implements DiffableInterface */
10
{
11
    /**
12
     * @see \Equip\Data\EntityInterface::withData()
13
     *
14
     * @param array $data
15
     *
16
     * @return static
17
     */
18
    abstract public function withData(array $data);
19
20
    /**
21
     * @see \Equip\Data\ArraySerializableInterface::toArray()
22
     *
23
     * @return array
24
     */
25
    abstract public function toArray();
26
27
    /**
28
     * @param array $values
29
     *
30
     * @return array
31
     */
32 1
    public function diff(array $values)
33
    {
34 1
        $copy = $this->withData($values);
35 1
        return array_diff_assoc($copy->toArray(), $this->toArray());
36
    }
37
}
38