| Total Complexity | 9 | 
| Total Lines | 90 | 
| Duplicated Lines | 0 % | 
| Coverage | 57.14% | 
| Changes | 0 | ||
| 1 | <?php  | 
            ||
| 5 | class AccessToken  | 
            ||
| 6 | { | 
            ||
| 7 | private $token;  | 
            ||
| 8 | private $type;  | 
            ||
| 9 | private $expiration;  | 
            ||
| 10 | private $scope = [  | 
            ||
| 11 | 'payments',  | 
            ||
| 12 | 'user.app-settings',  | 
            ||
| 13 | 'transactions.history',  | 
            ||
| 14 | 'user.profile_readonly'  | 
            ||
| 15 | ];  | 
            ||
| 16 | |||
| 17 | /**  | 
            ||
| 18 | * @param string $token  | 
            ||
| 19 | * @param string $type  | 
            ||
| 20 | * @param integer $expiresIn  | 
            ||
| 21 | * @param string|null $scope  | 
            ||
| 22 | */  | 
            ||
| 23 | 5 | public function __construct(string $token, string $type, int $expiresIn, string $scope = null)  | 
            |
| 24 |     { | 
            ||
| 25 | 5 | $this->token = $token;  | 
            |
| 26 | 5 | $this->type = $type;  | 
            |
| 27 | 5 | $this->expiration = time() + $expiresIn;  | 
            |
| 28 | |||
| 29 | 5 |         if($scope !== null) { | 
            |
| 30 | $this->scope = $scope;  | 
            ||
| 31 | }  | 
            ||
| 32 | 5 | }  | 
            |
| 33 | |||
| 34 | /**  | 
            ||
| 35 | * Check if token is valid  | 
            ||
| 36 | *  | 
            ||
| 37 | * @return boolean  | 
            ||
| 38 | */  | 
            ||
| 39 | 5 | public function isValid(): bool  | 
            |
| 40 |     { | 
            ||
| 41 | 5 | return $this->getToken() !== '' && time() < $this->expiration;  | 
            |
| 42 | }  | 
            ||
| 43 | |||
| 44 | /**  | 
            ||
| 45 | * getToken  | 
            ||
| 46 | *  | 
            ||
| 47 | * @return string  | 
            ||
| 48 | */  | 
            ||
| 49 | 5 | public function getToken(): string  | 
            |
| 50 |     { | 
            ||
| 51 | 5 | return $this->token;  | 
            |
| 52 | }  | 
            ||
| 53 | |||
| 54 | /**  | 
            ||
| 55 | * getType  | 
            ||
| 56 | *  | 
            ||
| 57 | * @return string  | 
            ||
| 58 | */  | 
            ||
| 59 | 5 | public function getType(): string  | 
            |
| 60 |     { | 
            ||
| 61 | 5 | return $this->type;  | 
            |
| 62 | }  | 
            ||
| 63 | |||
| 64 | /**  | 
            ||
| 65 | * Get Expiration  | 
            ||
| 66 | *  | 
            ||
| 67 | * @return integer  | 
            ||
| 68 | */  | 
            ||
| 69 | public function getExpiration(): int  | 
            ||
| 70 |     { | 
            ||
| 71 | return $this->expiration;  | 
            ||
| 72 | }  | 
            ||
| 73 | |||
| 74 | /**  | 
            ||
| 75 | * Get scope  | 
            ||
| 76 | *  | 
            ||
| 77 | * @return array  | 
            ||
| 78 | */  | 
            ||
| 79 | public function getScope(): array  | 
            ||
| 80 |     { | 
            ||
| 81 | return $this->scope;  | 
            ||
| 82 | }  | 
            ||
| 83 | |||
| 84 | /**  | 
            ||
| 85 | * Check if token can access one or more scope  | 
            ||
| 86 | *  | 
            ||
| 87 | * @param string $scope[,$scope[,$scope[,...]]]  | 
            ||
| 88 | * @return boolean  | 
            ||
| 89 | */  | 
            ||
| 90 | public function canAccess(string $scope)  | 
            ||
| 95 | }  | 
            ||
| 96 | }  | 
            ||
| 97 |