Passed
Push — staging ( 81ba0c...d71a8f )
by Woeler
14:37 queued 10s
created

app/bundles/ApiBundle/Entity/oAuth2/AuthCode.php (4 issues)

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
    /**
61
     * @param ORM\ClassMetadata $metadata
62
     */
63
    public static function loadMetadata(ORM\ClassMetadata $metadata)
64
    {
65
        $builder = new ClassMetadataBuilder($metadata);
66
67
        $builder->setTable('oauth2_authcodes');
68
69
        $builder->createField('id', 'integer')
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\ORM\Mapping\Bui...Builder::isPrimaryKey() has been deprecated: Use makePrimaryKey() instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

69
        /** @scrutinizer ignore-deprecated */ $builder->createField('id', 'integer')

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
70
            ->isPrimaryKey()
71
            ->generatedValue()
72
            ->build();
73
74
        $builder->createManyToOne('client', 'Client')
75
            ->addJoinColumn('client_id', 'id', false, false, 'CASCADE')
76
            ->build();
77
78
        $builder->createManyToOne('user', 'Mautic\UserBundle\Entity\User')
79
            ->addJoinColumn('user_id', 'id', false, false, 'CASCADE')
80
            ->build();
81
82
        $builder->createField('token', 'string')
83
            ->unique()
84
            ->build();
85
86
        $builder->createField('expiresAt', 'bigint')
87
            ->columnName('expires_at')
88
            ->nullable()
89
            ->build();
90
91
        $builder->createField('scope', 'string')
92
            ->nullable()
93
            ->build();
94
95
        $builder->createField('redirectUri', 'text')
96
            ->columnName('redirect_uri')
97
            ->build();
98
    }
99
100
    /**
101
     * Get id.
102
     *
103
     * @return int
104
     */
105
    public function getId()
106
    {
107
        return $this->id;
108
    }
109
110
    /**
111
     * Set client.
112
     *
113
     * @param ClientInterface $client
114
     *
115
     * @return RefreshToken
116
     */
117
    public function setClient(ClientInterface $client)
118
    {
119
        $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...
120
121
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Mautic\ApiBundle\Entity\oAuth2\AuthCode which is incompatible with the documented return type Mautic\ApiBundle\Entity\oAuth2\RefreshToken.
Loading history...
122
    }
123
124
    /**
125
     * Get client.
126
     *
127
     * @return ClientInterface
128
     */
129
    public function getClient()
130
    {
131
        return $this->client;
132
    }
133
134
    /**
135
     * Set user.
136
     *
137
     * @param UserInterface $user
138
     *
139
     * @return RefreshToken
140
     */
141
    public function setUser(UserInterface $user = null)
142
    {
143
        $this->user = $user;
144
145
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Mautic\ApiBundle\Entity\oAuth2\AuthCode which is incompatible with the documented return type Mautic\ApiBundle\Entity\oAuth2\RefreshToken.
Loading history...
146
    }
147
148
    /**
149
     * Get user.
150
     *
151
     * @return UserInterface
152
     */
153
    public function getUser()
154
    {
155
        return $this->user;
156
    }
157
}
158