Passed
Push — master ( 80b57f...2460a5 )
by Yo
02:49
created

AuthorListNormalizer::normalize()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 13
cts 13
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 10
nc 5
nop 1
crap 4
1
<?php
2
namespace Yoanm\ComposerConfigManager\Application\Serializer\Normalizer;
3
4
use Yoanm\ComposerConfigManager\Domain\Model\Author;
5
6
class AuthorListNormalizer
7
{
8
    const KEY_NAME = 'name';
9
    const KEY_EMAIL = 'email';
10
    const KEY_ROLE = 'role';
11
    /**
12
     * @param Author[] $authorList
13
     *
14
     * @return array
15
     */
16 2
    public function normalize(array $authorList)
17
    {
18 2
        $normalizeList = [];
19 2
        foreach ($authorList as $author) {
20 2
            $normalizedAuthor = [self::KEY_NAME => $author->getName()];
21 2
            if ($author->getEmail()) {
22 2
                $normalizedAuthor[self::KEY_EMAIL] = $author->getEmail();
23 2
            }
24 2
            if ($author->getRole()) {
25 2
                $normalizedAuthor[self::KEY_ROLE] = $author->getRole();
26 2
            }
27 2
            $normalizeList[] = $normalizedAuthor;
28 2
        }
29
30 2
        return $normalizeList;
31
    }
32
}
33