Conditions | 6 |
Paths | 12 |
Total Lines | 56 |
Code Lines | 24 |
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 |
||
38 | public function fill($max_inserts_count) |
||
39 | { |
||
40 | global $opt; |
||
41 | |||
42 | $rowCount = 0; |
||
43 | $nInsertCount = 0; |
||
44 | |||
45 | if ($opt['logic']['waypoint_pool']['fill_gaps'] === true) { |
||
46 | // query the first unused waypoint (between other waypoints) |
||
47 | $rsStartWp = sql( |
||
48 | "SELECT SQL_BUFFER_RESULT DECTOWP(WPTODEC(`c`.`wp_oc`, '&1')+1, '&1') AS `free_wp` |
||
49 | FROM `caches` AS `c` |
||
50 | LEFT JOIN `caches` AS `cNext` ON DECTOWP(WPTODEC(`c`.`wp_oc`, '&1')+1, '&1')=`cNext`.`wp_oc` |
||
51 | LEFT JOIN `cache_waypoint_pool` ON DECTOWP(WPTODEC(`c`.`wp_oc` ,'&1')+1, '&1')=`cache_waypoint_pool`.`wp_oc` |
||
52 | WHERE `c`.`wp_oc` REGEXP '&2' |
||
53 | AND ISNULL(`cNext`.`wp_oc`) |
||
54 | AND ISNULL(`cache_waypoint_pool`.`wp_oc`) |
||
55 | ORDER BY `free_wp` ASC |
||
56 | LIMIT 250", |
||
57 | $opt['logic']['waypoint_pool']['prefix'], |
||
58 | '^' . $opt['logic']['waypoint_pool']['prefix'] . '[' . $opt['logic']['waypoint_pool']['valid_chars'] . ']{1,}$' |
||
59 | ); |
||
60 | } else { |
||
61 | // query the last used waypoint |
||
62 | $rsStartWp = sql( |
||
63 | "SELECT SQL_BUFFER_RESULT DECTOWP(MAX(dec_wp)+1, '&2') AS `free_wp` |
||
64 | FROM ( |
||
65 | SELECT MAX(WPTODEC(`wp_oc`, '&2')) AS dec_wp |
||
66 | FROM `caches` |
||
67 | WHERE `wp_oc` REGEXP '&1' |
||
68 | UNION |
||
69 | SELECT MAX(WPTODEC(`wp_oc`, '&2')) AS dec_wp |
||
70 | FROM `cache_waypoint_pool` |
||
71 | ) AS tbl", |
||
72 | '^' . $opt['logic']['waypoint_pool']['prefix'] . '[' . $opt['logic']['waypoint_pool']['valid_chars'] . ']{1,}$', |
||
73 | $opt['logic']['waypoint_pool']['prefix'] |
||
74 | ); |
||
75 | } |
||
76 | |||
77 | while (($rStartWp = sql_fetch_assoc($rsStartWp)) && ($nInsertCount < $max_inserts_count)) { |
||
78 | $free_wp = $rStartWp['free_wp']; |
||
79 | if ($free_wp == '') { |
||
80 | $free_wp = $opt['logic']['waypoint_pool']['prefix'] . '0001'; |
||
81 | } |
||
82 | $nInsertCount += $this->fillTurn($free_wp, $max_inserts_count - $nInsertCount); |
||
83 | $rowCount++; |
||
84 | } |
||
85 | sql_free_result($rsStartWp); |
||
86 | |||
87 | if ($rowCount == 0) { |
||
88 | // new database ... |
||
89 | $nInsertCount += $this->fillTurn($opt['logic']['waypoint_pool']['prefix'] . '0001', $max_inserts_count); |
||
90 | } |
||
91 | |||
92 | return $nInsertCount; |
||
93 | } |
||
94 | |||
165 |
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.