Completed
Push — master ( 6a3534...3888fe )
by Carlos
01:41
created

AccessToken::getRefreshToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the overtrue/socialite.
5
 *
6
 * (c) overtrue <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Overtrue\Socialite;
13
14
use ArrayAccess;
15
use InvalidArgumentException;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Overtrue\Socialite\InvalidArgumentException.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
16
use JsonSerializable;
17
18
/**
19
 * Class AccessToken.
20
 */
21
class AccessToken implements AccessTokenInterface, ArrayAccess, JsonSerializable
22
{
23
    use HasAttributes;
24
25
    /**
26
     * AccessToken constructor.
27
     *
28
     * @param array $attributes
29
     */
30
    public function __construct(array $attributes)
31
    {
32
        if (empty($attributes['access_token'])) {
33
            throw new InvalidArgumentException('The key "access_token" could not be empty.');
34
        }
35
36
        $this->attributes = $attributes;
37
    }
38
39
    /**
40
     * Return the access token string.
41
     *
42
     * @return string
43
     */
44
    public function getToken()
45
    {
46
        return $this->getAttribute('access_token');
47
    }
48
49
    /**
50
     * Return the refresh token string.
51
     *
52
     * @return string
53
     */
54
    public function getRefreshToken()
55
    {
56
        return $this->getAttribute('refresh_token');
57
    }
58
59
    /**
60
     * Set refresh token into this object.
61
     *
62
     * @param string $token
63
     */
64
    public function setRefreshToken($token)
65
    {
66
        $this->setAttribute('refresh_token', $token);
67
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72
    public function __toString()
73
    {
74
        return strval($this->getAttribute('access_token', ''));
75
    }
76
77
    /**
78
     * {@inheritdoc}
79
     */
80
    public function jsonSerialize()
81
    {
82
        return $this->getToken();
83
    }
84
}
85