Conditions | 9 |
Paths | 12 |
Total Lines | 81 |
Code Lines | 61 |
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 |
||
68 | protected function getFormFields($controller, $name, $context) |
||
69 | { |
||
70 | $fields = []; |
||
71 | $url = (isset($context['url'])) ? $context['url'] : null; |
||
72 | |||
73 | if ($context['type'] === 'create') { |
||
74 | $fields = [ |
||
75 | TextField::create( |
||
76 | 'Url', |
||
77 | _t( |
||
78 | 'SilverStripe\\AssetAdmin\\Forms\\RemoteFileFormFactory.UrlDescription', |
||
79 | 'Embed Youtube and Vimeo videos, images and other media directly from the web.' |
||
80 | ) |
||
81 | ) |
||
82 | ->addExtraClass('insert-embed-modal__url-create'), |
||
83 | ]; |
||
84 | } |
||
85 | |||
86 | if ($context['type'] === 'edit' && $url && $this->validateUrl($url)) { |
||
87 | $embed = $this->getEmbed($url); |
||
88 | $alignments = array( |
||
89 | 'leftAlone' => _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.AlignmentLeftAlone', 'Left'), |
||
90 | 'center' => _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.AlignmentCenter', 'Center'), |
||
91 | 'rightAlone' => _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.AlignmentRightAlone', 'Right'), |
||
92 | 'left' => _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.AlignmentLeft', 'Left wrap'), |
||
93 | 'right' => _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.AlignmentRight', 'Right wrap'), |
||
94 | ); |
||
95 | |||
96 | $width = $embed->getWidth(); |
||
97 | $height = $embed->getHeight(); |
||
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('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.Caption', 'Caption')), |
||
114 | OptionsetField::create( |
||
115 | 'Placement', |
||
116 | _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.Placement', 'Placement'), |
||
117 | $alignments |
||
118 | ) |
||
119 | ->addExtraClass('insert-embed-modal__placement'), |
||
120 | $dimensions = FieldGroup::create( |
||
121 | _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.ImageSpecs', 'Dimensions'), |
||
122 | TextField::create('Width', '', $width) |
||
123 | ->setRightTitle(_t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.ImageWidth', 'Width')) |
||
124 | ->setMaxLength(5) |
||
125 | ->addExtraClass('flexbox-area-grow'), |
||
126 | TextField::create('Height', '', $height) |
||
127 | ->setRightTitle(_t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.ImageHeight', 'Height')) |
||
128 | ->setMaxLength(5) |
||
129 | ->addExtraClass('flexbox-area-grow') |
||
130 | )->addExtraClass('fieldgroup--fill-width') |
||
131 | ->setName('Dimensions') |
||
132 | ])->addExtraClass('flexbox-area-grow'), |
||
133 | ])->addExtraClass('insert-embed-modal__fields--fill-width'); |
||
134 | |||
135 | View Code Duplication | if ($dimensions && $width && $height) { |
|
136 | $ratio = $width / $height; |
||
137 | |||
138 | $dimensions->setSchemaComponent('ProportionConstraintField'); |
||
139 | $dimensions->setSchemaState([ |
||
140 | 'data' => [ |
||
141 | 'ratio' => $ratio |
||
142 | ] |
||
143 | ]); |
||
144 | } |
||
145 | } |
||
146 | |||
147 | return FieldList::create($fields); |
||
148 | } |
||
149 | |||
211 |
This check marks private properties in classes that are never used. Those properties can be removed.