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

CountryEntity::fromArray()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 1
dl 10
loc 10
rs 9.4285
c 0
b 0
f 0
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