Code Duplication    Length = 125-125 lines in 2 locations

htdocs/src/Oc/Country/CountryEntity.php 1 location

@@ 10-134 (lines=125) @@
7
 *
8
 * @package Oc\Country
9
 */
10
class CountryEntity
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 properties from the database.
69
     *
70
     * @return array
71
     */
72
    public function toDatabaseArray()
73
    {
74
        return [
75
            'short' => $this->short,
76
            'name' => $this->name,
77
            'de' => $this->de,
78
            'en' => $this->en,
79
            'trans_id' => $this->translationId,
80
            'list_default_de' => $this->listDefaultDe,
81
            'list_default_en' => $this->listDefaultEn,
82
            'sort_de' => $this->sortDe,
83
            'sort_en' => $this->sortEn
84
        ];
85
    }
86
87
    /**
88
     * Prepares database array from properties.
89
     *
90
     * @param array $data
91
     *
92
     * @return self
93
     */
94
    public function fromDatabaseArray(array $data)
95
    {
96
        $this->short = (string) $data['short'];
97
        $this->name = (string) $data['name'];
98
        $this->de = (string) $data['de'];
99
        $this->en = (string) $data['en'];
100
        $this->translationId = (int) $data['trans_id'];
101
        $this->listDefaultDe = (bool) $data['list_default_de'];
102
        $this->listDefaultEn = (bool) $data['list_default_en'];
103
        $this->sortDe = (string) $data['sort_de'];
104
        $this->sortEn = (string) $data['sort_en'];
105
106
        return $this;
107
    }
108
109
    /**
110
     * Sets all properties from array.
111
     *
112
     * @param array $data
113
     */
114
    public function fromArray(array $data)
115
    {
116
        foreach ($data as $key => $value) {
117
            if (!property_exists($this, $key)) {
118
                continue;
119
            }
120
121
            $this->{$key} = $value;
122
        }
123
    }
124
125
    /**
126
     * Returns all properties as array.
127
     *
128
     * @return array
129
     */
130
    public function toArray()
131
    {
132
        return get_object_vars($this);
133
    }
134
}
135

htdocs/src/Oc/Language/LanguageEntity.php 1 location

@@ 10-134 (lines=125) @@
7
 *
8
 * @package Oc\Language
9
 */
10
class LanguageEntity
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 $nativeName;
26
27
    /**
28
     * @var string
29
     */
30
    public $de;
31
32
    /**
33
     * @var string
34
     */
35
    public $en;
36
37
    /**
38
     * @var int
39
     */
40
    public $translationId;
41
42
    /**
43
     * @var bool
44
     */
45
    public $listDefaultDe;
46
47
    /**
48
     * @var bool
49
     */
50
    public $listDefaultEn;
51
52
    /**
53
     * @var bool
54
     */
55
    public $isTranslated;
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 properties from the database.
69
     *
70
     * @return array
71
     */
72
    public function toDatabaseArray()
73
    {
74
        return [
75
            'short' => $this->short,
76
            'name' => $this->name,
77
            'native_name' => $this->nativeName,
78
            'de' => $this->de,
79
            'en' => $this->en,
80
            'trans_id' => $this->translationId,
81
            'list_default_de' => $this->listDefaultDe,
82
            'list_default_en' => $this->listDefaultEn,
83
            'is_translated' => $this->isTranslated
84
        ];
85
    }
86
87
    /**
88
     * Prepares database array from properties.
89
     *
90
     * @param array $data
91
     *
92
     * @return self
93
     */
94
    public function fromDatabaseArray(array $data)
95
    {
96
        $this->short = (string) strtolower($data['short']);
97
        $this->name = (string) $data['name'];
98
        $this->nativeName = (string) $data['native_name'];
99
        $this->de = (string) $data['de'];
100
        $this->en = (string) $data['en'];
101
        $this->translationId = (int) $data['trans_id'];
102
        $this->listDefaultDe = (bool) $data['list_default_de'];
103
        $this->listDefaultEn = (bool) $data['list_default_en'];
104
        $this->isTranslated = (bool) $data['is_translated'];
105
106
        return $this;
107
    }
108
109
    /**
110
     * Sets all properties from array.
111
     *
112
     * @param array $data
113
     */
114
    public function fromArray(array $data)
115
    {
116
        foreach ($data as $key => $value) {
117
            if (!property_exists($this, $key)) {
118
                continue;
119
            }
120
121
            $this->{$key} = $value;
122
        }
123
    }
124
125
    /**
126
     * Returns all properties as array.
127
     *
128
     * @return array
129
     */
130
    public function toArray()
131
    {
132
        return get_object_vars($this);
133
    }
134
}
135