Completed
Push — master ( fdd157...c7fad4 )
by Wachter
15:08
created

ActivityLoggerViewDocument::setCreator()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

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