Completed
Pull Request — master (#1)
by
unknown
13:02
created

ActivityLoggerViewDocument::setEntityId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Sulu\Bundle\ElasticsearchActivityLogBundle\Document;
4
5
use JMS\Serializer\Annotation\Exclude;
6
use ONGR\ElasticsearchBundle\Annotation\Document;
7
use ONGR\ElasticsearchBundle\Annotation\Id;
8
use ONGR\ElasticsearchBundle\Annotation\Property;
9
use Ramsey\Uuid\Uuid;
10
use Sulu\Component\ActivityLog\Model\ActivityLogInterface;
11
use Symfony\Component\Security\Core\User\UserInterface;
12
13
/**
14
 * Indexable document for activity logs.
15
 *
16
 * @Document(type="sulu_activity_log")
17
 */
18
class ActivityLoggerViewDocument implements ActivityLogInterface
19
{
20
    /**
21
     * @var string
22
     *
23
     * @Id
24
     */
25
    protected $uuid;
26
27
    /**
28
     * @var string
29
     *
30
     * @Property(
31
     *     type="keyword",
32
     *     options={
33
     *         "fields":{
34
     *            "raw":{"type":"keyword"}
35
     *         }
36
     *     }
37
     * )
38
     */
39
    protected $type;
40
41
    /**
42
     * @var string
43
     *
44
     * @Property(
45
     *     type="keyword",
46
     *     options={
47
     *         "fields":{
48
     *            "raw":{"type":"keyword"}
49
     *         }
50
     *     }
51
     * )
52
     */
53
    protected $title;
54
55
    /**
56
     * @var string
57
     *
58
     * @Property(
59
     *     type="keyword",
60
     *     options={
61
     *         "fields":{
62
     *            "raw":{"type":"keyword"}
63
     *         }
64
     *     }
65
     * )
66
     */
67
    protected $message;
68
69
    /**
70
     * @var array
71
     */
72
    protected $data;
73
74
    /**
75
     * @var string
76
     *
77
     * @Property(
78
     *     type="keyword",
79
     *     name="dataString",
80
     *     options={
81
     *         "fields":{
82
     *            "raw":{"type":"keyword"}
83
     *         }
84
     *     }
85
     * )
86
     *
87
     * @Exclude
88
     */
89
    protected $dataString;
90
91
    /**
92
     * @var \DateTime
93
     *
94
     * @Property(
95
     *     type="date",
96
     *     options={
97
     *         "fields":{
98
     *            "raw":{"type":"keyword"}
99
     *         }
100
     *     }
101
     * )
102
     */
103
    protected $created;
104
105
    /**
106
     * @var UserObject
107
     *
108
     * @Property(
109
     *     type="integer",
110
     *     name="creatorId",
111
     *     options={
112
     *         "fields":{
113
     *            "raw":{"type":"integer"}
114
     *         }
115
     *     }
116
     * )
117
     */
118
    protected $creatorId;
119
120
    /**
121
     * @var ActivityLogInterface
122
     */
123
    protected $parent;
124
125
    /**
126
     * @var string
127
     *
128
     * @Property(
129
     *     type="keyword",
130
     *     name="parentUuid",
131
     *     options={
132
     *         "fields":{
133
     *            "raw":{"type":"keyword"}
134
     *         }
135
     *     }
136
     * )
137
     */
138
    protected $parentUuid;
139
140
    /**
141
     * @var UserInterface
142
     */
143
    protected $creator;
144
145
    /**
146
     * @var string
147
     *
148
     * @Property(
149
     *     type="keyword",
150
     *     name="entityId",
151
     *     options={
152
     *         "fields":{
153
     *            "raw":{"type":"keyword"}
154
     *         }
155
     *     }
156
     * )
157
     */
158
    protected $entityId;
159
160
    /**
161
     * @param string $type
162
     * @param string $uuid
163
     */
164
    public function __construct($type = null, $uuid = null)
165
    {
166
        $this->type = $type;
167
        $this->uuid = $uuid ?: Uuid::uuid4()->toString();
168
    }
169
170
    /**
171
     * {@inheritdoc}
172
     */
173
    public function getUuid()
174
    {
175
        return $this->uuid;
176
    }
177
178
    /**
179
     * Set uuid.
180
     *
181
     * @param string $uuid
182
     *
183
     * @return $this
184
     */
185
    public function setUuid($uuid)
186
    {
187
        $this->uuid = $uuid;
188
189
        return $this;
190
    }
191
192
    /**
193
     * {@inheritdoc}
194
     */
195
    public function getType()
196
    {
197
        return $this->type;
198
    }
199
200
    /**
201
     * Set type.
202
     *
203
     * @param string $type
204
     *
205
     * @return $this
206
     */
207
    public function setType($type)
208
    {
209
        $this->type = $type;
210
211
        return $this;
212
    }
213
214
    /**
215
     * {@inheritdoc}
216
     */
217
    public function getTitle()
218
    {
219
        return $this->title;
220
    }
221
222
    /**
223
     * {@inheritdoc}
224
     */
225
    public function setTitle($title)
226
    {
227
        $this->title = $title;
228
229
        return $this;
230
    }
231
232
    /**
233
     * {@inheritdoc}
234
     */
235
    public function getMessage()
236
    {
237
        return $this->message;
238
    }
239
240
    /**
241
     * {@inheritdoc}
242
     */
243
    public function setMessage($message)
244
    {
245
        $this->message = $message;
246
247
        return $this;
248
    }
249
250
    /**
251
     * {@inheritdoc}
252
     */
253
    public function getData()
254
    {
255
        return $this->data;
256
    }
257
258
    /**
259
     * {@inheritdoc}
260
     */
261
    public function setData($data)
262
    {
263
        $this->data = $data;
0 ignored issues
show
Documentation Bug introduced by
It seems like $data can also be of type string. However, the property $data is declared as type array. 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...
264
        $this->dataString = serialize($data);
265
        $this->entityId = array_key_exists('id', $data) ? $data['id'] : null;
266
267
        return $this;
268
    }
269
270
    /**
271
     * Returns data-string.
272
     *
273
     * @return string
274
     */
275
    public function getDataString()
276
    {
277
        return $this->dataString;
278
    }
279
280
    /**
281
     * Set data-string.
282
     *
283
     * @param string $dataString
284
     *
285
     * @return $this
286
     */
287
    public function setDataString($dataString)
288
    {
289
        $this->dataString = $dataString;
290
        $this->data = unserialize($dataString);
291
292
        return $this;
293
    }
294
295
    /**
296
     * {@inheritdoc}
297
     */
298
    public function getParent()
299
    {
300
        return $this->parent;
301
    }
302
303
    /**
304
     * {@inheritdoc}
305
     */
306
    public function setParent(ActivityLogInterface $parent = null)
307
    {
308
        $this->parent = $parent;
309
310
        $this->parentUuid = null;
311
        if ($parent) {
312
            $this->parentUuid = $parent->getUuid();
313
        }
314
315
        return $this;
316
    }
317
318
    /**
319
     * Returns parentUuid.
320
     *
321
     * @return string
322
     */
323
    public function getParentUuid()
324
    {
325
        return $this->parentUuid;
326
    }
327
328
    /**
329
     * Set parentUuid.
330
     *
331
     * @param string $parentUuid
332
     *
333
     * @return $this
334
     */
335
    public function setParentUuid($parentUuid)
336
    {
337
        $this->parentUuid = $parentUuid;
338
339
        return $this;
340
    }
341
342
    /**
343
     * {@inheritdoc}
344
     */
345
    public function getCreated()
346
    {
347
        return $this->created;
348
    }
349
350
    /**
351
     * {@inheritdoc}
352
     */
353
    public function setCreated(\DateTime $created)
354
    {
355
        $this->created = $created;
356
357
        return $this;
358
    }
359
360
    /**
361
     * Returns createdBy.
362
     *
363
     * @return UserObject
364
     */
365
    public function getCreatorId()
366
    {
367
        return $this->creatorId;
368
    }
369
370
    /**
371
     * Set createdBy.
372
     *
373
     * @param UserObject $creatorId
374
     *
375
     * @return $this
376
     */
377
    public function setCreatorId($creatorId)
378
    {
379
        $this->creatorId = $creatorId;
380
381
        return $this;
382
    }
383
384
    /**
385
     * {@inheritdoc}
386
     */
387
    public function getCreator()
388
    {
389
        return $this->creator;
390
    }
391
392
    /**
393
     * {@inheritdoc}
394
     */
395
    public function setCreator(UserInterface $creator = null)
396
    {
397
        $this->creator = $creator;
398
399
        $this->creatorId = null;
400
        if ($creator) {
401
            $this->creatorId = $creator->getId();
0 ignored issues
show
Bug introduced by
The method getId() does not seem to exist on object<Symfony\Component...ore\User\UserInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
402
        }
403
404
        return $this;
405
    }
406
407
    /**
408
     * Returns entityId.
409
     *
410
     * @return string
411
     */
412
    public function getEntityId()
413
    {
414
        return $this->entityId;
415
    }
416
417
    /**
418
     * Set entityId.
419
     *
420
     * @param string $entityId
421
     *
422
     * @return $this
423
     */
424
    public function setEntityId($entityId)
425
    {
426
        $this->entityId = $entityId;
427
428
        return $this;
429
    }
430
}
431