Regex   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 37.5%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 15
ccs 3
cts 8
cp 0.375
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A matchesAny() 0 11 4
1
<?php
2
/**
3
 * Utility class for some useful directory operations
4
 *
5
 * @author matias
6
 */
7
8
namespace Columnis\Utils;
9
10
class Regex
11
{
12
13 4
    public static function matchesAny($str, Array $expressions = null)
14
    {
15 4
        if (count($expressions) > 0) {
16
            foreach ($expressions as $expression) {
0 ignored issues
show
Bug introduced by
The expression $expressions of type null|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
17
                if (preg_match($expression, $str) > 0) {
18
                    return true;
19
                }
20
            }
21
        }
22 4
        return false;
23
    }
24
}