BacktraceIgnoreMatcher   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 23
rs 10
wmc 6

3 Methods

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