Conditions | 2 |
Paths | 2 |
Total Lines | 15 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Tests | 3 |
CRAP Score | 2 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
34 | 2 | public function buildMethod(Query $query) |
|
35 | { |
||
36 | static $defaultMethods = [ |
||
37 | 'get' => 'GET', |
||
38 | 'put' => 'PUT', |
||
39 | 'head' => 'HEAD', |
||
40 | 'post' => 'GET', |
||
41 | 'search' => 'GET', |
||
42 | 'insert' => 'POST', |
||
43 | 'update' => 'PUT', |
||
44 | 'delete' => 'DELETE', |
||
45 | 2 | ]; |
|
46 | |||
47 | 2 | return isset($defaultMethods[$query->action]) ? $defaultMethods[$query->action] : 'POST'; |
|
48 | } |
||
49 | |||
80 |
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.