| Conditions | 13 |
| Paths | 288 |
| Total Lines | 55 |
| Code Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 11 | ||
| 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 = trim($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 $item) { |
||
| 60 | $title = $item->Title . ' (' . $item->SingularName . ')'; |
||
| 61 | if ($debug !== '' && $debug !== '0') { |
||
| 62 | $title .= ' Class: ' . $item->ClassName . ', ID: ' . $item->ID . ', Sort Value: ' . $item->SiteWideSearchSortValue; |
||
| 63 | } |
||
| 64 | |||
| 65 | $cmsEditLink = $item->HasCMSEditLink ? '<a href="' . $item->CMSEditLink . '">✎</a> ...' : 'x ...'; |
||
| 66 | if ($item->HasLink) { |
||
| 67 | DB::alteration_message($cmsEditLink . '<a href="' . $item->Link . '">' . $title . '</a> - ', 'created'); |
||
| 68 | } else { |
||
| 69 | DB::alteration_message($cmsEditLink . $title, 'obsolete'); |
||
| 70 | } |
||
| 71 | } |
||
| 72 | |||
| 73 | if ($replace !== '' && $replace !== '0') { |
||
| 74 | $api->setDebug(true); |
||
| 75 | $api->doReplacement($word, $replace); |
||
| 76 | } |
||
| 79 |