Passed
Pull Request — master (#47)
by
unknown
11:29
created

FilterPass   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 6
c 0
b 0
f 0
dl 0
loc 17
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A process() 0 11 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace hanneskod\readmetester\Compiler\Pass;
6
7
use hanneskod\readmetester\Compiler\CompilerPassInterface;
8
use hanneskod\readmetester\Example\ArrayExampleStore;
9
use hanneskod\readmetester\Example\ExampleStoreInterface;
10
use hanneskod\readmetester\Utils\Regexp;
11
12
/**
13
 * Filter examples based on names
14
 */
15
final class FilterPass implements CompilerPassInterface
16
{
17
    public function __construct(
18
        private Regexp $filter,
19
    ) {}
20
21
    public function process(ExampleStoreInterface $store): ExampleStoreInterface
22
    {
23
        $examples = [];
24
25
        foreach ($store->getExamples() as $example) {
26
            if ($this->filter->matches($example->getName()->getFullName())) {
27
                $examples[] = $example;
28
            }
29
        }
30
31
        return new ArrayExampleStore($examples);
32
    }
33
}
34