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

UserEntity::isNew()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Oc\User;
4
5
/**
6
 * Class UserEntity
7
 *
8
 * @package Oc\User
9
 */
10
class UserEntity
11
{
12
    /**
13
     * @var int
14
     */
15
    public $id;
16
17
    /**
18
     * @var string
19
     */
20
    public $username;
21
22
    /**
23
     * @var string
24
     */
25
    public $password;
26
27
    /**
28
     * @var string
29
     */
30
    public $email;
31
32
    /**
33
     * @var double
34
     */
35
    public $latitude;
36
37
    /**
38
     * @var double
39
     */
40
    public $longitude;
41
42
    /**
43
     * @var bool
44
     */
45
    public $isActive;
46
47
    /**
48
     * @var string
49
     */
50
    public $firstname;
51
52
    /**
53
     * @var string
54
     */
55
    public $lastname;
56
57
    /**
58
     * @var string
59
     */
60
    public $country;
61
62
    /**
63
     * @var string
64
     */
65
    public $language;
66
67
    /**
68
     * Checks if the entity is new.
69
     *
70
     * @return bool
71
     */
72
    public function isNew()
73
    {
74
        return $this->id === null;
75
    }
76
77
    /**
78
     * Sets all properties from array.
79
     *
80
     * @param array $data
81
     */
82
    public function fromArray(array $data)
83
    {
84
        foreach ($data as $key => $value) {
85
            if (!property_exists($this, $key)) {
86
                continue;
87
            }
88
89
            $this->{$key} = $value;
90
        }
91
    }
92
93
    /**
94
     * Returns all properties as array.
95
     *
96
     * @return array
97
     */
98
    public function toArray()
99
    {
100
        return get_object_vars($this);
101
    }
102
}
103