ContactListFactory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 48
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A parse() 0 4 1
A buildCollection() 0 19 3
A buildElement() 0 4 1
1
<?php
2
3
namespace Mailxpert\Model;
4
5
use Mailxpert\Exceptions\MailxpertSDKException;
6
7
/**
8
 * Date: 19/08/15
9
 */
10
class ContactListFactory extends Factory
11
{
12
    /**
13
     * @param mixed $data
14
     *
15
     * @return ContactList|ContactListCollection
16
     * @throws MailxpertSDKException
17
     */
18
    public static function parse($data)
19
    {
20
        return parent::parse($data);
21
    }
22
23
    /**
24
     * @param $data
25
     *
26
     * @return ContactListCollection
27
     */
28
    protected static function buildCollection($data)
29
    {
30
        $contactLists = new ContactListCollection();
31
32
        foreach ($data as $contactListData) {
33
            $contactList = static::buildElement($contactListData);
34
35
            if (!$contactLists->exists(
36
                function ($key, ContactList $element) use ($contactList) {
37
                    return $contactList->getId() == $element->getId();
38
                }
39
            )
40
            ) {
41
                $contactLists->add($contactList);
42
            }
43
        }
44
45
        return $contactLists;
46
    }
47
48
    /**
49
     * @param $data
50
     *
51
     * @return ContactList
52
     */
53
    protected static function buildElement($data)
54
    {
55
        return new ContactList($data['id'], $data['name'], $data['default']);
56
    }
57
}
58