Conditions | 4 |
Paths | 4 |
Total Lines | 164 |
Code Lines | 127 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 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 |
||
140 | public function addAddtionalForms(Event $event) |
||
141 | { |
||
142 | if (!$this->allowWYSIWYG()) { |
||
143 | return; |
||
144 | } |
||
145 | |||
146 | if (!in_array($event->data, ['edit', 'preview'])) { |
||
147 | return; |
||
148 | } |
||
149 | |||
150 | $linkForm = new Form([ |
||
151 | 'class' => 'plugin_prosemirror_linkform', |
||
152 | 'id' => 'prosemirror-linkform', |
||
153 | 'style' => 'display: none;', |
||
154 | ]); |
||
155 | $linkForm->addFieldsetOpen('Links')->addClass('js-link-fieldset'); |
||
156 | $iwOptions = array_keys(getInterwiki()); |
||
157 | $linkForm->addDropdown('iwshortcut', $iwOptions, 'InterWiki')->attr('required', 'required'); |
||
158 | |||
159 | $linkForm->addButtonHTML('linkwiz', inlineSVG(DOKU_PLUGIN . 'prosemirror/images/link.svg'))->attrs([ |
||
160 | 'type' => 'button', |
||
161 | 'class' => 'js-open-linkwiz linkform_linkwiz' |
||
162 | ]); |
||
163 | $linkForm->addTextInput('linktarget', $this->getLang('link target'))->attrs( |
||
164 | [ |
||
165 | 'required' => 'required', |
||
166 | 'autofocus' => 'autofocus', |
||
167 | ] |
||
168 | ); |
||
169 | |||
170 | $linkForm->addTagOpen('div')->addClass('radio-wrapper'); |
||
171 | $linkForm->addTagOpen('fieldset'); |
||
172 | $linkForm->addTagOpen('legend'); |
||
173 | $linkForm->addHTML('Link Type'); |
||
174 | $linkForm->addTagClose('legend'); |
||
175 | $linkForm->addRadioButton('linktype', $this->getLang('type:wiki page'))->val('internallink'); |
||
176 | $linkForm->addRadioButton('linktype', $this->getLang('type:interwiki'))->val('interwikilink'); |
||
177 | $linkForm->addRadioButton('linktype', $this->getLang('type:email'))->val('emaillink'); |
||
178 | $linkForm->addRadioButton('linktype', $this->getLang('type:external')) |
||
179 | ->val('externallink') |
||
180 | ->attr('checked', 'checked'); |
||
181 | $linkForm->addRadioButton('linktype', $this->getLang('type:other'))->val('other'); |
||
182 | $linkForm->addTagClose('fieldset'); |
||
183 | $linkForm->addTagClose('div'); |
||
184 | |||
185 | $linkForm->addTagOpen('div')->addClass('radio-wrapper'); |
||
186 | $linkForm->addTagOpen('fieldset'); |
||
187 | $linkForm->addTagOpen('legend'); |
||
188 | $linkForm->addHTML('Link Name Type'); |
||
189 | $linkForm->addTagClose('legend'); |
||
190 | $linkForm->addRadioButton('nametype', $this->getLang('type:automatic title')) |
||
191 | ->val('automatic') |
||
192 | ->attr('checked', 'checked'); |
||
193 | $linkForm->addRadioButton('nametype', $this->getLang('type:custom title'))->val('custom'); |
||
194 | $linkForm->addRadioButton('nametype', $this->getLang('type:image'))->val('image'); |
||
195 | $linkForm->addTextInput('linkname', 'Link name')->attr('placeholder', $this->getLang('placeholder:link name')); |
||
196 | $linkForm->addTagOpen('div')->addClass('js-media-wrapper'); |
||
197 | $linkForm->addTagClose('div'); |
||
198 | $linkForm->addTagClose('fieldset'); |
||
199 | $linkForm->addTagClose('div'); |
||
200 | |||
201 | |||
202 | $linkForm->addFieldsetClose(); |
||
203 | $linkForm->addButton('ok-button', 'OK')->attr('type', 'submit'); |
||
204 | $linkForm->addButton('cancel-button', $this->getLang('cancel'))->attr('type', 'button'); |
||
205 | |||
206 | echo $linkForm->toHTML(); |
||
207 | |||
208 | $mediaForm = new Form([ |
||
209 | 'class' => 'plugin_prosemirror_mediaform', |
||
210 | 'id' => 'prosemirror-mediaform', |
||
211 | 'style' => 'display: none;', |
||
212 | ]); |
||
213 | $mediaForm->addFieldsetOpen($this->getLang('legend:media'))->addClass('js-media-fieldset'); |
||
214 | $mediaForm->addButtonHTML( |
||
215 | 'mediamanager', |
||
216 | inlineSVG(DOKU_PLUGIN . 'prosemirror/images/file-image-outline.svg') |
||
217 | )->attrs([ |
||
218 | 'type' => 'button', |
||
219 | 'class' => 'js-open-mediamanager mediaform_mediamanager' |
||
220 | ]); |
||
221 | $mediaForm->addTextInput('mediatarget', $this->getLang('media target'))->attrs( |
||
222 | [ |
||
223 | 'required' => 'required', |
||
224 | 'autofocus' => 'autofocus', |
||
225 | ] |
||
226 | ); |
||
227 | $mediaForm->addTextInput('mediacaption', $this->getLang('label:caption')); |
||
228 | |||
229 | $mediaForm->addTagOpen('div')->addClass('image-properties'); |
||
230 | $mediaForm->addTagOpen('p'); |
||
231 | $mediaForm->addHTML($this->getLang('label:image_properties')); |
||
232 | $mediaForm->addTagClose('p'); |
||
233 | |||
234 | $mediaForm->addTagOpen('div')->addClass('input-wrapper'); |
||
235 | $mediaForm->addTagOpen('fieldset'); |
||
236 | $mediaForm->addTagOpen('legend'); |
||
237 | $mediaForm->addHTML($this->getLang('legend:size')); |
||
238 | $mediaForm->addTagClose('legend'); |
||
239 | $mediaForm->addTextInput('width', $this->getLang('label:width'))->attr('type', 'number'); |
||
240 | $mediaForm->addTextInput('height', $this->getLang('label:height'))->attr('type', 'number'); |
||
241 | $mediaForm->addTagClose('fieldset'); |
||
242 | $mediaForm->addTagClose('div'); |
||
243 | |||
244 | $mediaForm->addTagOpen('div')->addClass('input-wrapper'); |
||
245 | $mediaForm->addTagOpen('fieldset'); |
||
246 | $mediaForm->addTagOpen('legend'); |
||
247 | $mediaForm->addHTML($this->getLang('legend:alignment')); |
||
248 | $mediaForm->addTagClose('legend'); |
||
249 | $mediaForm->addRadioButton('alignment', $this->getLang('label:default alignment')) |
||
250 | ->val('') |
||
251 | ->attr('checked', 'checked'); |
||
252 | $mediaForm->addRadioButton('alignment', $this->getLang('label:float left'))->val('left'); |
||
253 | $mediaForm->addRadioButton('alignment', $this->getLang('label:center alignment'))->val('center'); |
||
254 | $mediaForm->addRadioButton('alignment', $this->getLang('label:float right'))->val('right'); |
||
255 | $mediaForm->addTagClose('fieldset'); |
||
256 | $mediaForm->addTagClose('div'); |
||
257 | |||
258 | $mediaForm->addTagOpen('div')->addClass('input-wrapper'); |
||
259 | $mediaForm->addTagOpen('fieldset'); |
||
260 | $mediaForm->addTagOpen('legend'); |
||
261 | $mediaForm->addHTML($this->getLang('legend:linking')); |
||
262 | $mediaForm->addTagClose('legend'); |
||
263 | $mediaForm->addRadioButton('linking', $this->getLang('label:default linking')) |
||
264 | ->val('details') |
||
265 | ->attr('checked', 'checked'); |
||
266 | $mediaForm->addRadioButton('linking', $this->getLang('label:direct linking'))->val('direct'); |
||
267 | $mediaForm->addRadioButton('linking', $this->getLang('label:nolink'))->val('nolink'); |
||
268 | $mediaForm->addRadioButton('linking', $this->getLang('label:linkonly'))->val('linkonly'); |
||
269 | $mediaForm->addTagClose('fieldset'); |
||
270 | $mediaForm->addTagClose('div'); |
||
271 | |||
272 | $mediaForm->addTagOpen('div')->addClass('input-wrapper'); |
||
273 | $mediaForm->addTagOpen('fieldset'); |
||
274 | $mediaForm->addTagOpen('legend'); |
||
275 | $mediaForm->addHTML($this->getLang('legend:caching')); |
||
276 | $mediaForm->addTagClose('legend'); |
||
277 | $mediaForm->addRadioButton('caching', $this->getLang('label:default caching')) |
||
278 | ->val('') |
||
279 | ->attr('checked', 'checked'); |
||
280 | $mediaForm->addRadioButton('caching', $this->getLang('label:recache'))->val('recache'); |
||
281 | $mediaForm->addRadioButton('caching', $this->getLang('label:nocache'))->val('nocache'); |
||
282 | $mediaForm->addTagClose('fieldset'); |
||
283 | $mediaForm->addTagClose('div'); |
||
284 | |||
285 | $mediaForm->addTagClose('div'); // end of image-properties |
||
286 | |||
287 | $mediaForm->addFieldsetClose(); |
||
288 | $mediaForm->addButton('ok-button', 'OK')->attr('type', 'submit'); |
||
289 | $mediaForm->addButton('cancel-button', $this->getLang('cancel'))->attr('type', 'button'); |
||
290 | |||
291 | // dynamic image hack? https://www.dokuwiki.org/images#dynamic_images |
||
292 | |||
293 | echo $mediaForm->toHTML(); |
||
294 | |||
295 | // phpcs:disable |
||
296 | $languages = explode(' ', '4cs 6502acme 6502kickass 6502tasm 68000devpac abap actionscript3 actionscript ada aimms algol68 apache applescript apt_sources arm asm asp asymptote autoconf autohotkey autoit avisynth awk bascomavr bash basic4gl batch bf biblatex bibtex blitzbasic bnf boo caddcl cadlisp ceylon cfdg cfm chaiscript chapel cil c_loadrunner clojure c_mac cmake cobol coffeescript c cpp cpp-qt cpp-winapi csharp css cuesheet c_winapi dart dcl dcpu16 dcs delphi diff div dos dot d ecmascript eiffel email epc e erlang euphoria ezt f1 falcon fo fortran freebasic freeswitch fsharp gambas gdb genero genie gettext glsl gml gnuplot go groovy gwbasic haskell haxe hicest hq9plus html html4strict html5 icon idl ini inno intercal io ispfpanel java5 java javascript jcl j jquery julia kixtart klonec klonecpp kotlin latex lb ldif lisp llvm locobasic logtalk lolcode lotusformulas lotusscript lscript lsl2 lua m68k magiksf make mapbasic mathematica matlab mercury metapost mirc mk-61 mmix modula2 modula3 mpasm mxml mysql nagios netrexx newlisp nginx nimrod nsis oberon2 objc objeck ocaml-brief ocaml octave oobas oorexx oracle11 oracle8 oxygene oz parasail parigp pascal pcre perl6 perl per pf phix php-brief php pic16 pike pixelbender pli plsql postgresql postscript povray powerbuilder powershell proftpd progress prolog properties providex purebasic pycon pys60 python qbasic qml q racket rails rbs rebol reg rexx robots rpmspec rsplus ruby rust sas sass scala scheme scilab scl sdlbasic smalltalk smarty spark sparql sql standardml stonescript swift systemverilog tclegg tcl teraterm texgraph text thinbasic tsql twig typoscript unicon upc urbi uscript vala vbnet vb vbscript vedit verilog vhdl vim visualfoxpro visualprolog whitespace whois winbatch xbasic xml xojo xorg_conf xpp yaml z80 zxbasic'); |
||
297 | // phpcs:enable |
||
298 | $datalistHTML = '<datalist id="codelanguages">'; |
||
299 | foreach ($languages as $language) { |
||
300 | $datalistHTML .= "<option value=\"$language\">"; |
||
301 | } |
||
302 | $datalistHTML .= '</datalist>'; |
||
303 | echo $datalistHTML; |
||
304 | } |
||
338 |
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: