Conditions | 8 |
Paths | 9 |
Total Lines | 52 |
Code Lines | 29 |
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 |
||
15 | public function run() |
||
16 | { |
||
17 | $rsDuplicatePic = sql( |
||
18 | 'SELECT `object_id`, `title` |
||
19 | FROM `pictures` |
||
20 | WHERE `object_type`=1 |
||
21 | GROUP BY `object_id`, `title` |
||
22 | HAVING COUNT(*) > 1' |
||
23 | ); |
||
24 | |||
25 | while ($rDuplicatePic = sql_fetch_assoc($rsDuplicatePic)) { |
||
26 | $rsInstances = sql( |
||
27 | "SELECT `pictures`.`id` `picid`, `cache_logs`.`cache_id` `cache_id` |
||
28 | FROM `pictures` |
||
29 | LEFT JOIN `cache_logs` ON `cache_logs`.`id` = `pictures`.`object_id` |
||
30 | WHERE `pictures`.`object_type`=1 AND `pictures`.`object_id`='&1' AND `pictures`.`title`='&2' |
||
31 | ORDER BY `pictures`.`date_created`", |
||
32 | $rDuplicatePic['object_id'], |
||
33 | $rDuplicatePic['title'] |
||
34 | ); |
||
35 | |||
36 | $instances = sql_fetch_assoc_table($rsInstances); |
||
37 | foreach ($instances as &$instance) { |
||
38 | $instance['pic'] = new picture($instance['picid']); |
||
39 | $instance['filesize'] = @filesize($instance['pic']->getFilename()); |
||
40 | } |
||
41 | $countInstances = count($instances); |
||
42 | for ($n = 1; $n < $countInstances; ++ $n) { |
||
43 | if ($instances[$n]['filesize'] !== false) { |
||
44 | // ensure that pic is stored locally |
||
45 | for ($nn = $n - 1; $nn >= 0; -- $nn) { |
||
46 | if ($instances[$nn]['filesize'] === $instances[$n]['filesize'] |
||
47 | && file_get_contents($instances[$nn]['pic']->getFilename()) |
||
48 | === file_get_contents($instances[$n]['pic']->getFilename()) |
||
49 | ) { |
||
50 | $picture = $instances[$n]['pic']; |
||
51 | echo |
||
52 | 'deleting duplicate picture ' |
||
53 | . $picture->getPictureId() . ' ("' . $picture->getTitle() . '")' |
||
54 | . ' from log ' . $rDuplicatePic['object_id'] |
||
55 | . ' of cache ' . $instances[$n]['cache_id'] . "\n"; |
||
56 | $picture->delete(false); |
||
57 | $instances[$n]['filesize'] = false; |
||
58 | break; |
||
59 | } |
||
60 | } |
||
61 | } |
||
62 | } |
||
63 | } |
||
64 | |||
65 | sql_free_result($rsDuplicatePic); |
||
66 | } |
||
67 | } |
||
68 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.