Passed
Push — master ( 162929...df6b58 )
by Chris
07:31
created

AbstractCollectionComparator::diff()   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 2
crap 1
1
<?php
2
3
namespace WebTheory\Collection\Comparison\Abstracts;
4
5
use LogicException;
6
use WebTheory\Collection\Contracts\CollectionComparatorInterface;
7
8
abstract class AbstractCollectionComparator implements CollectionComparatorInterface
9
{
10 45
    public function diff(array $array, array $values): array
11
    {
12 45
        return array_udiff($array, $values, $this->getComparisonFunction());
13
    }
14
15 27
    public function contrast(array $array1, array $array2): array
16
    {
17 27
        return array_merge(
18 27
            $this->diff($array1, $array2),
19 27
            $this->diff($array2, $array1),
20
        );
21
    }
22
23 21
    public function intersect($array, $values): array
24
    {
25 21
        return array_uintersect($array, $values, $this->getComparisonFunction());
26
    }
27
28 6
    public function matches(array $array1, array $array2): bool
29
    {
30 6
        return empty($this->contrast($array1, $array2));
31
    }
32
33
    protected function whatEvenIsThis(array $array1, array $array2): array
34
    {
35
        /*
36
         if both primary and secondary are empty this will return false
37
         because the "array_diff" family of functions returns an empty array
38
         if the first array provided is empty itself. if both arrays are
39
         empty this will return an empty array as there is no difference.
40
         */
41
        return !empty($array1)
42
            ? $this->diff($array1, $array2)
43
            : $this->diff($array2, $array1);
44
    }
45
}
46