TokenExtractor::extract()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 9
cts 9
cp 1
rs 9.7998
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 3
1
<?php
2
3
namespace DDDominio\EventSourcing\Versioning\JsonTransformer;
4
5
class TokenExtractor
6
{
7
    const TOKEN_DELIMITER_REGEX = '/[\.\[]/';
8
9 33
    public function extract($pathExpression)
10
    {
11 33
        $tokensRepresentation = preg_split(self::TOKEN_DELIMITER_REGEX, $pathExpression, -1, PREG_SPLIT_NO_EMPTY);
12 33
        $tokens = [];
13 33
        foreach ($tokensRepresentation as $tokenRepresentation) {
14 33
            if (preg_match('/(\d+)\]/', $tokenRepresentation, $matches)) {
15 7
                $arrayKey = intval($matches[1]);
16 7
                $tokens[] = new ArrayAccessToken($arrayKey);
17
            } else {
18 33
                $tokens[] = new ObjectAccessToken($tokenRepresentation);
19
            }
20
        }
21 33
        return $tokens;
22
    }
23
}
24