Message::getRecordedDate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
3
namespace WZRD\Messaging;
4
5
use ArrayIterator;
6
use DateTime;
7
use WZRD\Contracts\Messaging\Message as MessageContract;
8
9
abstract class Message implements MessageContract
10
{
11
    /**
12
     * Get message id.
13
     *
14
     * @return string
15
     */
16
    public function getId()
17
    {
18
        if (empty($this->id)) {
19
            $this->id = uniqid();
0 ignored issues
show
Bug introduced by
The property id does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
20
        }
21
22
        return $this->id;
23
    }
24
25
    /**
26
     * Get payload.
27
     *
28
     * @return array
29
     */
30
    public function getPayload()
31
    {
32
        $iterator = new ArrayIterator(array_filter((array) $this, function ($k) {
33
            return $k != 'id' && $k != 'recorded_date';
34
        }, ARRAY_FILTER_USE_KEY));
35
36
        return (array) $iterator;
37
    }
38
39
    /**
40
     * Get the recorded date.
41
     *
42
     * @return Datetime
43
     */
44
    public function getRecordedDate()
45
    {
46
        if (empty($this->recorded_date)) {
47
            $this->recorded_date = new DateTime();
0 ignored issues
show
Bug introduced by
The property recorded_date does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
48
        }
49
50
        return $this->recorded_date;
51
    }
52
53
    /**
54
     * Get the message name (e.g. the type).
55
     *
56
     * @return string
57
     */
58
    public function getName()
59
    {
60
        return get_class($this);
61
    }
62
}
63