Completed
Pull Request — development (#546)
by Nick
06:25
created

CountryEntity   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 83
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 83
loc 83
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isNew() 4 4 1
A fromArray() 10 10 3
A toArray() 4 4 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
namespace Oc\Country;
4
5
/**
6
 * Class CountryEntity
7
 *
8
 * @package Oc\Country
9
 */
10 View Code Duplication
class CountryEntity
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...
11
{
12
    /**
13
     * @var string
14
     */
15
    public $short;
16
17
    /**
18
     * @var string
19
     */
20
    public $name;
21
22
    /**
23
     * @var string
24
     */
25
    public $de;
26
27
    /**
28
     * @var string
29
     */
30
    public $en;
31
32
    /**
33
     * @var int
34
     */
35
    public $translationId;
36
37
    /**
38
     * @var bool
39
     */
40
    public $listDefaultDe;
41
42
    /**
43
     * @var bool
44
     */
45
    public $listDefaultEn;
46
47
    /**
48
     * @var string
49
     */
50
    public $sortDe;
51
52
    /**
53
     * @var string
54
     */
55
    public $sortEn;
56
57
    /**
58
     * Checks if the entity is new.
59
     *
60
     * @return bool
61
     */
62
    public function isNew()
63
    {
64
        return $this->short === null;
65
    }
66
67
    /**
68
     * Sets all properties from array.
69
     *
70
     * @param array $data
71
     */
72
    public function fromArray(array $data)
73
    {
74
        foreach ($data as $key => $value) {
75
            if (!property_exists($this, $key)) {
76
                continue;
77
            }
78
79
            $this->{$key} = $value;
80
        }
81
    }
82
83
    /**
84
     * Returns all properties as array.
85
     *
86
     * @return array
87
     */
88
    public function toArray()
89
    {
90
        return get_object_vars($this);
91
    }
92
}
93