| Conditions | 13 |
| Paths | 12 |
| Total Lines | 62 |
| 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 |
||
| 23 | public function run($request) |
||
| 24 | { |
||
| 25 | echo "<style>table {width: 100%;} th, td {padding: 5px; font-size: 12px; border: 1px solid #ccc; vertical-align: top;}</style>"; |
||
| 26 | $minutes = intval($request->getVar("m"))-0; |
||
| 27 | if ($request->getVar("m") === $minutes) { |
||
| 28 | //do nothing |
||
| 29 | } else { |
||
| 30 | $tsFrom = strtotime($request->getVar("m")); |
||
| 31 | if ($tsFrom) { |
||
| 32 | $tsUntil = strtotime("NOW"); |
||
| 33 | $minutes = round(($tsUntil - $tsFrom) / 60); |
||
| 34 | } |
||
| 35 | } |
||
| 36 | if ($minutes) { |
||
| 37 | $ts = strtotime($minutes." minutes ago"); |
||
| 38 | $date = date(DATE_RFC2822, $ts); |
||
| 39 | echo "<hr /><h3>changes in the last ".$this->minutesToTime($minutes)."<br />from: ".$date."<br />make sure you see THE END at the bottom of this list</h3><hr />"; |
||
| 40 | $whereStatementFixed = "UNIX_TIMESTAMP(\"LastEdited\") > ".$ts." "; |
||
| 41 | $dataClasses = ClassInfo::subclassesFor('DataObject'); |
||
| 42 | array_shift($dataClasses); |
||
| 43 | foreach ($dataClasses as $dataClass) { |
||
| 44 | if (class_exists($dataClass)) { |
||
| 45 | $singleton = Injector::inst()->get($dataClass); |
||
| 46 | if ($singleton instanceof TestOnly) { |
||
| 47 | //do nothing |
||
| 48 | } else { |
||
| 49 | $whereStatement = $whereStatementFixed." AND \"ClassName\" = '".$dataClass."' "; |
||
| 50 | $count = $dataClass::get()->where($whereStatement)->count(); |
||
| 51 | $fields = Config::inst()->get($dataClass, "db", Config::INHERITED); |
||
| 52 | if (!is_array($fields)) { |
||
| 53 | $fields = array(); |
||
| 54 | } |
||
| 55 | $fields = array("ID" => "Int", "Created" => "SS_DateAndTime", "LastEdited" => "SS_DateAndTime")+$fields; |
||
| 56 | if ($count) { |
||
| 57 | echo "<h2>".$singleton->singular_name()."(".$count.")</h2>"; |
||
| 58 | $objects = $dataClass::get()->where($whereStatement)->limit(1000); |
||
| 59 | foreach ($objects as $object) { |
||
| 60 | echo "<h4>".$object->getTitle()."</h4><ul>"; |
||
| 61 | if (count($fields)) { |
||
| 62 | $array = array(); |
||
|
|
|||
| 63 | foreach ($fields as $field => $typeOfField) { |
||
| 64 | echo "<li><strong>".$field."</strong><pre>\t\t".htmlentities($object->$field)."</pre></li>"; |
||
| 65 | } |
||
| 66 | } |
||
| 67 | echo "</ul>"; |
||
| 68 | } |
||
| 69 | echo "</blockquote>"; |
||
| 70 | } |
||
| 71 | } |
||
| 72 | } |
||
| 73 | } |
||
| 74 | echo "<hr /><h1>-------- THE END --------</h1>"; |
||
| 75 | } |
||
| 76 | if (empty($_GET["m"])) { |
||
| 77 | $_GET["m"] = 0; |
||
| 78 | } |
||
| 79 | echo " |
||
| 80 | <form method=\"get\" action=\"".Director::absoluteURL("dev/tasks/".$this->class."/")."\"> |
||
| 81 | <label for=\"m\">please enter minutes ago or any date (e.g. last week, yesterday, 2011-11-11, etc...)</label> |
||
| 82 | <input name=\"m\" id=\"m\" value=\"".$_GET["m"]."\"> |
||
| 83 | </form>"; |
||
| 84 | } |
||
| 85 | |||
| 94 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.