Completed
Pull Request — master (#170)
by Simonas
03:06
created

Setting::getSerializableData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 11
rs 9.4285
cc 1
eloc 8
nc 1
nop 0
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
     * @const TYPE_STRING setting model of string type
33
     */
34
    const TYPE_STRING = 'string';
35
36
    /**
37
     * @const TYPE_ARRAY setting model of array type
38
     */
39
    const TYPE_ARRAY = 'array';
40
41
    /**
42
     * @const TYPE_BOOLEAN setting model of boolean type
43
     */
44
    const TYPE_BOOLEAN = 'bool';
45
46
    /**
47
     * @const TYPE_OBJECT setting model of object type
48
     */
49
    const TYPE_OBJECT = 'yaml';
50
51
    /**
52
     * @var string
53
     *
54
     * @ES\Property(type="string", options={"analyzer"="standard"})
55
     */
56
    private $name;
57
58
    /**
59
     * @var string
60
     *
61
     * @ES\Property(type="string", options={"analyzer"="standard"})
62
     */
63
    private $description;
64
65
    /**
66
     * @var string
67
     *
68
     * @ES\Property(type="string", options={"analyzer"="standard"})
69
     */
70
    private $profile;
71
72
    /**
73
     * @var string
74
     *
75
     * @ES\Property(type="string", options={"analyzer"="standard"})
76
     */
77
    private $type;
78
79
    /**
80
     * @var string
81
     *
82
     * @ES\Property(type="string", options={"index"="not_analyzed"})
83
     */
84
    private $value;
85
86
    /**
87
     * @var string
88
     *
89
     * @ES\Property(type="string", options={"index"="not_analyzed"})
90
     */
91
    private $salt;
92
93
    /**
94
     * @return string
95
     */
96
    public function getId()
97
    {
98
        return $this->id;
99
    }
100
101
    /**
102
     * @param string $id
103
     */
104
    public function setId($id)
105
    {
106
        $this->id = $id;
107
    }
108
109
    /**
110
     * @return string
111
     */
112
    public function getValue()
113
    {
114
        return $this->value;
115
    }
116
117
    /**
118
     * @param string $value
119
     */
120
    public function setValue($value)
121
    {
122
        $this->value = $value;
123
    }
124
125
    /**
126
     * Get type.
127
     *
128
     * @return string
129
     */
130
    public function getType()
131
    {
132
        return $this->type;
133
    }
134
135
    /**
136
     * Set type.
137
     *
138
     * @param string $type
139
     */
140
    public function setType($type)
141
    {
142
        $this->type = $type;
143
    }
144
145
    /**
146
     * Get profile.
147
     *
148
     * @return string|array
149
     */
150
    public function getProfile()
151
    {
152
        return $this->profile;
153
    }
154
155
    /**
156
     * Set profile.
157
     *
158
     * @param string|array $profile
159
     */
160
    public function setProfile($profile)
161
    {
162
        $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...
163
    }
164
165
    /**
166
     * Get description.
167
     *
168
     * @return string
169
     */
170
    public function getDescription()
171
    {
172
        return $this->description;
173
    }
174
175
    /**
176
     * Set description.
177
     *
178
     * @param string $description
179
     */
180
    public function setDescription($description)
181
    {
182
        $this->description = $description;
183
    }
184
185
    /**
186
     * Get name.
187
     *
188
     * @return string
189
     */
190
    public function getName()
191
    {
192
        return $this->name;
193
    }
194
195
    /**
196
     * Set name.
197
     *
198
     * @param string $name
199
     */
200
    public function setName($name)
201
    {
202
        $this->name = $name;
203
    }
204
205
    /**
206
     * @return string
207
     */
208
    public function getSalt()
209
    {
210
        return $this->salt;
211
    }
212
213
    /**
214
     * @param string $salt
215
     */
216
    public function setSalt($salt)
217
    {
218
        $this->salt = $salt;
219
    }
220
221
    /**
222
     * Specify data which should be serialized to JSON.
223
     *
224
     * @return mixed Data which can be serialized by json_encode.
225
     */
226
    public function getSerializableData()
227
    {
228
        return [
229
            'id' => $this->getId(),
230
            'name' => $this->getName(),
231
            'description' => $this->getDescription(),
232
            'profile' => $this->getProfile(),
233
            'type' => $this->getType(),
234
            'value' => $this->getValue(),
235
        ];
236
    }
237
}
238