Conditions | 1 |
Paths | 1 |
Total Lines | 49 |
Code Lines | 23 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
45 | public function textProvider() { |
||
46 | |||
47 | #0 |
||
48 | $provider[] = array( |
||
|
|||
49 | 'Foo bar', |
||
50 | 'Foo bar' |
||
51 | ); |
||
52 | |||
53 | #1 |
||
54 | $provider[] = array( |
||
55 | 'Foo [42] bar', |
||
56 | 'Foo [42] bar' |
||
57 | ); |
||
58 | |||
59 | #2 |
||
60 | $provider[] = array( |
||
61 | 'Foo [42 1001] bar', |
||
62 | 'Foo [42 1001] bar' |
||
63 | ); |
||
64 | |||
65 | #3 |
||
66 | $provider[] = array( |
||
67 | 'Foo [[42]] bar', |
||
68 | 'Foo [[abc:42|42]] bar' |
||
69 | ); |
||
70 | |||
71 | #4 |
||
72 | $provider[] = array( |
||
73 | 'Foo [[42|1001]] bar', |
||
74 | 'Foo [[abc:42|1001]] bar' |
||
75 | ); |
||
76 | |||
77 | // We can't guess the type of a remote annotation therefore it is turned |
||
78 | // into an simple text value |
||
79 | |||
80 | #5 |
||
81 | $provider[] = array( |
||
82 | 'Foo [[Has number::42]] bar', |
||
83 | 'Foo 42 bar' |
||
84 | ); |
||
85 | |||
86 | #6 |
||
87 | $provider[] = array( |
||
88 | 'Foo [[Has number::42|1001]] bar', |
||
89 | 'Foo 1001 bar' |
||
90 | ); |
||
91 | |||
92 | return $provider; |
||
93 | } |
||
94 | |||
96 |
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.