Completed
Push — master ( 6d3173...686ecf )
by Guillermo A.
09:20
created

AbstractEntity::getUpdatedAt()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Guillermoandrae\Highrise\Entities;
4
5
use DateTime;
6
use SimpleXMLElement;
7
8
abstract class AbstractEntity implements EntityInterface
9
{
10
    /**
11
     * @var SimpleXMLElement
12
     */
13
    protected $xml;
14
15
    /**
16
     * The entity ID.
17
     *
18
     * @var int
19
     */
20
    protected $id;
21
22
    /**
23
     * The entity name.
24
     *
25
     * @var string
26
     */
27
    protected $name;
28
29
    /**
30
     * The date on which the entity was created.
31
     *
32
     * @var DateTime
33
     */
34
    protected $createdAt;
35
36
    /**
37
     * The date on which the entity was updated.
38
     *
39
     * @var DateTime
40
     */
41
    protected $updatedAt;
42
43
    public function __construct(string $xml)
44
    {
45
        $this->xml = simplexml_load_string($xml);
0 ignored issues
show
Documentation Bug introduced by
It seems like simplexml_load_string($xml) can also be of type false. However, the property $xml is declared as type SimpleXMLElement. 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...
46
        $this->id = (int) $this->xml->xpath('//id');
47
        $this->name = (string) $this->xml->xpath('//name')[0];
48
        $this->createdAt = new DateTime((string) $this->xml->xpath('//created-at')[0]);
49
        $this->updatedAt = new DateTime((string) $this->xml->xpath('//updated-at')[0]);
50
    }
51
52
    /**
53
     * Returns the SimpleXMLElement.
54
     *
55
     * @return SimpleXMLElement
56
     */
57
    final public function getXml(): SimpleXMLElement
58
    {
59
        return $this->xml;
60
    }
61
62
    /**
63
     * Returns the entity ID.
64
     *
65
     * @return int
66
     */
67
    public function getId(): int
68
    {
69
        return $this->id;
70
    }
71
72
    /**
73
     * Returns the entity name;
74
     *
75
     * @return string
76
     */
77
    public function getName(): string
78
    {
79
        return $this->name;
80
    }
81
82
    /**
83
     * Returns the date on which the entity was created.
84
     *
85
     * @return DateTime
86
     */
87
    public function getCreatedAt(): DateTime
88
    {
89
        return $this->createdAt;
90
    }
91
92
    /**
93
     * Returns the date on which the entity was updated.
94
     *
95
     * @return DateTime
96
     */
97
    public function getUpdatedAt(): DateTime
98
    {
99
        return $this->updatedAt;
100
    }
101
}
102