Conditions | 8 |
Paths | 8 |
Total Lines | 74 |
Code Lines | 52 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
43 | public function handleAjax(Doku_Event $event, $param) |
||
44 | { |
||
45 | if ($event->data !== 'plugin_prosemirror') { |
||
46 | return; |
||
47 | } |
||
48 | $event->preventDefault(); |
||
49 | $event->stopPropagation(); |
||
50 | |||
51 | global $INPUT, $ID; |
||
52 | $ID = $INPUT->str('id'); |
||
53 | $responseData = []; |
||
54 | foreach ($INPUT->arr('actions') as $action) { |
||
55 | switch ($action) { |
||
56 | case 'resolveInternalLink': |
||
57 | { |
||
58 | $inner = $INPUT->str('inner'); |
||
59 | $responseData[$action] = $this->resolveInternalLink($inner, $ID); |
||
60 | break; |
||
61 | } |
||
62 | case 'resolveInterWikiLink': |
||
63 | { |
||
64 | $inner = $INPUT->str('inner'); |
||
65 | list($shortcut, $reference) = explode('>', $inner); |
||
66 | $responseData[$action] = $this->resolveInterWikiLink($shortcut, $reference); |
||
67 | break; |
||
68 | } |
||
69 | case 'resolveMedia': |
||
70 | { |
||
71 | $attrs = $INPUT->arr('attrs'); |
||
72 | $responseData[$action] = [ |
||
73 | 'data-resolvedHtml' => \dokuwiki\plugin\prosemirror\parser\ImageNode::resolveMedia( |
||
74 | $attrs['id'], |
||
75 | $attrs['title'], |
||
76 | $attrs['align'], |
||
77 | $attrs['width'], |
||
78 | $attrs['height'], |
||
79 | $attrs['cache'], |
||
80 | $attrs['linking'] |
||
81 | ) |
||
82 | ]; |
||
83 | break; |
||
84 | } |
||
85 | case 'resolveImageTitle': |
||
86 | { |
||
87 | $image = $INPUT->arr('image'); |
||
88 | $responseData[$action] = []; |
||
89 | $responseData[$action]['data-resolvedImage'] = LinkNode::resolveImageTitle( |
||
90 | $ID, |
||
91 | $image['id'], |
||
92 | $image['title'], |
||
93 | $image['align'], |
||
94 | $image['width'], |
||
95 | $image['height'], |
||
96 | $image['cache'] |
||
97 | ); |
||
98 | break; |
||
99 | } |
||
100 | case 'resolveRSS': |
||
101 | { |
||
102 | $attrs = json_decode($INPUT->str('attrs'), true); |
||
103 | $responseData[$action] = \dokuwiki\plugin\prosemirror\parser\RSSNode::renderAttrsToHTML($attrs); |
||
104 | break; |
||
105 | } |
||
106 | default: |
||
107 | { |
||
108 | dbglog('Unknown action: ' . $action, __FILE__ . ': ' . __LINE__); |
||
109 | http_status(400, 'unknown action'); |
||
110 | return; |
||
111 | } |
||
112 | } |
||
113 | } |
||
114 | |||
115 | header('Content-Type: application/json'); |
||
116 | echo json_encode($responseData); |
||
117 | } |
||
214 |