Passed
Push — master ( a4571b...162929 )
by Chris
07:18
created

AbstractCollectionComparator::stripDuplicates()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
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
0 ignored issues
show
Unused Code introduced by
The parameter $array1 is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

33
    protected function whatEvenIsThis(/** @scrutinizer ignore-unused */ array $array1, array $array2): array

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $array2 is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

33
    protected function whatEvenIsThis(array $array1, /** @scrutinizer ignore-unused */ array $array2): array

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
34
    {
35
        throw new LogicException('No!');
36
37
        /*
38
         if both primary and secondary are empty this will return false
39
         because the "array_diff" family of functions returns an empty array
40
         if the first array provided is empty itself. if both arrays are
41
         empty this will return an empty array as there is no difference.
42
         */
43
        return !empty($array1)
0 ignored issues
show
Unused Code introduced by
return ! empty($array1) ...>diff($array2, $array1) is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
44
            ? $this->diff($array1, $array2)
45
            : $this->diff($array2, $array1);
46
    }
47
}
48