| Conditions | 6 |
| Paths | 8 |
| Total Lines | 65 |
| Code Lines | 51 |
| 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 |
||
| 71 | protected function getFormFields($controller, $name, $context) |
||
| 72 | { |
||
| 73 | $fields = []; |
||
| 74 | $url = (isset($context['url'])) ? $context['url'] : null; |
||
| 75 | |||
| 76 | if ($context['type'] === 'create') { |
||
| 77 | $fields = [ |
||
| 78 | TextField::create('Url', |
||
| 79 | _t( |
||
| 80 | 'RemoteFileForm.UrlDescription', |
||
| 81 | 'Embed Youtube and Vimeo videos, images and other media directly from the web.' |
||
| 82 | ) |
||
| 83 | ) |
||
| 84 | ->addExtraClass('insert-embed-modal__url-create'), |
||
| 85 | ]; |
||
| 86 | } |
||
| 87 | |||
| 88 | if ($context['type'] === 'edit' && $url && $this->validateUrl($url)) { |
||
| 89 | $embed = $this->getEmbed($url); |
||
| 90 | $alignments = array( |
||
| 91 | 'leftAlone' => _t('AssetAdmin.AlignmentLeftAlone', 'Left'), |
||
| 92 | 'center' => _t('AssetAdmin.AlignmentCenter', 'Center'), |
||
| 93 | 'rightAlone' => _t('AssetAdmin.AlignmentRightAlone', 'Right'), |
||
| 94 | 'left' => _t('AssetAdmin.AlignmentLeft', 'Left wrap'), |
||
| 95 | 'right' => _t('AssetAdmin.AlignmentRight', 'Right wrap'), |
||
| 96 | ); |
||
| 97 | |||
| 98 | $fields = CompositeField::create([ |
||
| 99 | LiteralField::create( |
||
| 100 | 'Preview', |
||
| 101 | sprintf( |
||
| 102 | '<img src="%s" class="%s" />', |
||
| 103 | $embed->getPreviewURL(), |
||
| 104 | 'insert-embed-modal__preview' |
||
| 105 | ) |
||
| 106 | )->addExtraClass('insert-embed-modal__preview-container'), |
||
| 107 | HiddenField::create('PreviewUrl', 'PreviewUrl', $embed->getPreviewURL()), |
||
| 108 | CompositeField::create([ |
||
| 109 | TextField::create('UrlPreview', $embed->getName(), $url) |
||
| 110 | ->setReadonly(true), |
||
| 111 | HiddenField::create('Url', false, $url), |
||
| 112 | TextField::create('CaptionText', _t('AssetAdmin.Caption', 'Caption')), |
||
| 113 | OptionsetField::create( |
||
| 114 | 'Placement', |
||
| 115 | _t('AssetAdmin.Placement', 'Placement'), |
||
| 116 | $alignments |
||
| 117 | ) |
||
| 118 | ->addExtraClass('insert-embed-modal__placement'), |
||
| 119 | FieldGroup::create( |
||
| 120 | _t('AssetAdmin.ImageSpecs', 'Dimensions'), |
||
| 121 | TextField::create('Width', '', $embed->getWidth()) |
||
| 122 | ->setRightTitle(_t('AssetAdmin.ImageWidth', 'Width')) |
||
| 123 | ->setMaxLength(5) |
||
| 124 | ->addExtraClass('flexbox-area-grow'), |
||
| 125 | TextField::create('Height', '', $embed->getHeight()) |
||
| 126 | ->setRightTitle(_t('AssetAdmin.ImageHeight', 'Height')) |
||
| 127 | ->setMaxLength(5) |
||
| 128 | ->addExtraClass('flexbox-area-grow') |
||
| 129 | )->addExtraClass('fieldgroup--fill-width') |
||
| 130 | ])->addExtraClass('flexbox-area-grow'), |
||
| 131 | ])->addExtraClass('insert-embed-modal__fields--fill-width'); |
||
| 132 | } |
||
| 133 | |||
| 134 | return FieldList::create($fields); |
||
| 135 | } |
||
| 136 | |||
| 198 |
This check marks private properties in classes that are never used. Those properties can be removed.