Conditions | 11 |
Paths | 168 |
Total Lines | 51 |
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 |
||
24 | public function run($request) |
||
25 | { |
||
26 | if ($this->verbose) { |
||
27 | set_time_limit(3600); |
||
28 | increase_time_limit_to(3600); |
||
29 | increase_memory_limit_to('512M'); |
||
30 | Config::inst()->update("GetLatLngFromGoogleUsingAddress", "debug", true); |
||
31 | } |
||
32 | if ($this->verbose) { |
||
33 | echo "<h1>============= Start =============</h1>"; |
||
34 | flush(); |
||
35 | ob_flush(); |
||
36 | } |
||
37 | if ($this->verbose) { |
||
38 | $objects = GoogleMapLocationsObject::get()->where("(Longitude IS NULL OR Latitude IS NULL) AND (Address IS NOT NULL AND Address <> '')")->count(); |
||
|
|||
39 | echo "<h3>============= Redoing $count Objects =============</h3>"; |
||
40 | flush(); |
||
41 | ob_flush(); |
||
42 | } |
||
43 | for ($i = 0; $i < 1000000; $i = $i + $this->step) { |
||
44 | $objects = GoogleMapLocationsObject::get()->where("(Longitude IS NULL OR Latitude IS NULL) AND (Address IS NOT NULL AND Address <> '')")->limit($this->step, $i); |
||
45 | if ($objects = GoogleMapLocationsObject::get()->where("(Longitude IS NULL OR Latitude IS NULL) AND (Address IS NOT NULL AND Address <> '')")->limit($this->step, $i)->count() == 0) { |
||
46 | $i = 99999999999; |
||
47 | } |
||
48 | foreach ($objects as $object) { |
||
49 | DB::alteration_message("<hr /><hr /><hr /><h1>Looking up ".$object->Address."</h1>"); |
||
50 | $object->FullAddress = ''; |
||
51 | $object->write(); |
||
52 | if ($object->Longitude) { |
||
53 | if ($this->verbose) { |
||
54 | DB::alteration_message(" --- found ".$object->FullAddress, "created"); |
||
55 | ; |
||
56 | flush(); |
||
57 | ob_flush(); |
||
58 | } |
||
59 | } else { |
||
60 | if ($this->verbose) { |
||
61 | DB::alteration_message(" --- not found ".$object->Address, "deleted"); |
||
62 | ; |
||
63 | flush(); |
||
64 | ob_flush(); |
||
65 | } |
||
66 | } |
||
67 | } |
||
68 | if ($this->verbose) { |
||
69 | echo "<h1>============= END =============</h1>"; |
||
70 | flush(); |
||
71 | ob_flush(); |
||
72 | } |
||
73 | } |
||
74 | } |
||
75 | } |
||
76 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.