Completed
Pull Request — master (#170)
by Simonas
04:25
created

Setting::setCreatedAt()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the ONGR package.
5
 *
6
 * (c) NFQ Technologies UAB <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ONGR\SettingsBundle\Document;
13
14
use ONGR\ElasticsearchBundle\Annotation as ES;
15
use ONGR\FilterManagerBundle\SerializableInterface;
16
17
/**
18
 * Stores admin settings.
19
 *
20
 * @ES\Document(type="setting")
21
 */
22
class Setting implements SerializableInterface
23
{
24
    /**
25
     * @var string
26
     *
27
     * @ES\Id()
28
     */
29
    private $id;
30
31
    /**
32
     * @var string
33
     *
34
     * @ES\Property(type="string", options={"analyzer"="standard"})
35
     */
36
    private $name;
37
38
    /**
39
     * @var string
40
     *
41
     * @ES\Property(type="string", options={"analyzer"="standard"})
42
     */
43
    private $description;
44
45
    /**
46
     * @var string
47
     *
48
     * @ES\Property(type="string", options={"analyzer"="standard"})
49
     */
50
    private $profile = [];
51
52
    /**
53
     * @var string
54
     *
55
     * @ES\Property(type="string", options={"analyzer"="standard"})
56
     */
57
    private $type;
58
59
    /**
60
     * @var string
61
     *
62
     * @ES\Property(type="string", options={"index"="not_analyzed"})
63
     */
64
    private $value;
65
66
    /**
67
     * @var string
68
     *
69
     * @ES\Property(type="string", options={"index"="not_analyzed"})
70
     */
71
    private $salt;
72
73
    /**
74
     * @var string
75
     *
76
     * @ES\Property(type="date")
77
     */
78
    private $createdAt;
79
80
    /**
81
     * Setting constructor.
82
     */
83
    public function __construct()
84
    {
85
        $this->createdAt = new \DateTime();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \DateTime() of type object<DateTime> is incompatible with the declared type string of property $createdAt.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
86
    }
87
88
    /**
89
     * @return string
90
     */
91
    public function getId()
92
    {
93
        return $this->id;
94
    }
95
96
    /**
97
     * @param string $id
98
     */
99
    public function setId($id)
100
    {
101
        $this->id = $id;
102
    }
103
104
    /**
105
     * @return string
106
     */
107
    public function getValue()
108
    {
109
        return $this->value;
110
    }
111
112
    /**
113
     * @param string $value
114
     */
115
    public function setValue($value)
116
    {
117
        $this->value = $value;
118
    }
119
120
    /**
121
     * Get type.
122
     *
123
     * @return string
124
     */
125
    public function getType()
126
    {
127
        return $this->type;
128
    }
129
130
    /**
131
     * Set type.
132
     *
133
     * @param string $type
134
     */
135
    public function setType($type)
136
    {
137
        $this->type = $type;
138
    }
139
140
    /**
141
     * Get profile.
142
     *
143
     * @return string|array
144
     */
145
    public function getProfile()
146
    {
147
        return $this->profile;
148
    }
149
150
    /**
151
     * Set profile.
152
     *
153
     * @param string|array $profile
154
     */
155
    public function setProfile($profile)
156
    {
157
        $this->profile = $profile;
0 ignored issues
show
Documentation Bug introduced by
It seems like $profile can also be of type array. However, the property $profile is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
158
    }
159
160
    /**
161
     * Get description.
162
     *
163
     * @return string
164
     */
165
    public function getDescription()
166
    {
167
        return $this->description;
168
    }
169
170
    /**
171
     * Set description.
172
     *
173
     * @param string $description
174
     */
175
    public function setDescription($description)
176
    {
177
        $this->description = $description;
178
    }
179
180
    /**
181
     * Get name.
182
     *
183
     * @return string
184
     */
185
    public function getName()
186
    {
187
        return $this->name;
188
    }
189
190
    /**
191
     * Set name.
192
     *
193
     * @param string $name
194
     */
195
    public function setName($name)
196
    {
197
        $this->name = $name;
198
    }
199
200
    /**
201
     * @return string
202
     */
203
    public function getSalt()
204
    {
205
        return $this->salt;
206
    }
207
208
    /**
209
     * @param string $salt
210
     */
211
    public function setSalt($salt)
212
    {
213
        $this->salt = $salt;
214
    }
215
216
    /**
217
     * @return string
218
     */
219
    public function getCreatedAt()
220
    {
221
        return $this->createdAt;
222
    }
223
224
    /**
225
     * @param string $createdAt
226
     */
227
    public function setCreatedAt($createdAt)
228
    {
229
        $this->createdAt = $createdAt;
230
    }
231
232
    /**
233
     * Specify data which should be serialized to JSON.
234
     *
235
     * @return mixed Data which can be serialized by json_encode.
236
     */
237
    public function getSerializableData()
238
    {
239
        return [
240
            'id' => $this->getId(),
241
            'name' => $this->getName(),
242
            'description' => $this->getDescription(),
243
            'profile' => $this->getProfile(),
244
            'type' => $this->getType(),
245
            'value' => $this->getValue(),
246
        ];
247
    }
248
}
249