Conditions | 13 |
Paths | 288 |
Total Lines | 56 |
Code Lines | 34 |
Lines | 0 |
Ratio | 0 % |
Changes | 10 | ||
Bugs | 0 | Features | 3 |
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 |
||
21 | public function run($request) |
||
22 | { |
||
23 | Environment::increaseTimeLimitTo(300); |
||
24 | Environment::setMemoryLimitMax(-1); |
||
25 | Environment::increaseMemoryLimitTo(-1); |
||
26 | $debug = $request->postVar('debug') ? 'checked="checked"' : ''; |
||
27 | $word = $request->requestVar('word'); |
||
28 | if (! is_string($word)) { |
||
29 | $word = ''; |
||
30 | } |
||
31 | |||
32 | $replace = $request->requestVar('replace'); |
||
33 | if (! is_string($replace)) { |
||
34 | $replace = ''; |
||
35 | } |
||
36 | |||
37 | $html = ' |
||
38 | <form methd="post" action=""> |
||
39 | <h2>Enter Search Word(s):</h2> |
||
40 | <h3>Find</h3> |
||
41 | <input name="word" value="' . Convert::raw2att($word) . '" style="width: 500px; padding: 5px;" /> |
||
42 | <h3>Replace (optional)</h3> |
||
43 | <input name="replace" value="' . Convert::raw2att($replace) . '" style="width: 500px; padding: 5px;" /> |
||
44 | <h3>Do it now ... (careful)</h3> |
||
45 | <input type="submit" value="search OR search and replace" style="width: 250px; padding: 5px;" /> |
||
46 | <br /> |
||
47 | <br />debug: <input name="debug" type="checkbox" ' . $debug . ' /> |
||
48 | </form> |
||
49 | '; |
||
50 | echo $html; |
||
51 | $api = SearchApi::create(); |
||
52 | if ($debug !== '' && $debug !== '0') { |
||
53 | $api->setDebug(true); |
||
54 | } |
||
55 | |||
56 | $api->setWordsAsString($word); |
||
57 | $links = $api->getLinks(); |
||
58 | echo '<h2>results</h2>'; |
||
59 | foreach ($links as $link) { |
||
60 | $item = $link->Object; |
||
61 | $title = $item->getTitle() . ' (' . $item->i18n_singular_name() . ')'; |
||
62 | if ($debug !== '' && $debug !== '0') { |
||
63 | $title .= ' Class: ' . $item->ClassName . ', ID: ' . $item->ID . ', Sort Value: ' . $link->SiteWideSearchSortValue; |
||
64 | } |
||
65 | |||
66 | $cmsEditLink = $link->HasCMSEditLink ? '<a href="' . $link->CMSEditLink . '">✎</a> ...' : 'x ...'; |
||
67 | if ($link->HasLink) { |
||
68 | DB::alteration_message($cmsEditLink . '<a href="' . $link->Link . '">' . $title . '</a> - ', 'created'); |
||
69 | } else { |
||
70 | DB::alteration_message($cmsEditLink . $title, 'obsolete'); |
||
71 | } |
||
72 | } |
||
73 | |||
74 | if ($replace !== '' && $replace !== '0') { |
||
75 | $api->doReplacement($word, $replace); |
||
76 | $api->setDebug(true); |
||
77 | } |
||
80 |