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
Push — master ( 0acb89...6978d5 )
by Cees-Jan
17s queued 11s
created

JWT   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 0
dl 28
loc 28
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A getOptions() 15 15 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Client\Github\Authentication;
4
5
use ApiClients\Client\Github\AuthenticationInterface;
6
use ApiClients\Foundation\Options as FoundationOptions;
7
use ApiClients\Foundation\Transport\Options as TransportOptions;
8
use ApiClients\Middleware\BearerAuthorization\BearerAuthorizationHeaderMiddleware;
9
use ApiClients\Middleware\BearerAuthorization\Options as BearerAuthorizationHeaderMiddlewareOptions;
10
use Lcobucci\JWT\Token;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, ApiClients\Client\Github\Authentication\Token.

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...
11
12 View Code Duplication
final class JWT implements AuthenticationInterface
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...
13
{
14
    /**
15
     * @var Token
16
     */
17
    private $token;
18
19
    public function __construct(Token $token)
20
    {
21
        $this->token = $token;
22
    }
23
24
    public function getOptions(): array
25
    {
26
        return [
27
            FoundationOptions::TRANSPORT_OPTIONS => [
28
                TransportOptions::MIDDLEWARE => [
29
                    BearerAuthorizationHeaderMiddleware::class,
30
                ],
31
                TransportOptions::DEFAULT_REQUEST_OPTIONS => [
32
                    BearerAuthorizationHeaderMiddleware::class => [
33
                        BearerAuthorizationHeaderMiddlewareOptions::TOKEN => $this->token,
34
                    ],
35
                ],
36
            ],
37
        ];
38
    }
39
}
40