Passed
Push — master ( be994a...680396 )
by Hilari
01:36
created

ExampleParser::getDataProvider()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 3
nop 1
dl 0
loc 14
rs 10
c 0
b 0
f 0
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 (false === $docComment) {
24
            return null;
25
        }
26
27
        if (!preg_match(self::DATA_PROVIDER_REGEX, $docComment, $matches)) {
0 ignored issues
show
Bug introduced by
It seems like $docComment can also be of type true; however, parameter $subject of preg_match() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

27
        if (!preg_match(self::DATA_PROVIDER_REGEX, /** @scrutinizer ignore-type */ $docComment, $matches)) {
Loading history...
28
            return null;
29
        }
30
31
        return $matches[1];
32
    }
33
}
34