| Conditions | 11 |
| Paths | 19 |
| Total Lines | 45 |
| 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 |
||
| 55 | public function run($request) |
||
| 56 | { |
||
| 57 | if (!Director::isDev() || Director::isLive()) { |
||
| 58 | DB::alteration_message('you can only run this in dev mode!'); |
||
| 59 | } else { |
||
| 60 | if (!isset($_REQUEST['i-am-sure'])) { |
||
| 61 | $_REQUEST['i-am-sure'] = ''; |
||
| 62 | } |
||
| 63 | if ('yes' != $_REQUEST['i-am-sure']) { |
||
| 64 | die("<h1>ARE YOU SURE?</h1><br /><br /><br /> please add the 'i-am-sure' get variable to your request and set it to 'yes' ... e.g. <br />http://www.mysite.com/dev/ecommerce/ecommercetaskdeleteallorders/?i-am-sure=yes"); |
||
| 65 | } |
||
| 66 | $oldCarts = Order::get(); |
||
| 67 | $count = 0; |
||
| 68 | if ($oldCarts->count()) { |
||
| 69 | if ($this->verbose) { |
||
| 70 | $totalToDeleteSQLObject = DB::query('SELECT COUNT(*) FROM "Order"'); |
||
| 71 | $totalToDelete = $totalToDeleteSQLObject->value(); |
||
| 72 | DB::alteration_message('<h2>Total number of orders: '.$totalToDelete.' .... now deleting: </h2>', 'deleted'); |
||
| 73 | } |
||
| 74 | foreach ($oldCarts as $oldCart) { |
||
| 75 | ++$count; |
||
| 76 | if ($this->verbose) { |
||
| 77 | DB::alteration_message("$count ... deleting abandonned order #".$oldCart->ID, 'deleted'); |
||
| 78 | } |
||
| 79 | $oldCart->delete(); |
||
| 80 | $oldCart->destroy(); |
||
| 81 | } |
||
| 82 | } else { |
||
| 83 | if ($this->verbose) { |
||
| 84 | $count = DB::query('SELECT COUNT("ID") FROM "Order"')->value(); |
||
| 85 | DB::alteration_message("There are no abandonned orders. There are $count 'live' Orders.", 'created'); |
||
| 86 | } |
||
| 87 | } |
||
| 88 | $countCheck = DB::query('Select COUNT(ID) FROM "Order"')->value(); |
||
| 89 | if ($countCheck) { |
||
| 90 | DB::alteration_message('ERROR: in testing <i>Orders</i> it appears there are '.$countCheck.' records left.', 'deleted'); |
||
| 91 | } else { |
||
| 92 | DB::alteration_message('PASS: in testing <i>Orders</i> there seem to be no records left.', 'created'); |
||
| 93 | } |
||
| 94 | $this->cleanupUnlinkedOrderObjects(); |
||
| 95 | $this->doubleCheckModifiersAndItems(); |
||
| 96 | |||
| 97 | return $count; |
||
| 98 | } |
||
| 99 | } |
||
| 100 | |||
| 178 |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.