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 (#21)
by Cees-Jan
08:23
created

ApiSettings   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A getOptions() 0 20 2
1
<?php declare(strict_types=1);
2
3
namespace WyriHaximus\Travis;
4
5
use ApiClients\Foundation\Hydrator\Options as HydratorOptions;
6
use ApiClients\Foundation\Options as FoundationOptions;
7
use ApiClients\Foundation\Transport\Middleware\JsonDecodeMiddleware;
8
use ApiClients\Foundation\Transport\Middleware\JsonEncodeMiddleware;
9
use ApiClients\Foundation\Transport\Options as TransportOptions;
10
use ApiClients\Foundation\Transport\UserAgentStrategies;
11
use WyriHaximus\Travis\Middleware\TokenAuthorizationHeaderMiddleware;
12
13
class ApiSettings
14
{
15
    /**
16
     * Travis' Pusher App ID as found on: https://docs.travis-ci.com/api?http#external-apis
17
     * Will automate the retrieval of that key later in the PR
18
     */
19
    const PUSHER_KEY = '5df8ac576dcccf4fd076';
20
21
    const NAMESPACE = 'WyriHaximus\\Travis\\Resource';
22
23
    const TRANSPORT_OPTIONS = [
24
        FoundationOptions::HYDRATOR_OPTIONS => [
25
            HydratorOptions::NAMESPACE => self::NAMESPACE,
26
            HydratorOptions::NAMESPACE_DIR => __DIR__ .
27
                DIRECTORY_SEPARATOR .
28
                'Resource' .
29
                DIRECTORY_SEPARATOR,
30
        ],
31
        FoundationOptions::TRANSPORT_OPTIONS => [
32
            TransportOptions::HOST => 'api.travis-ci.org',
33
            TransportOptions::HEADERS => [
34
                'Accept' => 'application/vnd.travis-ci.2+json',
35
            ],
36
            TransportOptions::USER_AGENT_STRATEGY => UserAgentStrategies::PACKAGE_VERSION,
37
            TransportOptions::PACKAGE => 'wyrihaximus/travis-client',
38
            TransportOptions::MIDDLEWARE => [
39
                JsonDecodeMiddleware::class,
40
                JsonEncodeMiddleware::class,
41
            ],
42
        ],
43
    ];
44
45
    /**
46
     * @param string $token
47
     * @param string $suffix
48
     * @return array
49
     */
50
    public static function getOptions(
51
        string $token,
52
        string $suffix
53
    ): array {
54
        $options = self::TRANSPORT_OPTIONS;
55
        $transportOptions[HydratorOptions::NAMESPACE_SUFFIX] = $suffix;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$transportOptions was never initialized. Although not strictly required by PHP, it is generally a good practice to add $transportOptions = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
56
57
        if (!empty($token)) {
58
            $transportOptions[TransportOptions::MIDDLEWARE][] = TokenAuthorizationHeaderMiddleware::class;
59
            $transportOptions[TransportOptions::DEFAULT_REQUEST_OPTIONS] = [
60
                TokenAuthorizationHeaderMiddleware::class => [
61
                    Options::TOKEN => $token,
62
                ],
63
            ];
64
        }
65
66
        $options[FoundationOptions::HYDRATOR_OPTIONS] = $transportOptions;
67
68
        return $options;
69
    }
70
}
71