Setting   A
last analyzed

Complexity

Total Complexity 18

Size/Duplication

Total Lines 244
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 4
Bugs 0 Features 2
Metric Value
wmc 18
c 4
b 0
f 2
lcom 1
cbo 0
dl 0
loc 244
rs 10

18 Methods

Rating   Name   Duplication   Size   Complexity  
A getId() 0 4 1
A setId() 0 4 1
A getValue() 0 4 1
A setValue() 0 4 1
A getType() 0 4 1
A setType() 0 4 1
A getProfile() 0 4 1
A setProfile() 0 4 1
A getDescription() 0 4 1
A setDescription() 0 4 1
A getName() 0 4 1
A setName() 0 4 1
A getSalt() 0 4 1
A setSalt() 0 4 1
A getSerializableData() 0 12 1
A __construct() 0 4 1
A getCreatedAt() 0 4 1
A setCreatedAt() 0 4 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(
35
     *  type="keyword",
36
     *  options={
37
     *    "fields"={
38
     *        "raw"={"type"="keyword", "index"="not_analyzed"},
39
     *        "name"={"type"="keyword"}
40
     *    }
41
     *  }
42
     * )
43
     */
44
    private $name;
45
46
    /**
47
     * @var string
48
     *
49
     * @ES\Property(type="text", options={"analyzer"="standard"})
50
     */
51
    private $description;
52
53
    /**
54
     * @var string
55
     *
56
     * @ES\Property(
57
     *  type="keyword",
58
     *  options={
59
     *    "fields"={
60
     *        "raw"={"type"="keyword", "index"="not_analyzed"},
61
     *        "profile"={"type"="keyword"}
62
     *    }
63
     *  }
64
     * )
65
     */
66
    private $profile = [];
67
68
    /**
69
     * @var string
70
     *
71
     * @ES\Property(type="keyword", options={"index"="not_analyzed"})
72
     */
73
    private $type;
74
75
    /**
76
     * @var string
77
     *
78
     * @ES\Property(type="keyword", options={"index"="not_analyzed"})
79
     */
80
    private $value;
81
82
    /**
83
     * @var string
84
     *
85
     * @ES\Property(type="keyword", options={"index"="not_analyzed"})
86
     */
87
    private $salt;
88
89
    /**
90
     * @var string
91
     *
92
     * @ES\Property(type="date")
93
     */
94
    private $createdAt;
95
96
    /**
97
     * Setting constructor.
98
     */
99
    public function __construct()
100
    {
101
        $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...
102
    }
103
104
    /**
105
     * @return string
106
     */
107
    public function getId()
108
    {
109
        return $this->id;
110
    }
111
112
    /**
113
     * @param string $id
114
     */
115
    public function setId($id)
116
    {
117
        $this->id = $id;
118
    }
119
120
    /**
121
     * @return string
122
     */
123
    public function getValue()
124
    {
125
        return $this->value;
126
    }
127
128
    /**
129
     * @param string $value
130
     */
131
    public function setValue($value)
132
    {
133
        $this->value = $value;
134
    }
135
136
    /**
137
     * Get type.
138
     *
139
     * @return string
140
     */
141
    public function getType()
142
    {
143
        return $this->type;
144
    }
145
146
    /**
147
     * Set type.
148
     *
149
     * @param string $type
150
     */
151
    public function setType($type)
152
    {
153
        $this->type = $type;
154
    }
155
156
    /**
157
     * Get profile.
158
     *
159
     * @return string|array
160
     */
161
    public function getProfile()
162
    {
163
        return $this->profile;
164
    }
165
166
    /**
167
     * Set profile.
168
     *
169
     * @param string|array $profile
170
     */
171
    public function setProfile($profile)
172
    {
173
        $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...
174
    }
175
176
    /**
177
     * Get description.
178
     *
179
     * @return string
180
     */
181
    public function getDescription()
182
    {
183
        return $this->description;
184
    }
185
186
    /**
187
     * Set description.
188
     *
189
     * @param string $description
190
     */
191
    public function setDescription($description)
192
    {
193
        $this->description = $description;
194
    }
195
196
    /**
197
     * Get name.
198
     *
199
     * @return string
200
     */
201
    public function getName()
202
    {
203
        return $this->name;
204
    }
205
206
    /**
207
     * Set name.
208
     *
209
     * @param string $name
210
     */
211
    public function setName($name)
212
    {
213
        $this->name = $name;
214
    }
215
216
    /**
217
     * @return string
218
     */
219
    public function getSalt()
220
    {
221
        return $this->salt;
222
    }
223
224
    /**
225
     * @param string $salt
226
     */
227
    public function setSalt($salt)
228
    {
229
        $this->salt = $salt;
230
    }
231
232
    /**
233
     * @return string
234
     */
235
    public function getCreatedAt()
236
    {
237
        return $this->createdAt;
238
    }
239
240
    /**
241
     * @param string $createdAt
242
     */
243
    public function setCreatedAt($createdAt)
244
    {
245
        $this->createdAt = $createdAt;
246
    }
247
248
    /**
249
     * Specify data which should be serialized to JSON.
250
     *
251
     * @return mixed Data which can be serialized by json_encode.
252
     */
253
    public function getSerializableData()
254
    {
255
        return [
256
            'id' => $this->getId(),
257
            'name' => $this->getName(),
258
            'description' => $this->getDescription(),
259
            'profile' => $this->getProfile(),
260
            'salt' => $this->getSalt(),
261
            'type' => $this->getType(),
262
            'value' => $this->getValue(),
263
        ];
264
    }
265
}
266