Passed
Push — master ( bace86...bb4cad )
by Dmitriy
05:30 queued 02:57
created

BacktraceIgnoreMatcher   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 25
rs 10
c 1
b 0
f 0
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isIgnoredByFile() 0 8 2
A isIgnoredByClass() 0 3 2
A doesStringMatchPattern() 0 8 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Debug\Helper;
6
7
/**
8
 * All backtrace parameters should contain at least 4 elements in the following order:
9
 * 0 – Called method
10
 * 1 – Proxy
11
 * 2 – Real using place / Composer\ClassLoader include function
12
 * 3 – Whatever / Composer\ClassLoader
13
 */
14
final class BacktraceIgnoreMatcher
15
{
16
    public static function isIgnoredByFile(array $backtrace, array $patterns): bool
17
    {
18
        if (!isset($backtrace[2])) {
19
            return false;
20
        }
21
        $path = $backtrace[2]['file'];
22
23
        return self::doesStringMatchPattern($path, $patterns);
24
    }
25
26
    public static function isIgnoredByClass(array $backtrace, array $classes): bool
27
    {
28
        return isset($backtrace[3]['class']) && in_array($backtrace[3]['class'], $classes, true);
29
    }
30
31
    public static function doesStringMatchPattern(string $string, array $patterns): bool
32
    {
33
        foreach ($patterns as $ignoredPathPattern) {
34
            if (preg_match($ignoredPathPattern, $string) > 0) {
35
                return true;
36
            }
37
        }
38
        return false;
39
    }
40
}
41