JoinFilter   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 13
c 1
b 0
f 0
dl 0
loc 27
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A filter() 0 20 6
1
<?php
2
/**
3
 * This file is part of the ArrayQuery package.
4
 *
5
 * (c) Mauro Cassani<https://github.com/mauretto78>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace ArrayQuery\Filters;
12
13
class JoinFilter extends AbstractFilter
14
{
15
    /**
16
     * @param array $results
17
     * @param null $joinArray
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $joinArray is correct as it would always require null to be passed?
Loading history...
18
     * @return array
19
     */
20
    public static function filter(array $results, $joinArray = null)
21
    {
22
        if ($joinArray) {
0 ignored issues
show
introduced by
$joinArray is of type null, thus it always evaluated to false.
Loading history...
23
            foreach ($joinArray as $join) {
24
                foreach ($results as $key => $result) {
25
                    $arrayToJoin = $join['array'];
26
                    $arrayName = $join['arrayName'];
27
                    $parentKey = $join['parentKey'];
28
                    $foreignKey = $join['foreignKey'];
29
30
                    if (array_key_exists($parentKey, $result) && $arrayToJoin[$foreignKey] === $result[$parentKey]) {
31
                        $results[$key][$arrayName] = $arrayToJoin;
32
                    } else {
33
                        unset($results[$key]);
34
                    }
35
                }
36
            }
37
        }
38
39
        return $results;
40
    }
41
}
42