Completed
Branch master (7b4639)
by Johannes
13:16
created

LocateDefinedSymbolsFromExtensions::__invoke()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 18
rs 9.4286
cc 3
eloc 13
nc 4
nop 1
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
    public function __invoke(array $extensionNames) : array
17
    {
18
        $definedSymbols = [];
19
        foreach($extensionNames as $extensionName) {
20
            try{
21
                $extensionReflection = new \ReflectionExtension($extensionName);
22
                $definedSymbols = array_merge(
23
                    $definedSymbols,
24
                    array_keys($extensionReflection->getConstants()),
25
                    array_keys($extensionReflection->getFunctions()),
26
                    $extensionReflection->getClassNames()
27
                );
28
            } catch (\Exception $e) {
29
                throw new UnknownExtensionException($e->getMessage());
30
            }
31
        }
32
        return $definedSymbols;
33
    }
34
35
36
37
}