Conditions | 21 |
Paths | 2113 |
Total Lines | 64 |
Code Lines | 40 |
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 |
||
81 | public function render() |
||
82 | { |
||
83 | if (($this->arguments['src'] === '' && $this->arguments['image'] === null) || ($this->arguments['src'] !== '' && $this->arguments['image'] !== null)) { |
||
84 | throw new Exception('You must either specify a string src or a File object.', 1533290762); |
||
85 | } |
||
86 | |||
87 | try { |
||
88 | $image = $this->getImageService()->getImage((string)$this->arguments['src'], $this->arguments['image'], (bool)$this->arguments['treatIdAsReference']); |
||
89 | |||
90 | $cropString = $this->arguments['crop']; |
||
91 | if ($cropString === null && $image->hasProperty('crop') && $image->getProperty('crop')) { |
||
92 | $cropString = $image->getProperty('crop'); |
||
93 | } |
||
94 | $cropVariantCollection = CropVariantCollection::create((string)$cropString); |
||
95 | $cropVariant = $this->arguments['cropVariant'] ?: 'default'; |
||
96 | $cropArea = $cropVariantCollection->getCropArea($cropVariant); |
||
97 | $processingInstructions = []; |
||
98 | if (!$cropArea->isEmpty()) { |
||
99 | $processingInstructions['crop'] = $cropArea->makeAbsoluteBasedOnFile($image); |
||
100 | } |
||
101 | foreach (['width', 'height', 'minWidth', 'minHeight', 'maxWidth', 'maxHeight'] as $argument) { |
||
102 | if (!empty($this->arguments[$argument])) { |
||
103 | $processingInstructions[$argument] = $this->arguments[$argument]; |
||
104 | } |
||
105 | } |
||
106 | |||
107 | $processedFile = $image->process($this->arguments['context'], $processingInstructions); |
||
|
|||
108 | $imageUri = PathUtility::getAbsoluteWebPath($processedFile->getPublicUrl()); |
||
109 | |||
110 | if (!$this->tag->hasAttribute('data-focus-area')) { |
||
111 | $focusArea = $cropVariantCollection->getFocusArea($cropVariant); |
||
112 | if (!$focusArea->isEmpty()) { |
||
113 | $this->tag->addAttribute('data-focus-area', $focusArea->makeAbsoluteBasedOnFile($image)); |
||
114 | } |
||
115 | } |
||
116 | $this->tag->addAttribute('src', $imageUri); |
||
117 | $this->tag->addAttribute('width', $processedFile->getProperty('width')); |
||
118 | $this->tag->addAttribute('height', $processedFile->getProperty('height')); |
||
119 | |||
120 | $alt = $image->getProperty('alternative'); |
||
121 | $title = $image->getProperty('title'); |
||
122 | |||
123 | // The alt-attribute is mandatory to have valid html-code, therefore add it even if it is empty |
||
124 | if (empty($this->arguments['alt'])) { |
||
125 | $this->tag->addAttribute('alt', $alt); |
||
126 | } |
||
127 | if (empty($this->arguments['title']) && $title) { |
||
128 | $this->tag->addAttribute('title', $title); |
||
129 | } |
||
130 | } catch (ResourceDoesNotExistException $e) { |
||
131 | // thrown if file does not exist |
||
132 | throw new Exception($e->getMessage(), 1533294109, $e); |
||
133 | } catch (\UnexpectedValueException $e) { |
||
134 | // thrown if a file has been replaced with a folder |
||
135 | throw new Exception($e->getMessage(), 1533294113, $e); |
||
136 | } catch (\RuntimeException $e) { |
||
137 | // RuntimeException thrown if a file is outside of a storage |
||
138 | throw new Exception($e->getMessage(), 1533294116, $e); |
||
139 | } catch (\InvalidArgumentException $e) { |
||
140 | // thrown if file storage does not exist |
||
141 | throw new Exception($e->getMessage(), 1533294120, $e); |
||
142 | } |
||
143 | |||
144 | return $this->tag->render(); |
||
145 | } |
||
147 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.