BreakFilter   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
c 1
b 0
f 0
dl 0
loc 63
ccs 22
cts 22
cp 1
rs 10
wmc 16

2 Methods

Rating   Name   Duplication   Size   Complexity  
A removeMatching() 0 11 3
C isMatching() 0 31 13
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
			}
33
		}
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 ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $rules of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
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
			}
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
			}
72
73 4
			return true;
74
		}
75
76 5
		return false;
77
	}
78
79
}
80