Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
5 / 5 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
CheckedMatcher | |
100.00% |
5 / 5 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
generateMatches | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
3 |
1 | <?php |
2 | /** |
3 | * @file |
4 | * @license https://opensource.org/licenses/Apache-2.0 Apache-2.0 |
5 | */ |
6 | |
7 | namespace Wikimedia\CSS\Grammar; |
8 | |
9 | use Wikimedia\CSS\Objects\ComponentValueList; |
10 | |
11 | /** |
12 | * Wrap another matcher in a callback to verify the matches |
13 | */ |
14 | class CheckedMatcher extends Matcher { |
15 | /** @var Matcher */ |
16 | private $matcher; |
17 | |
18 | /** @var callable */ |
19 | protected $check; |
20 | |
21 | /** |
22 | * @param Matcher $matcher Base matcher |
23 | * @param callable $check Function to check the match is really valid. |
24 | * Prototype is bool func( ComponentValueList $values, GrammarMatch $match, array $options ) |
25 | */ |
26 | public function __construct( Matcher $matcher, callable $check ) { |
27 | $this->matcher = $matcher; |
28 | $this->check = $check; |
29 | } |
30 | |
31 | /** @inheritDoc */ |
32 | protected function generateMatches( ComponentValueList $values, $start, array $options ) { |
33 | foreach ( $this->matcher->generateMatches( $values, $start, $options ) as $match ) { |
34 | if ( call_user_func( $this->check, $values, $match, $options ) ) { |
35 | yield $this->makeMatch( $values, $start, $match->getNext(), $match ); |
36 | } |
37 | } |
38 | } |
39 | } |