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

AuthorListNormalizer::denormalize()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 13
rs 9.2
ccs 0
cts 0
cp 0
cc 4
eloc 8
nc 2
nop 1
crap 20
1
<?php
2
namespace Yoanm\ComposerConfigManager\Application\Serializer\Normalizer;
3
4
use Yoanm\ComposerConfigManager\Domain\Model\Author;
5
6
class AuthorListNormalizer implements DenormalizerInterface
7
{
8
    const KEY_NAME = 'name';
9
    const KEY_EMAIL = 'email';
10
    const KEY_ROLE = 'role';
11
12
    /**
13
     * @param Author[] $authorList
14
     *
15
     * @return array
16 2
     */
17
    public function normalize(array $authorList)
18 2
    {
19 2
        $normalizedList = [];
20 2
        foreach ($authorList as $author) {
21 2
            $normalizedAuthor = [self::KEY_NAME => $author->getName()];
22 2
            if ($author->getEmail()) {
23 2
                $normalizedAuthor[self::KEY_EMAIL] = $author->getEmail();
24 2
            }
25 2
            if ($author->getRole()) {
26 2
                $normalizedAuthor[self::KEY_ROLE] = $author->getRole();
27 2
            }
28 2
            $normalizedList[] = $normalizedAuthor;
29
        }
30 2
31
        return $normalizedList;
32
    }
33
34
    /**
35
     * @param array $authorList
36
     *
37
     * @return Author[]
38
     */
39
    public function denormalize(array $authorList)
40
    {
41
        $normalizedList = [];
42
        foreach ($authorList as $authorData) {
43
            $normalizedList[] = new Author(
44
                $authorData[self::KEY_NAME],
45
                $authorData[self::KEY_EMAIL] ? $authorData[self::KEY_EMAIL] : null,
46
                $authorData[self::KEY_ROLE] ? $authorData[self::KEY_ROLE] : null
47
            );
48
        }
49
50
        return $normalizedList;
51
    }
52
}
53