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

MiddlewareFilter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 22
ccs 7
cts 7
cp 1
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A filter() 0 13 3
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