| Conditions | 8 | 
| Paths | 11 | 
| Total Lines | 59 | 
| Code Lines | 38 | 
| 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  | 
            ||
| 89 | public function getVariation(Field $field, VersionInfo $versionInfo, $variationName, array $parameters = array())  | 
            ||
| 90 |     { | 
            ||
| 91 | /** @var \eZ\Publish\Core\FieldType\Image\Value $imageValue */  | 
            ||
| 92 | $imageValue = $field->value;  | 
            ||
| 93 | $fieldId = $field->id;  | 
            ||
| 94 | $fieldDefIdentifier = $field->fieldDefIdentifier;  | 
            ||
| 95 |         if (!$this->supportsValue($imageValue)) { | 
            ||
| 96 |             throw new InvalidArgumentException("Value for field #$fieldId ($fieldDefIdentifier) cannot be used for image alias generation."); | 
            ||
| 97 | }  | 
            ||
| 98 | |||
| 99 | $originalPath = $imageValue->id;  | 
            ||
| 100 | |||
| 101 | $variationWidth = $variationHeight = null;  | 
            ||
| 102 | // Create the image alias only if it does not already exist.  | 
            ||
| 103 |         if ($variationName !== IORepositoryResolver::VARIATION_ORIGINAL && !$this->ioResolver->isStored($originalPath, $variationName)) { | 
            ||
| 104 |             try { | 
            ||
| 105 | $originalBinary = $this->dataLoader->find($originalPath);  | 
            ||
| 106 |             } catch (NotLoadableException $e) { | 
            ||
| 107 | throw new SourceImageNotFoundException($originalPath, 0, $e);  | 
            ||
| 108 | }  | 
            ||
| 109 | |||
| 110 |             $this->logger->debug("Generating '$variationName' variation on $originalPath, field #$fieldId ($fieldDefIdentifier)"); | 
            ||
| 111 | |||
| 112 | $this->ioResolver->store(  | 
            ||
| 113 | $this->applyFilter($originalBinary, $variationName),  | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 114 | $originalPath,  | 
            ||
| 115 | $variationName  | 
            ||
| 116 | );  | 
            ||
| 117 |         } else { | 
            ||
| 118 |             if ($variationName === IORepositoryResolver::VARIATION_ORIGINAL) { | 
            ||
| 119 | $variationWidth = $imageValue->width;  | 
            ||
| 120 | $variationHeight = $imageValue->height;  | 
            ||
| 121 | }  | 
            ||
| 122 |             $this->logger->debug("'$variationName' variation on $originalPath is already generated. Loading from cache."); | 
            ||
| 123 | }  | 
            ||
| 124 | |||
| 125 |         try { | 
            ||
| 126 | $aliasInfo = new SplFileInfo(  | 
            ||
| 127 | $this->ioResolver->resolve($originalPath, $variationName)  | 
            ||
| 128 | );  | 
            ||
| 129 |         } catch (NotResolvableException $e) { | 
            ||
| 130 | // If for some reason image alias cannot be resolved, throw the appropriate exception.  | 
            ||
| 131 | throw new InvalidVariationException($variationName, 'image', 0, $e);  | 
            ||
| 132 |         } catch (RuntimeException $e) { | 
            ||
| 133 | throw new InvalidVariationException($variationName, 'image', 0, $e);  | 
            ||
| 134 | }  | 
            ||
| 135 | |||
| 136 | return new ImageVariation(  | 
            ||
| 137 | [  | 
            ||
| 138 | 'name' => $variationName,  | 
            ||
| 139 | 'fileName' => $aliasInfo->getFilename(),  | 
            ||
| 140 | 'dirPath' => $aliasInfo->getPath(),  | 
            ||
| 141 | 'uri' => $aliasInfo->getPathname(),  | 
            ||
| 142 | 'imageId' => $imageValue->imageId,  | 
            ||
| 143 | 'width' => $variationWidth,  | 
            ||
| 144 | 'height' => $variationHeight,  | 
            ||
| 145 | ]  | 
            ||
| 146 | );  | 
            ||
| 147 | }  | 
            ||
| 148 | |||
| 178 | 
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.