Completed
Push — master ( 52046a...4ff8ff )
by Alexander
05:18
created

BreakFilter::removeMatching()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 3
nop 2
crap 3
1
<?php
2
/**
3
 * This file is part of the Code-Insight library.
4
 * For the full copyright and license information, please view
5
 * the LICENSE file that was distributed with this source code.
6
 *
7
 * @copyright Alexander Obuhovich <[email protected]>
8
 * @link      https://github.com/console-helpers/code-insight
9
 */
10
11
namespace ConsoleHelpers\CodeInsight\BackwardsCompatibility;
12
13
14
class BreakFilter
15
{
16
17
	/**
18
	 * Removes ignored BC breaks.
19
	 *
20
	 * @param array $bc_breaks BC breaks.
21
	 * @param array $rules     Rules.
22
	 *
23
	 * @return array
24
	 */
25 6
	public function removeMatching(array $bc_breaks, array $rules)
26
	{
27 6
		$ret = array();
28
29 6
		foreach ( $bc_breaks as $break_data ) {
30 6
			if ( !$this->isMatching($break_data, $rules) ) {
31 6
				$ret[] = $break_data;
32 6
			}
33 6
		}
34
35 6
		return $ret;
36
	}
37
38
	/**
39
	 * Determines if BC break is ignored.
40
	 *
41
	 * @param array $break_data Break data.
42
	 * @param array $rules      Rules.
43
	 *
44
	 * @return boolean
45
	 */
46 6
	protected function isMatching(array $break_data, array $rules)
47
	{
48 6
		if ( !$rules ) {
49 1
			return false;
50
		}
51
52 5
		foreach ( $rules as $rule_data ) {
53 5
			if ( isset($rule_data['type']) && $rule_data['type'] !== $break_data['type'] ) {
54 4
				continue;
55
			}
56
57 5
			if ( isset($rule_data['element']) && $rule_data['element'] !== $break_data['element'] ) {
58 4
				continue;
59
			}
60
61 5
			if ( isset($rule_data['old']) ) {
62 2
				if ( !isset($break_data['old']) || $rule_data['old'] !== $break_data['old'] ) {
63 2
					continue;
64
				}
65 2
			}
66
67 5
			if ( isset($rule_data['new']) ) {
68 2
				if ( !isset($break_data['new']) || $rule_data['new'] !== $break_data['new'] ) {
69 1
					continue;
70
				}
71 1
			}
72
73 4
			return true;
74 5
		}
75
76 5
		return false;
77
	}
78
79
}
80