ScriptListNormalizer::denormalize()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 3
nop 1
crap 3
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 1
    public function denormalize(array $scriptList)
29
    {
30 1
        $denormalizedList = [];
31 1
        foreach ($scriptList as $scriptName => $scriptCommandList) {
32 1
            foreach ($scriptCommandList as $scriptCommand) {
33 1
                $denormalizedList[] = new Script($scriptName, $scriptCommand);
34 1
            }
35 1
        }
36
37 1
        return $denormalizedList;
38
    }
39
}
40