| Conditions | 3 |
| Paths | 3 |
| Total Lines | 18 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| 1 | <?php |
||
| 9 | protected function result() { |
||
| 10 | add_action( 'automatic_updates_complete', array( $this, 'get_update_results' ), 100, 1 ); |
||
| 11 | |||
| 12 | wp_maybe_auto_update(); |
||
| 13 | |||
| 14 | $result['log'] = $this->update_results; |
||
|
|
|||
| 15 | |||
| 16 | if ( empty( $result['log'] ) ) { |
||
| 17 | $possible_reasons_for_failure = Jetpack_Autoupdate::get_possible_failures(); |
||
| 18 | |||
| 19 | if ( $possible_reasons_for_failure ) { |
||
| 20 | $result['log']['error'] = $possible_reasons_for_failure; |
||
| 21 | } |
||
| 22 | |||
| 23 | } |
||
| 24 | |||
| 25 | return $result; |
||
| 26 | } |
||
| 27 | |||
| 33 |
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.