Conditions | 1 |
Paths | 1 |
Total Lines | 61 |
Code Lines | 41 |
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 |
||
94 | public function getCMSFields() { |
||
95 | $fields = parent::getCMSFields(); |
||
96 | $fields->removeByName(['Type', 'Mp4', 'WebM', 'Ogg', 'URL', 'AutoPlay']); |
||
97 | $fields->findOrMakeTab('Root.Media', $this->fieldLabel('Media')); |
||
98 | |||
99 | $fields->addFieldsToTab('Root.Media', [ |
||
100 | DropdownField::create('AutoPlay', $this->fieldLabel('TurnOnAutoPlayMode'), BlocksUtility::localized_answers()), |
||
101 | $videoType = OptionsetField::create('Type', $this->fieldLabel('Type'), $this->getSliderTypes(), 'File'), |
||
102 | $uploadFieldContainer = DisplayLogicWrapper::create( |
||
103 | $mp4UploadField = UploadField::create('Mp4', $this->fieldLabel('VideoMp4')), |
||
104 | $webMUploadField = UploadField::create('WebM', $this->fieldLabel('VideoWebM')), |
||
105 | $oggUploadField = UploadField::create('Ogg', $this->fieldLabel('VideoOgg')) |
||
106 | ), |
||
107 | $urlAddressField = TextField::create('URL', $this->fieldLabel('URLAddress'))->setRightTitle( |
||
108 | $this->fieldLabel('SetVideoURLAddress') |
||
109 | ), |
||
110 | ]); |
||
111 | |||
112 | $mp4UploadField |
||
113 | ->setAllowedMaxFileNumber(1) |
||
114 | ->setAllowedExtensions('mp4') |
||
115 | ->setRightTitle( |
||
116 | _t('VideoSliderItem.ALLOWED_FILE_EXTENSIONS', 'Allowed file extensions: {extensions}', [ |
||
117 | 'extensions' => '.mp4', |
||
118 | ]) |
||
119 | ) |
||
120 | ->setFolderName( |
||
121 | sprintf('%s/Video-Sliders', BaseBlock::config()->upload_directory) |
||
122 | ); |
||
123 | |||
124 | $webMUploadField |
||
125 | ->setAllowedMaxFileNumber(1) |
||
126 | ->setAllowedExtensions('webm') |
||
127 | ->setRightTitle( |
||
128 | _t('VideoSliderItem.ALLOWED_FILE_EXTENSIONS', 'Allowed file extensions: {extensions}', [ |
||
129 | 'extensions' => '.webm', |
||
130 | ]) |
||
131 | ) |
||
132 | ->setFolderName( |
||
133 | sprintf('%s/Video-Sliders', BaseBlock::config()->upload_directory) |
||
134 | ); |
||
135 | |||
136 | $oggUploadField |
||
137 | ->setAllowedMaxFileNumber(1) |
||
138 | ->setAllowedExtensions('ogg') |
||
139 | ->setRightTitle( |
||
140 | _t('VideoSliderItem.ALLOWED_FILE_EXTENSIONS', 'Allowed file extensions: {extensions}', [ |
||
141 | 'extensions' => '.ogg', |
||
142 | ]) |
||
143 | ) |
||
144 | ->setFolderName( |
||
145 | sprintf('%s/Video-Sliders', BaseBlock::config()->upload_directory) |
||
146 | ); |
||
147 | |||
148 | $uploadFieldContainer->displayIf('Type')->isEqualTo('File'); |
||
149 | $urlAddressField->displayIf('Type')->isNotEqualTo('File'); |
||
150 | |||
151 | $this->extend('updateCMSFields', $fields); |
||
152 | |||
153 | return $fields; |
||
154 | } |
||
155 | |||
248 | } |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.