ContactFactory::buildElement()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 7
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 7
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Date: 20/08/15
4
 */
5
6
namespace Mailxpert\Model;
7
8
use Mailxpert\Exceptions\MailxpertSDKException;
9
10
/**
11
 * Class ContactFactory
12
 * @package Mailxpert\Model
13
 */
14 View Code Duplication
class ContactFactory extends Factory
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
15
{
16
    /**
17
     * @param mixed $data
18
     *
19
     * @return Contact|ContactCollection
20
     * @throws MailxpertSDKException
21
     */
22
    public static function parse($data)
23
    {
24
        return parent::parse($data);
25
    }
26
27
    /**
28
     * @param $data
29
     *
30
     * @return ContactCollection
31
     */
32
    protected static function buildCollection($data)
33
    {
34
        $contacts = new ContactCollection();
35
36
        foreach ($data as $contactData) {
37
            $contact = static::buildElement($contactData);
38
            $contacts->add($contact);
39
        }
40
41
        return $contacts;
42
    }
43
44
    /**
45
     * @param $data
46
     *
47
     * @return Contact
48
     */
49
    protected static function buildElement($data)
50
    {
51
        $contact = new Contact($data['email'], $data['id']);
52
        $contact->fromAPI($data);
53
54
        return $contact;
55
    }
56
}
57