1 | <?php declare(strict_types=1); |
||
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( |
||
70 | } |
||
71 |
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:
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 thebar
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.