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