Issues (3627)

app/bundles/ApiBundle/Entity/oAuth2/AuthCode.php (1 issue)

1
<?php
2
3
/*
4
 * @copyright   2014 Mautic Contributors. All rights reserved
5
 * @author      Mautic
6
 *
7
 * @link        http://mautic.org
8
 *
9
 * @license     GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
10
 */
11
12
namespace Mautic\ApiBundle\Entity\oAuth2;
13
14
use Doctrine\ORM\Mapping as ORM;
15
use FOS\OAuthServerBundle\Model\AuthCode as BaseAuthCode;
16
use FOS\OAuthServerBundle\Model\ClientInterface;
17
use Mautic\CoreBundle\Doctrine\Mapping\ClassMetadataBuilder;
18
use Symfony\Component\Security\Core\User\UserInterface;
19
20
/**
21
 * Class AuthCode.
22
 */
23
class AuthCode extends BaseAuthCode
24
{
25
    /**
26
     * @var int
27
     */
28
    protected $id;
29
30
    /**
31
     * @var Client
32
     */
33
    protected $client;
34
35
    /**
36
     * @var \Mautic\UserBundle\Entity\User
37
     */
38
    protected $user;
39
40
    /**
41
     * @var string
42
     */
43
    protected $token;
44
45
    /**
46
     * @var int
47
     */
48
    protected $expiresAt;
49
50
    /**
51
     * @var string
52
     */
53
    protected $scope;
54
55
    /**
56
     * @var string
57
     */
58
    protected $redirectUri;
59
60
    public static function loadMetadata(ORM\ClassMetadata $metadata)
61
    {
62
        $builder = new ClassMetadataBuilder($metadata);
63
64
        $builder->setTable('oauth2_authcodes');
65
66
        $builder->createField('id', 'integer')
67
            ->isPrimaryKey()
68
            ->generatedValue()
69
            ->build();
70
71
        $builder->createManyToOne('client', 'Client')
72
            ->addJoinColumn('client_id', 'id', false, false, 'CASCADE')
73
            ->build();
74
75
        $builder->createManyToOne('user', 'Mautic\UserBundle\Entity\User')
76
            ->addJoinColumn('user_id', 'id', false, false, 'CASCADE')
77
            ->build();
78
79
        $builder->createField('token', 'string')
80
            ->unique()
81
            ->build();
82
83
        $builder->createField('expiresAt', 'bigint')
84
            ->columnName('expires_at')
85
            ->nullable()
86
            ->build();
87
88
        $builder->createField('scope', 'string')
89
            ->nullable()
90
            ->build();
91
92
        $builder->createField('redirectUri', 'text')
93
            ->columnName('redirect_uri')
94
            ->build();
95
    }
96
97
    /**
98
     * Get id.
99
     *
100
     * @return int
101
     */
102
    public function getId()
103
    {
104
        return $this->id;
105
    }
106
107
    /**
108
     * Set client.
109
     *
110
     * @return RefreshToken
111
     */
112
    public function setClient(ClientInterface $client)
113
    {
114
        $this->client = $client;
0 ignored issues
show
Documentation Bug introduced by
$client is of type FOS\OAuthServerBundle\Model\ClientInterface, but the property $client was declared to be of type Mautic\ApiBundle\Entity\oAuth2\Client. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof 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 given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
115
116
        return $this;
117
    }
118
119
    /**
120
     * Get client.
121
     *
122
     * @return ClientInterface
123
     */
124
    public function getClient()
125
    {
126
        return $this->client;
127
    }
128
129
    /**
130
     * Set user.
131
     *
132
     * @param UserInterface $user
133
     *
134
     * @return RefreshToken
135
     */
136
    public function setUser(UserInterface $user = null)
137
    {
138
        $this->user = $user;
139
140
        return $this;
141
    }
142
143
    /**
144
     * Get user.
145
     *
146
     * @return UserInterface
147
     */
148
    public function getUser()
149
    {
150
        return $this->user;
151
    }
152
}
153