DiffableEntityTrait   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 2
Metric Value
wmc 1
c 3
b 0
f 2
lcom 0
cbo 0
dl 0
loc 29
ccs 3
cts 3
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
withData() 0 1 ?
toArray() 0 1 ?
A diff() 0 5 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