ScriptHandler::buildParameters()   B
last analyzed

Complexity

Conditions 6
Paths 8

Size

Total Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 8.8497
c 0
b 0
f 0
cc 6
nc 8
nop 1
1
<?php
2
3
namespace Incenteev\ParameterHandler;
4
5
use Composer\Script\Event;
6
7
class ScriptHandler
8
{
9
    public static function buildParameters(Event $event)
10
    {
11
        $extras = $event->getComposer()->getPackage()->getExtra();
12
13
        if (!isset($extras['incenteev-parameters'])) {
14
            throw new \InvalidArgumentException('The parameter handler needs to be configured through the extra.incenteev-parameters setting.');
15
        }
16
17
        $configs = $extras['incenteev-parameters'];
18
19
        if (!is_array($configs)) {
20
            throw new \InvalidArgumentException('The extra.incenteev-parameters setting must be an array or a configuration object.');
21
        }
22
23
        if (array_keys($configs) !== range(0, count($configs) - 1)) {
24
            $configs = [$configs];
25
        }
26
27
        $processor = new Processor($event->getIO());
28
29
        foreach ($configs as $config) {
30
            if (!is_array($config)) {
31
                throw new \InvalidArgumentException('The extra.incenteev-parameters setting must be an array of configuration objects.');
32
            }
33
34
            $processor->processFile($config);
35
        }
36
    }
37
}
38