RegexNamedGroupsIterator::getIterator()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 11
cts 11
cp 1
rs 9.3554
c 0
b 0
f 0
cc 5
nc 5
nop 0
crap 5
1
<?php
2
/**
3
 * This file is part of Railt package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace Railt\Lexer\Iterator;
11
12
/**
13
 * An iterator which returns a list of regex named groups
14
 */
15
class RegexNamedGroupsIterator extends RegexIterator
16
{
17
    /**
18
     * @return \Traversable|\Generator|array[]
19
     * @throws \InvalidArgumentException
20
     * @throws \RuntimeException
21
     */
22 6
    public function getIterator(): \Traversable
23
    {
24 6
        foreach (parent::getIterator() as $result) {
25 6
            $context = [];
26
27 6
            foreach (\array_reverse($result) as $index => $body) {
28 6
                if (! \is_string($index)) {
29 6
                    $context[] = $body;
30 6
                    continue;
31
                }
32
33 6
                if ($body !== '') {
34 6
                    yield $index => \array_reverse($context);
35 6
                    continue 2;
36
                }
37
            }
38
        }
39 6
    }
40
}
41