DataProviderExtractor::getProvidedData()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 13
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 2
1
<?php declare(strict_types=1);
2
3
namespace HMoragrega\PhpSpec\DataProvider\Parser;
4
5
use PhpSpec\Loader\Node\ExampleNode;
6
7
class DataProviderExtractor
8
{
9
    /**
10
     * Extract the data from the data provider method
11
     *
12
     * @param ExampleNode $example
13
     * @param string $dataProviderMethod
14
     *
15
     * @return array
16
     *
17
     * @throws \ReflectionException
18
     */
19
    public function getProvidedData(ExampleNode $example, string $dataProviderMethod): array
20
    {
21
        $specification = $example->getSpecification()->getClassReflection();
22
        if (!$specification->hasMethod($dataProviderMethod)) {
23
            return [];
24
        }
25
26
        $subject      = $specification->newInstance();
27
        $providedData = $specification->getMethod($dataProviderMethod)->invoke($subject);
28
29
        return is_array($providedData)
30
            ? $providedData
31
            : [];
32
    }
33
}