DataProviderExtractor   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A getProvidedData() 0 13 3
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
}