| Conditions | 7 |
| Paths | 10 |
| Total Lines | 72 |
| Code Lines | 50 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 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 |
||
| 139 | public function getCroppedImageSrcBySrc($src, $ratio, $x, $y) |
||
| 140 | { |
||
| 141 | $absoluteImageName = GeneralUtility::getFileAbsFileName($src); |
||
| 142 | if (!is_file($absoluteImageName)) { |
||
| 143 | return null; |
||
| 144 | } |
||
| 145 | $docRoot = rtrim(GeneralUtility::getIndpEnv('TYPO3_DOCUMENT_ROOT'), '/') . '/'; |
||
| 146 | $relativeSrc = str_replace($docRoot, '', $absoluteImageName); |
||
| 147 | $focusPointX = MathUtility::forceIntegerInRange((int)$x, -100, 100, 0); |
||
| 148 | $focusPointY = MathUtility::forceIntegerInRange((int)$y, -100, 100, 0); |
||
| 149 | |||
| 150 | if ($focusPointX === 0 && $focusPointY === 0) { |
||
| 151 | $connection = GlobalUtility::getDatabaseConnection(); |
||
| 152 | $row = $connection->exec_SELECTgetSingleRow( |
||
| 153 | 'uid,focus_point_x,focus_point_y', |
||
| 154 | Group::TABLE, |
||
| 155 | 'relative_file_path = ' . $connection->fullQuoteStr($relativeSrc, Group::TABLE) |
||
| 156 | ); |
||
| 157 | if ($row) { |
||
| 158 | $focusPointX = MathUtility::forceIntegerInRange((int)$row['focus_point_x'], -100, 100, 0); |
||
| 159 | $focusPointY = MathUtility::forceIntegerInRange((int)$row['focus_point_y'], -100, 100, 0); |
||
| 160 | } |
||
| 161 | } |
||
| 162 | |||
| 163 | $tempImageFolder = 'typo3temp/focuscrop/'; |
||
| 164 | $tempImageName = $this->generateTempImageName($absoluteImageName, $ratio, $focusPointX, $focusPointY); |
||
| 165 | $tempImageName = $tempImageFolder . $tempImageName; |
||
| 166 | |||
| 167 | $absoluteTempImageName = GeneralUtility::getFileAbsFileName($tempImageName); |
||
| 168 | |||
| 169 | if (is_file($absoluteTempImageName)) { |
||
| 170 | return $tempImageName; |
||
| 171 | } |
||
| 172 | |||
| 173 | $absoluteTempImageFolder = GeneralUtility::getFileAbsFileName($tempImageFolder); |
||
| 174 | if (!is_dir($absoluteTempImageFolder)) { |
||
| 175 | GeneralUtility::mkdir_deep($absoluteTempImageFolder); |
||
| 176 | } |
||
| 177 | |||
| 178 | $imageSizeInformation = getimagesize($absoluteImageName); |
||
| 179 | $width = $imageSizeInformation[0]; |
||
| 180 | $height = $imageSizeInformation[1]; |
||
| 181 | |||
| 182 | // dimensions |
||
| 183 | /** @var DimensionService $dimensionService */ |
||
| 184 | $dimensionService = GeneralUtility::makeInstance(DimensionService::class); |
||
| 185 | list($focusWidth, $focusHeight) = $dimensionService->getFocusWidthAndHeight($width, $height, $ratio); |
||
| 186 | $cropMode = $dimensionService->getCropMode($width, $height, $ratio); |
||
| 187 | list($sourceX, $sourceY) = $dimensionService->calculateSourcePosition( |
||
| 188 | $cropMode, |
||
| 189 | $width, |
||
| 190 | $height, |
||
| 191 | $focusWidth, |
||
| 192 | $focusHeight, |
||
| 193 | $focusPointX, |
||
| 194 | $focusPointY |
||
| 195 | ); |
||
| 196 | |||
| 197 | $cropService = GeneralUtility::makeInstance(CropService::class); |
||
| 198 | $cropService->createImage( |
||
| 199 | $absoluteImageName, |
||
| 200 | $focusWidth, |
||
| 201 | $focusHeight, |
||
| 202 | $sourceX, |
||
| 203 | $sourceY, |
||
| 204 | $absoluteTempImageName |
||
| 205 | ); |
||
| 206 | |||
| 207 | $this->emitTempImageCropped($tempImageName); |
||
| 208 | |||
| 209 | return $tempImageName; |
||
| 210 | } |
||
| 211 | |||
| 282 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.