| Conditions | 2 |
| Paths | 2 |
| Total Lines | 28 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 2 |
| 1 | <?php |
||
| 35 | public function getUrls() |
||
| 36 | { |
||
| 37 | $resolver = new OptionsResolver(); |
||
| 38 | $resolver->setRequired( |
||
| 39 | [ |
||
| 40 | 'url', |
||
| 41 | 'method', |
||
| 42 | 'headers', |
||
| 43 | 'timeout', |
||
| 44 | 'status_code', |
||
| 45 | ] |
||
| 46 | ); |
||
| 47 | |||
| 48 | $config = $this->configurationLoader->loadConfiguration(); |
||
| 49 | foreach ($config['urls'] as $name => $attribute) { |
||
| 50 | $attribute = $resolver->resolve($attribute); |
||
| 51 | $urls[$name] = new UrlInfo( |
||
|
|
|||
| 52 | $name, |
||
| 53 | $attribute['url'], |
||
| 54 | $attribute['method'], |
||
| 55 | $attribute['headers'], |
||
| 56 | $attribute['timeout'], |
||
| 57 | $attribute['status_code'] |
||
| 58 | ); |
||
| 59 | } |
||
| 60 | |||
| 61 | return $urls; |
||
| 62 | } |
||
| 63 | } |
||
| 64 |
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
$myArrayis initialized the first time when the foreach loop is entered. You can also see that the value of thebarkey 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.