PercentageWrappingParser::parse()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 16
ccs 0
cts 12
cp 0
rs 10
cc 4
nc 3
nop 1
crap 20
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Setono\VariableResolver\Parser;
6
7
use function Safe\preg_match_all;
8
use Setono\VariableResolver\Variable\Variable;
9
10
final class PercentageWrappingParser implements ParserInterface
11
{
12
    public function parse(string $str): array
13
    {
14
        preg_match_all('/%([A-Z_]+)%/', $str, $matches);
15
16
        if (!isset($matches[0]) || count($matches[0]) === 0) {
17
            return [];
18
        }
19
20
        $variables = [];
21
22
        foreach ($matches[0] as $key => $value) {
23
            $name = $matches[1][$key];
24
            $variables[] = new Variable($value, $name);
25
        }
26
27
        return $variables;
28
    }
29
}
30