ExampleParser   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 9
dl 0
loc 25
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getDataProvider() 0 14 3
1
<?php declare(strict_types=1);
2
3
namespace HMoragrega\PhpSpec\DataProvider\Parser;
4
5
use PhpSpec\Loader\Node\ExampleNode;
6
7
class ExampleParser
8
{
9
    private const DATA_PROVIDER_REGEX = '/@dataProvider ([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)/';
10
11
    /**
12
     * Returns the data provider method looking for the @dataProvider annotation
13
     *
14
     * @param ExampleNode $example
15
     *
16
     * @return string|null
17
     */
18
    public function getDataProvider(ExampleNode $example): ?string
19
    {
20
        $method = $example->getFunctionReflection();
21
22
        $docComment = $method->getDocComment();
23
        if (!is_string($docComment)) {
24
            return null;
25
        }
26
27
        if (!preg_match(self::DATA_PROVIDER_REGEX, $docComment, $matches)) {
28
            return null;
29
        }
30
31
        return $matches[1];
32
    }
33
}
34