| Conditions | 6 |
| Paths | 6 |
| Total Lines | 81 |
| Code Lines | 60 |
| Lines | 10 |
| Ratio | 12.35 % |
| 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 |
||
| 172 | protected function getEditFormFields($context) |
||
| 173 | { |
||
| 174 | // Check if the url is valid |
||
| 175 | $url = (isset($context['url'])) ? $context['url'] : null; |
||
| 176 | if (empty($url)) { |
||
| 177 | return $this->getCreateFormFields(); |
||
| 178 | } |
||
| 179 | |||
| 180 | // Get embed |
||
| 181 | $this->validateUrl($url); |
||
| 182 | $embed = new EmbedResource($url); |
||
| 183 | |||
| 184 | // Build form |
||
| 185 | $alignments = array( |
||
| 186 | 'leftAlone' => _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.AlignmentLeftAlone', 'Left'), |
||
| 187 | 'center' => _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.AlignmentCenter', 'Center'), |
||
| 188 | 'rightAlone' => _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.AlignmentRightAlone', 'Right'), |
||
| 189 | 'left' => _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.AlignmentLeft', 'Left wrap'), |
||
| 190 | 'right' => _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.AlignmentRight', 'Right wrap'), |
||
| 191 | ); |
||
| 192 | |||
| 193 | $width = $embed->getWidth(); |
||
| 194 | $height = $embed->getHeight(); |
||
| 195 | |||
| 196 | $fields = CompositeField::create([ |
||
| 197 | LiteralField::create( |
||
| 198 | 'Preview', |
||
| 199 | sprintf( |
||
| 200 | '<img src="%s" class="%s" />', |
||
| 201 | $embed->getPreviewURL(), |
||
| 202 | 'insert-embed-modal__preview' |
||
| 203 | ) |
||
| 204 | )->addExtraClass('insert-embed-modal__preview-container'), |
||
| 205 | HiddenField::create('PreviewUrl', 'PreviewUrl', $embed->getPreviewURL()), |
||
| 206 | CompositeField::create([ |
||
| 207 | TextField::create('UrlPreview', $embed->getName(), $url) |
||
| 208 | ->setReadonly(true), |
||
| 209 | HiddenField::create('Url', false, $url), |
||
| 210 | TextField::create( |
||
| 211 | 'CaptionText', |
||
| 212 | _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.Caption', 'Caption') |
||
| 213 | ), |
||
| 214 | OptionsetField::create( |
||
| 215 | 'Placement', |
||
| 216 | _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.Placement', 'Placement'), |
||
| 217 | $alignments |
||
| 218 | ) |
||
| 219 | ->addExtraClass('insert-embed-modal__placement'), |
||
| 220 | $dimensions = FieldGroup::create( |
||
| 221 | _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.ImageSpecs', 'Dimensions'), |
||
| 222 | TextField::create('Width', '', $width) |
||
| 223 | ->setRightTitle(_t( |
||
| 224 | 'SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.ImageWidth', |
||
| 225 | 'Width' |
||
| 226 | )) |
||
| 227 | ->setMaxLength(5) |
||
| 228 | ->addExtraClass('flexbox-area-grow'), |
||
| 229 | TextField::create('Height', '', $height) |
||
| 230 | ->setRightTitle(_t( |
||
| 231 | 'SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.ImageHeight', |
||
| 232 | 'Height' |
||
| 233 | )) |
||
| 234 | ->setMaxLength(5) |
||
| 235 | ->addExtraClass('flexbox-area-grow') |
||
| 236 | )->addExtraClass('fieldgroup--fill-width') |
||
| 237 | ->setName('Dimensions') |
||
| 238 | ])->addExtraClass('flexbox-area-grow'), |
||
| 239 | ])->addExtraClass('insert-embed-modal__fields--fill-width'); |
||
| 240 | |||
| 241 | View Code Duplication | if ($dimensions && $width && $height) { |
|
| 242 | $ratio = $width / $height; |
||
| 243 | |||
| 244 | $dimensions->setSchemaComponent('ProportionConstraintField'); |
||
| 245 | $dimensions->setSchemaState([ |
||
| 246 | 'data' => [ |
||
| 247 | 'ratio' => $ratio |
||
| 248 | ] |
||
| 249 | ]); |
||
| 250 | } |
||
| 251 | return FieldList::create($fields); |
||
| 252 | } |
||
| 253 | } |
||
| 254 |
This check marks private properties in classes that are never used. Those properties can be removed.