Conditions | 7 |
Paths | 6 |
Total Lines | 34 |
Code Lines | 26 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
14 | public function __construct() { |
||
15 | global $ACT; |
||
16 | global $INFO; |
||
17 | global $REV; |
||
18 | |||
19 | parent::__construct(); |
||
20 | |||
21 | if($ACT == 'show' || $ACT == 'search') { |
||
22 | $this->method = 'post'; |
||
23 | if($INFO['writable']) { |
||
24 | $this->accesskey = 'e'; |
||
25 | if(!empty($INFO['draft'])) { |
||
26 | $this->type = 'draft'; |
||
27 | $this->params['do'] = 'draft'; |
||
28 | } else { |
||
29 | $this->params['rev'] = $REV; |
||
30 | if(!$INFO['exists']) { |
||
31 | $this->type = 'create'; |
||
32 | } |
||
33 | } |
||
34 | } else { |
||
35 | if(!actionOK($this->type)) throw new \RuntimeException("action disabled: source"); |
||
36 | $params['rev'] = $REV; |
||
|
|||
37 | $this->type = 'source'; |
||
38 | $this->accesskey = 'v'; |
||
39 | } |
||
40 | } else { |
||
41 | $this->params = array('do' => ''); |
||
42 | $this->type = 'show'; |
||
43 | $this->accesskey = 'v'; |
||
44 | } |
||
45 | |||
46 | $this->setIcon(); |
||
47 | } |
||
48 | |||
66 |
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.