Passed
Pull Request — master (#225)
by Rustam
02:46
created

MiddlewareFilter::filter()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 13
ccs 7
cts 7
cp 1
crap 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Router\Internal;
6
7
/**
8
 * @internal
9
 */
10
final class MiddlewareFilter
11
{
12
    /**
13
     * @param array[]|callable[]|string[] $middlewares
14
     * @return array[]|callable[]|string[]
15
     *
16
     * @psalm-param list<array|callable|string> $middlewares
17
     * @psalm-return list<array|callable|string>
18
     */
19 44
    public static function filter(array $middlewares, array $disabledMiddlewares): array
20
    {
21 44
        $result = [];
22
23 44
        foreach ($middlewares as $middleware) {
24 34
            if (in_array($middleware, $disabledMiddlewares, true)) {
25 10
                continue;
26
            }
27
28 34
            $result[] = $middleware;
29
        }
30
31 44
        return $result;
32
    }
33
}
34