| Conditions | 11 |
| Paths | 18 |
| Total Lines | 58 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 31 | public function file($dir = null) { |
||
| 32 | if (!empty($dir)) { |
||
| 33 | if (isset($_FILES['archive'])) { |
||
| 34 | foreach ($_FILES['archive']['name'] as $i => $name) { |
||
| 35 | $this->name = $_FILES['archive']['name'][$i]; |
||
| 36 | $this->size = $_FILES['archive']['size'][$i]; |
||
| 37 | $this->type = $_FILES['archive']['type'][$i]; |
||
| 38 | $this->tmp = $_FILES['archive']['tmp_name'][$i]; |
||
| 39 | |||
| 40 | $explode = explode('.', $name); |
||
| 41 | $ext = end($explode); |
||
| 42 | |||
| 43 | $this->path = DIR_FILE . 'Upload' . DS . 'Default' . DS . $dir . DS; |
||
| 44 | |||
| 45 | $this->path .= basename($explode[0] . time() . '.' . $ext); |
||
| 46 | $explode = explode('.', $name); |
||
| 47 | |||
| 48 | // echo $ext . "<br/>"; |
||
| 49 | |||
| 50 | |||
| 51 | |||
| 52 | if (empty($this->type)) { |
||
| 53 | return $errors[] = '<div class="btn btn-danger"> Por favor, escolhe 1 ficheiro para ser carregado</div>'; |
||
| 54 | } else { |
||
| 55 | $allowed = array('jpg', 'JPG', 'jpeg', 'gif', 'btm', 'png', 'txt', 'docx', 'doc', 'pdf', 'mp3'); |
||
| 56 | |||
| 57 | if (in_array($ext, $allowed) === false) |
||
| 58 | return $errors[] = '<div class="btn btn-danger">A extensao do ficheiro nao foi permitido </div>'; |
||
| 59 | } |
||
| 60 | // 100000000 |
||
| 61 | $max_size = 100000000; |
||
| 62 | if ($this->size > $max_size) { |
||
| 63 | return $errors[] = '<div class="btn btn-danger"> O tamanho do ficheiro é muito grande</div>'; |
||
| 64 | } |
||
| 65 | }// end foreach |
||
| 66 | } // end if |
||
| 67 | |||
| 68 | if (empty($errors)) { |
||
| 69 | |||
| 70 | if (!file_exists(DIR_FILE . 'Upload' . DS . $dir . DS)) { |
||
| 71 | mkdir(DIR_FILE . 'Upload' . DS . $dir . DS, 0777, true); |
||
| 72 | |||
| 73 | } // chmod('uploads/', 0755); |
||
| 74 | else if (!file_exists(DIR_FILE . 'Upload' . DS . 'Default' . DS . $dir . DS)) { |
||
| 75 | mkdir(DIR_FILE . 'Upload' . DS . 'Default' . DS . $dir . DS, 0777, true); |
||
| 76 | |||
| 77 | } // chmod('uploads/', 0755); |
||
| 78 | |||
| 79 | if (move_uploaded_file($this->tmp, $this->path )) { |
||
| 80 | $output = '<div class="btn btn-success">'; |
||
| 81 | $output .= 'Ficheiro carregado com sucesso'; |
||
| 82 | $output .= '</div>'; |
||
| 83 | return $output; |
||
| 84 | } else { |
||
| 85 | $output = '<div class="btn btn-warning">'; |
||
| 86 | $output .= 'Nenhum ficheiro foi carregado'; |
||
| 87 | $output .= '</div>'; |
||
| 88 | return $output; |
||
| 89 | } |
||
| 107 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.