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