BreakFilter::isMatching()   C
last analyzed

Complexity

Conditions 13
Paths 11

Size

Total Lines 31
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 13

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 13
eloc 15
c 1
b 0
f 0
nc 11
nop 2
dl 0
loc 31
ccs 16
cts 16
cp 1
crap 13
rs 6.6166

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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