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

AuthorListNormalizer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 27
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A normalize() 0 16 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