Completed
Push — develop ( 098743...5f7eab )
by Raphael De
02:19
created

RefreshToken::getExpireIn()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 4
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Majora\Component\OAuth\Entity;
4
5
use Majora\Component\OAuth\Model\RefreshTokenInterface;
6
use Majora\Component\OAuth\Model\AccountInterface;
7
use Majora\Component\OAuth\Model\ApplicationInterface;
8
use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder;
9
10
/**
11
 * Class RefreshToken is the default implementation of RefreshTokenInterface
12
 *
13
 * @author Raphael De Freitas <[email protected]>
14
 */
15 View Code Duplication
class RefreshToken implements RefreshTokenInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
16
{
17
    /**
18
     * @var string
19
     */
20
    protected $hash;
21
22
    /**
23
     * @var int
24
     */
25
    protected $expireIn;
26
27
    /**
28
     * @var AccountInterface
29
     */
30
    protected $account;
31
32
    /**
33
     * @var ApplicationInterface
34
     */
35
    protected $application;
36
37
    /**
38
     * @see RefreshTokenInterface::__construct()
39
     */
40
    public function __construct(
41
        ApplicationInterface $application,
42
        AccountInterface $account = null,
43
        $expireIn = RefreshTokenInterface::DEFAULT_TTL,
44
        $hash = null
45
    ) {
46
        $this->application = $application;
47
        $this->account = $account;
48
        $this->expireIn = $expireIn;
49
50
        $this->hash = $hash ?: (new MessageDigestPasswordEncoder())->encodePassword(
51
            sprintf('[%s\o/%s]', $application->getSecret(), $account->getPassword() ?: time()),
0 ignored issues
show
Bug introduced by
It seems like $account is not always an object, but can also be of type null. Maybe add an additional type check?

If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:

function someFunction(A $objectMaybe = null)
{
    if ($objectMaybe instanceof A) {
        $objectMaybe->doSomething();
    }
}
Loading history...
52
            uniqid(mt_rand(), true)
53
        );
54
    }
55
56
    /**
57
     * @see RefreshTokenInterface::getHash()
58
     */
59
    public function getHash()
60
    {
61
        return $this->hash;
62
    }
63
64
    /**
65
     * @see RefreshTokenInterface::getExpireIn()
66
     */
67
    public function getExpireIn()
68
    {
69
        return $this->expireIn;
70
    }
71
72
    /**
73
     * @see RefreshTokenInterface::getAccount()
74
     */
75
    public function getAccount()
76
    {
77
        return $this->account;
78
    }
79
80
    /**
81
     * @see RefreshTokenInterface::getApplication()
82
     */
83
    public function getApplication()
84
    {
85
        return $this->application;
86
    }
87
88
    /**
89
     * @see RefreshTokenInterface::getRoles()
90
     */
91
    public function getRoles()
92
    {
93
        return array_intersect($this->account->getRoles(), $this->application->getRoles());
94
    }
95
}
96