Completed
Push — master ( 53cbf4...c4dd08 )
by Matthias
04:10
created

LocateDefinedSymbolsFromExtensions::__invoke()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3.0052

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 18
ccs 11
cts 12
cp 0.9167
rs 9.4285
cc 3
eloc 13
nc 4
nop 1
crap 3.0052
1
<?php
2
3
namespace ComposerRequireChecker\DefinedSymbolsLocator;
4
5
6
use ComposerRequireChecker\Exception\UnknownExtensionException;
7
8
class LocateDefinedSymbolsFromExtensions
9
{
10
11
    /**
12
     * @param string[] $extensionNames
13
     * @return string[]
14
     * @throws UnknownExtensionException if the extension cannot be found
15
     */
16 8
    public function __invoke(array $extensionNames) : array
17
    {
18 8
        $definedSymbols = [];
19 8
        foreach($extensionNames as $extensionName) {
20
            try{
21 8
                $extensionReflection = new \ReflectionExtension($extensionName);
22 7
                $definedSymbols = array_merge(
23
                    $definedSymbols,
24 7
                    array_keys($extensionReflection->getConstants()),
25 7
                    array_keys($extensionReflection->getFunctions()),
26 7
                    $extensionReflection->getClassNames()
27
                );
28 1
            } catch (\Exception $e) {
29 1
                throw new UnknownExtensionException($e->getMessage());
30
            }
31
        }
32 7
        return $definedSymbols;
33
    }
34
35
36
37
}