Completed
Push — master ( c3efa2...a812ec )
by Guilherme
13s
created

SubjectIdentifier::getUpdatedAt()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of the login-cidadao project or it's bundles.
4
 *
5
 * (c) Guilherme Donato <guilhermednt on github>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace LoginCidadao\OpenIDBundle\Entity;
12
13
use Doctrine\ORM\Mapping as ORM;
14
use LoginCidadao\CoreBundle\Model\PersonInterface;
15
use LoginCidadao\OAuthBundle\Model\ClientInterface;
16
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
17
18
/**
19
 * @ORM\Entity(repositoryClass="LoginCidadao\OpenIDBundle\Entity\SubjectIdentifierRepository")
20
 * @UniqueEntity({"client", "person"})
21
 * @ORM\HasLifecycleCallbacks
22
 * @ORM\Table(name="subject_identifier")
23
 */
24
class SubjectIdentifier
25
{
26
    /**
27
     * @ORM\Id
28
     * @ORM\Column(type="integer")
29
     * @ORM\GeneratedValue(strategy="AUTO")
30
     */
31
    protected $id;
32
33
    /**
34
     * @var PersonInterface
35
     * @ORM\ManyToOne(targetEntity="LoginCidadao\CoreBundle\Entity\Person")
36
     * @ORM\JoinColumn(name="person_id", referencedColumnName="id", nullable=false)
37
     */
38
    private $person;
39
40
    /**
41
     * @var ClientInterface
42
     * @ORM\ManyToOne(targetEntity="LoginCidadao\OAuthBundle\Entity\Client", inversedBy="authorizations")
43
     * @ORM\JoinColumn(name="client_id", referencedColumnName="id", nullable=false)
44
     */
45
    private $client;
46
47
    /**
48
     * @var mixed
49
     * @ORM\Column(name="subject_identifier", type="string", nullable=false)
50
     */
51
    private $subjectIdentifier;
52
53
    /**
54
     * @var \DateTime
55
     * @ORM\Column(name="created_at", type="datetime")
56
     */
57
    private $createdAt;
58
59
    /**
60
     * @var \DateTime
61
     * @ORM\Column(name="updated_at", type="datetime")
62
     */
63
    private $updatedAt;
64
65
    /**
66
     * @return mixed
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use PersonInterface.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
67
     */
68
    public function getPerson()
69
    {
70
        return $this->person;
71
    }
72
73
    /**
74
     * @param mixed $person
0 ignored issues
show
Documentation introduced by
Consider making the type for parameter $person a bit more specific; maybe use PersonInterface.
Loading history...
75
     * @return SubjectIdentifier
76
     */
77
    public function setPerson(PersonInterface $person)
78
    {
79
        $this->person = $person;
80
81
        return $this;
82
    }
83
84
    /**
85
     * @return ClientInterface
86
     */
87
    public function getClient()
88
    {
89
        return $this->client;
90
    }
91
92
    /**
93
     * @param ClientInterface $client
94
     * @return SubjectIdentifier
95
     */
96
    public function setClient(ClientInterface $client)
97
    {
98
        $this->client = $client;
99
100
        return $this;
101
    }
102
103
    /**
104
     * @return mixed
105
     */
106
    public function getSubjectIdentifier()
107
    {
108
        return $this->subjectIdentifier;
109
    }
110
111
    /**
112
     * @param mixed $subjectIdentifier
113
     * @return SubjectIdentifier
114
     */
115
    public function setSubjectIdentifier($subjectIdentifier)
116
    {
117
        $this->subjectIdentifier = $subjectIdentifier;
118
119
        return $this;
120
    }
121
122
    /**
123
     * @return mixed
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use \DateTime.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
124
     */
125
    public function getCreatedAt()
126
    {
127
        return $this->createdAt;
128
    }
129
130
    /**
131
     * @ORM\PrePersist()
132
     * @param mixed $createdAt
133
     * @return SubjectIdentifier
134
     */
135
    public function setCreatedAt($createdAt = null)
136
    {
137
        if ($createdAt instanceof \DateTime) {
138
            $this->createdAt = $createdAt;
139
        } else {
140
            $this->createdAt = \DateTime::createFromFormat('U', time());
0 ignored issues
show
Documentation Bug introduced by
It seems like \DateTime::createFromFormat('U', time()) can also be of type false. However, the property $createdAt is declared as type object<DateTime>. 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...
141
        }
142
143
        return $this;
144
    }
145
146
    /**
147
     * @return \DateTime
148
     */
149
    public function getUpdatedAt()
150
    {
151
        return $this->updatedAt;
152
    }
153
154
    /**
155
     * @ORM\PrePersist()
156
     * @ORM\PreUpdate()
157
     * @param \DateTime $updatedAt
0 ignored issues
show
Documentation introduced by
Should the type for parameter $updatedAt not be \DateTime|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
158
     * @return SubjectIdentifier
159
     */
160
    public function setUpdatedAt($updatedAt = null)
161
    {
162
        if ($updatedAt instanceof \DateTime) {
163
            $this->updatedAt = $updatedAt;
164
        } else {
165
            $this->updatedAt = \DateTime::createFromFormat('U', time());
0 ignored issues
show
Documentation Bug introduced by
It seems like \DateTime::createFromFormat('U', time()) can also be of type false. However, the property $updatedAt is declared as type object<DateTime>. 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...
166
        }
167
168
        return $this;
169
    }
170
}
171