Test Failed
Pull Request — master (#10)
by Yo
02:32
created

ScriptListNormalizer::denormalize()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 11
rs 9.4285
ccs 0
cts 0
cp 0
cc 3
eloc 6
nc 3
nop 1
crap 12
1
<?php
2
namespace Yoanm\ComposerConfigManager\Application\Serializer\Normalizer;
3
4
use Yoanm\ComposerConfigManager\Domain\Model\Script;
5
6
class ScriptListNormalizer implements DenormalizerInterface
7
{
8
    /**
9
     * @param Script[] $scriptList
10
     *
11
     * @return array
12
     */
13 2
    public function normalize(array $scriptList)
14
    {
15 2
        $normalizedList = [];
16 2
        foreach ($scriptList as $script) {
17 2
            $normalizedList[$script->getName()][] = $script->getCommand();
18 2
        }
19
20 2
        return $normalizedList;
21
    }
22
23
    /**
24
     * @param array $scriptList
25
     *
26
     * @return Script[]
27
     */
28
    public function denormalize(array $scriptList)
29
    {
30
        $denormalizedList = [];
31
        foreach ($scriptList as $scriptName => $scriptCommandList) {
32
            foreach ($scriptCommandList as $scriptCommand) {
33
                $denormalizedList[] = new Script($scriptName, $scriptCommand);
34
            }
35
        }
36
37
        return $denormalizedList;
38
    }
39
}
40