Passed
Push — master ( 3d52a7...3a32e2 )
by Edward
02:11
created

ReferenceFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 14
ccs 7
cts 7
cp 1
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A createReference() 0 11 3
1
<?php
2
declare(strict_types=1);
3
4
namespace Remorhaz\JSON\Pointer\Locator;
5
6
use function intval;
7
use function preg_match;
8
9
final class ReferenceFactory implements ReferenceFactoryInterface
10
{
11
12 8
    public function createReference(string $text): ReferenceInterface
13
    {
14 8
        if ('-' == $text) {
15 1
            return new NextIndexReference;
16
        }
17
18 7
        $isIndex = 1 === preg_match('/^(?:0|[1-9][0-9]*)$/', $text);
19
20 7
        return $isIndex
21 3
            ? new IndexReference(intval($text))
22 7
            : new PropertyReference($text);
23
    }
24
}
25