| Conditions | 11 |
| Paths | 15 |
| Total Lines | 56 |
| Code Lines | 30 |
| 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 |
||
| 86 | public function upload(string $sFile) |
||
|
|
|||
| 87 | { |
||
| 88 | if ($_FILES[$sFile]['error'] > 0) { |
||
| 89 | |||
| 90 | $this->_sError = "Error while the upload"; |
||
| 91 | return false; |
||
| 92 | } |
||
| 93 | |||
| 94 | if ($_FILES[$sFile]['size'] > $this->_iMaxFile) { |
||
| 95 | |||
| 96 | $this->_sError = "The file is too big"; |
||
| 97 | return false; |
||
| 98 | } |
||
| 99 | |||
| 100 | $sExtension = strtolower(substr(strrchr($_FILES[$sFile]['name'], '.'), 1)); |
||
| 101 | |||
| 102 | if (count($this->_aAllowExtension) > 0 && !in_array($sExtension ,$this->_aAllowExtension)) { |
||
| 103 | |||
| 104 | $this->_sError = "The extension is not good"; |
||
| 105 | return false; |
||
| 106 | } |
||
| 107 | |||
| 108 | $sPath = str_replace('bundles'.DIRECTORY_SEPARATOR.'lib', |
||
| 109 | 'data'.DIRECTORY_SEPARATOR.'upload'.DIRECTORY_SEPARATOR, __DIR__); |
||
| 110 | |||
| 111 | if ($this->_sExtension === null) { $this->setExtension($sExtension); } |
||
| 112 | |||
| 113 | if ($this->_sName) { $sName = $sPath.$this->_sName.'.'.$this->_sExtension; } |
||
| 114 | else { $sName = $sPath.md5(uniqid(rand(), true)).'.'.$this->_sExtension;} |
||
| 115 | |||
| 116 | if ($this->_bProportion === true && ($this->_iWidth || $this->_iHeight)) { |
||
| 117 | |||
| 118 | $aImageSizes = getimagesize($_FILES[$sFile]['tmp_name']); |
||
| 119 | |||
| 120 | $fRatio = min($aImageSizes[0] / $this->_iWidth, $aImageSizes[1] / $this->_iHeight); |
||
| 121 | $iHeight = $aImageSizes[1] / $fRatio; |
||
| 122 | $iWidth = $aImageSizes[0] / $fRatio; |
||
| 123 | $fY = ($iHeight - $this->_iHeight) / 2 * $fRatio; |
||
| 124 | $fX = ($iWidth - $this->_iWidth) / 2 * $fRatio; |
||
| 125 | |||
| 126 | $rNewImage = imagecreatefromjpeg($_FILES[$sFile]['tmp_name']); |
||
| 127 | |||
| 128 | $rNewImgTrueColor = imagecreatetruecolor($this->_iWidth , $this->_iHeight); |
||
| 129 | imagecopyresampled($rNewImgTrueColor , $rNewImage, 0, 0, $fX, $fY, $this->_iWidth, $this->_iHeight, $iWidth * $fRatio - $fX * 2, $iHeight * $fRatio - $fY * 2); |
||
| 130 | |||
| 131 | imagejpeg($rNewImgTrueColor , $sName, 100); |
||
| 132 | } |
||
| 133 | else { |
||
| 134 | |||
| 135 | $bResultat = move_uploaded_file($_FILES[$sFile]['tmp_name'], $sName); |
||
| 136 | |||
| 137 | if ($bResultat) { return true; } |
||
| 138 | } |
||
| 139 | |||
| 140 | |||
| 141 | } |
||
| 142 | |||
| 221 |