| Conditions | 4 |
| Paths | 4 |
| Total Lines | 22 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| 1 | <?php |
||
| 18 | public function isValid() |
||
|
|
|||
| 19 | { |
||
| 20 | //file not required and not send by user |
||
| 21 | if ($this->isNotRequiredAndEmpty('file')) { |
||
| 22 | return true; |
||
| 23 | } |
||
| 24 | |||
| 25 | $fileField = $this->getParams()[0]; |
||
| 26 | |||
| 27 | //uploading error: file is too big, or permissions, etc.. |
||
| 28 | if (!isset($_FILES[$fileField])) { |
||
| 29 | return false; |
||
| 30 | } |
||
| 31 | |||
| 32 | if ($_FILES[$fileField]['tmp_name']) { |
||
| 33 | |||
| 34 | //if file is image |
||
| 35 | return is_array(getimagesize($_FILES[$fileField]['tmp_name'])); |
||
| 36 | } |
||
| 37 | |||
| 38 | return false; |
||
| 39 | } |
||
| 40 | |||
| 46 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: