| Conditions | 2 |
| Paths | 2 |
| Total Lines | 27 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 29 | function wpbo_mp_settings( $settings ) { |
||
| 30 | |||
| 31 | $lists = wpbo_mp_get_mailpoet_lists(); |
||
| 32 | $lists_list[''] = esc_html_x( 'Please select...', 'Select a MailPoet mailing list', 'betteroptin' ); |
||
|
|
|||
| 33 | |||
| 34 | foreach ( $lists as $list ) { |
||
| 35 | $lists_list[ $list['list_id'] ] = $list['name']; |
||
| 36 | } |
||
| 37 | |||
| 38 | $list_id = array( |
||
| 39 | 'name' => __( 'List', 'betteroptin' ), |
||
| 40 | 'id' => 'mp_list_id', |
||
| 41 | 'type' => 'select', |
||
| 42 | 'options' => $lists_list, |
||
| 43 | 'default' => '' |
||
| 44 | ); |
||
| 45 | |||
| 46 | $settings['mailpoet'] = array( |
||
| 47 | 'name' => __( 'MailPoet', 'betteroptin' ), |
||
| 48 | 'options' => array( |
||
| 49 | $list_id |
||
| 50 | ) |
||
| 51 | ); |
||
| 52 | |||
| 53 | return $settings; |
||
| 54 | |||
| 55 | } |
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.