CustomFieldFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
dl 43
loc 43
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A parse() 4 4 1
A buildCollection() 11 11 2
A buildElement() 7 7 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * Date: 21/08/15
4
 */
5
6
namespace Mailxpert\Model;
7
8
/**
9
 * Class CustomFieldFactory
10
 * @package Mailxpert\Model
11
 */
12 View Code Duplication
class CustomFieldFactory 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...
13
{
14
    /**
15
     * @param mixed $data
16
     *
17
     * @return CustomField|CustomFieldCollection
18
     * @throws \Mailxpert\Exceptions\MailxpertSDKException
19
     */
20
    public static function parse($data)
21
    {
22
        return parent::parse($data);
23
    }
24
25
    /**
26
     * @param $data
27
     *
28
     * @return CustomFieldCollection
29
     */
30
    protected static function buildCollection($data)
31
    {
32
        $customFields = new CustomFieldCollection();
33
34
        foreach ($data as $customFieldData) {
35
            $customField = static::buildElement($customFieldData);
36
            $customFields ->add($customField);
37
        }
38
39
        return $customFields;
40
    }
41
42
    /**
43
     * @param $data
44
     *
45
     * @return CustomField
46
     */
47
    protected static function buildElement($data)
48
    {
49
        $customField = new CustomField($data['alias'], $data['id']);
50
        $customField->fromAPI($data);
51
52
        return $customField;
53
    }
54
}
55