GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#159)
by Roman
01:55
created

Token::getAliases()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 8
Ratio 100 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 8
loc 8
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
crap 1
1
<?php declare(strict_types=1);
2
3
namespace OpenStack\Identity\v2\Models;
4
5
use OpenStack\Common\Resource\Alias;
6
use OpenStack\Common\Transport\Utils;
7
use Psr\Http\Message\ResponseInterface;
8
use OpenStack\Common\Resource\OperatorResource;
9
use OpenStack\Common\Resource\ValueResource;
10
11
/**
12
 * Represents an Identity v2 Token.
13
 *
14
 * @package OpenStack\Identity\v2\Models
15
 */
16
class Token extends OperatorResource implements \OpenStack\Common\Auth\Token
17
{
18
    /** @var \DateTimeImmutable */
19
    public $issuedAt;
20
21
    /** @var string */
22
    public $id;
23
24
    /** @var \DateTimeImmutable */
25
    public $expires;
26
27
    /** @var Tenant */
28
    public $tenant;
29
30
    /**
31
     * @var array
32
     */
33
    protected $aliases = [];
34 2
35
    /**
36 2
     * @inheritdoc
37
     */
38 2 View Code Duplication
    protected function getAliases()
0 ignored issues
show
Duplication introduced by
This method 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...
39
    {
40
        $aliases = parent::getAliases();
41 1
        $aliases['tenant'] = new Alias('tenant', Tenant::class);
42
        $aliases['expires'] = new Alias('expires', \DateTimeImmutable::class);
43 1
        $aliases['issued_at'] = new Alias('issuedAt', \DateTimeImmutable::class);
44
        return $aliases;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $aliases; (array<*,OpenStack\Common\Resource\Alias>) is incompatible with the return type of the parent method OpenStack\Common\Resourc...actResource::getAliases of type OpenStack\Common\Resource\Alias[].

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
45
    }
46 2
47
    /**
48 2
     * {@inheritDoc}
49
     */
50
    public function populateFromResponse(ResponseInterface $response): self
51
    {
52
        $this->populateFromArray(Utils::jsonDecode($response)['access']['token']);
53
54
        return $this;
55
    }
56
57
    public function getId(): string
58
    {
59
        return $this->id;
60
    }
61
62
    public function hasExpired(): bool
63
    {
64
        return $this->expires <= new \DateTimeImmutable('now', $this->expires->getTimezone());
65
    }
66
}
67