Test Setup Failed
Push — oauth2 ( 63c070 )
by Herberto
11:43 queued 07:12
created

OauthAccessToken   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 4
dl 0
loc 60
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 20 4
A isRevoked() 0 4 1
A revoke() 0 4 1
A setIdentifier() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Explicit Architecture POC,
7
 * which is created on top of the Symfony Demo application.
8
 *
9
 * (c) Herberto Graça <[email protected]>
10
 *
11
 * For the full copyright and license information, please view the LICENSE
12
 * file that was distributed with this source code.
13
 */
14
15
namespace Acme\App\Infrastructure\Auth\Authentication\Oauth;
16
17
use Acme\App\Core\SharedKernel\Component\User\Domain\User\UserId;
18
use DateTime;
19
use DateTimeImmutable;
20
use DateTimeInterface;
21
use League\OAuth2\Server\Entities\AccessTokenEntityInterface;
22
use League\OAuth2\Server\Entities\ClientEntityInterface;
23
use League\OAuth2\Server\Entities\Traits\AccessTokenTrait;
24
use League\OAuth2\Server\Entities\Traits\EntityTrait;
25
use League\OAuth2\Server\Entities\Traits\TokenEntityTrait;
26
27
class OauthAccessToken implements AccessTokenEntityInterface
28
{
29
    use AccessTokenTrait;
30
    use EntityTrait;
31
    use TokenEntityTrait;
32
33
    /**
34
     * @var bool
35
     */
36
    private $revoked = false;
37
38
    /**
39
     * @var DateTimeImmutable
40
     */
41
    private $createdAt;
42
43
    /**
44
     * @var DateTimeImmutable
45
     */
46
    private $updatedAt;
47
48
    public function __construct(
49
        UserId $userId,
50
        ClientEntityInterface $client,
51
        array $scopes = [],
52
        DateTimeInterface $expiryDate = null
53
    ) {
54
        $this->setIdentifier(new OauthAccessTokenId());
55
        $this->setUserIdentifier($userId);
0 ignored issues
show
Documentation introduced by
$userId is of type object<Acme\App\Core\Sha...ser\Domain\User\UserId>, but the function expects a string|integer|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
56
        $this->setClient($client);
57
        foreach ($scopes as $scope) {
58
            $this->addScope($scope);
59
        }
60
        if ($expiryDate) {
61
            $this->setExpiryDateTime(
62
                $expiryDate instanceof DateTimeImmutable
63
                    ? DateTime::createFromImmutable($expiryDate)
64
                    : $expiryDate
65
            );
66
        }
67
    }
68
69
    public function isRevoked(): bool
70
    {
71
        return $this->revoked;
72
    }
73
74
    public function revoke(): void
75
    {
76
        $this->revoked = true;
77
    }
78
79
    /**
80
     * It will only set the identifier if it's not yet set.
81
     */
82
    public function setIdentifier($identifier): void
83
    {
84
        $this->identifier = $this->identifier ?? $identifier;
85
    }
86
}
87