| Conditions | 4 | 
| Paths | 6 | 
| Total Lines | 37 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 0 | ||
| 1 | <?php | ||
| 19 | public function editor($file) | ||
| 20 |     { | ||
| 21 |         if ('/admin/appearance/editor' === $file) { | ||
| 22 |             $this->redirectTo('/admin/appearance/editor/file/dGVtcGxhdGVzL19oZWFkLmh0bWwucGhw'); | ||
| 23 | } | ||
| 24 | |||
| 25 | $model = new EditorModel(); | ||
| 26 | |||
| 27 |         $filesList['templates'] = $model->getFilesListByPath('templates'); | ||
|  | |||
| 28 |         $filesList['css'] = $model->getFilesListByPath('css'); | ||
| 29 |         $filesList['js'] = $model->getFilesListByPath('js'); | ||
| 30 | |||
| 31 | $filename = base64_decode($file); | ||
| 32 | |||
| 33 | // if data was send | ||
| 34 |         if (isset($_POST['save'])) { | ||
| 35 | /** @var array $_POST */ | ||
| 36 |             if ($model->saveFile($filename, $_POST['content'])) { | ||
| 37 | AlertsCollection::add(new Alert( | ||
| 38 | 'success', | ||
| 39 | 'Pomyślnie zapisano plik szablonu '.$filename.'.' | ||
| 40 | )); | ||
| 41 |             } else { | ||
| 42 | AlertsCollection::add(new Alert( | ||
| 43 | 'error', | ||
| 44 | 'Coś poszło nie tak podczas zapisywania pliku '.$filename.'. '. | ||
| 45 | 'Sprawdź prawa dostępu' | ||
| 46 | )); | ||
| 47 | } | ||
| 48 | |||
| 49 | $this->redirectTo($file); | ||
| 50 | } | ||
| 51 | |||
| 52 | $view = new EditorView(); | ||
| 53 | $view->editor($filesList, $model->getFileInfo($filename)); | ||
| 54 | $view->render(); | ||
| 55 | } | ||
| 56 | } | ||
| 57 | 
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.