| Conditions | 7 |
| Paths | 20 |
| Total Lines | 61 |
| Code Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 35 | public function reparse($resume_data) |
||
| 36 | { |
||
| 37 | $limit = 100; |
||
| 38 | $fast_reparsers = array( |
||
| 39 | array('\ernadoo\phpbbdirectory\textreparser\plugins\cat_description', 'directory_cats'), |
||
| 40 | array('\ernadoo\phpbbdirectory\textreparser\plugins\comment_text', 'directory_comments'), |
||
| 41 | array('\ernadoo\phpbbdirectory\textreparser\plugins\link_description', 'directory_links'), |
||
| 42 | ); |
||
| 43 | |||
| 44 | if (!is_array($resume_data)) |
||
| 45 | { |
||
| 46 | $default_reparser = new $fast_reparsers[0][0]( |
||
| 47 | $this->db, |
||
| 48 | $this->container->getParameter('core.table_prefix') . $fast_reparsers[0][1]); |
||
| 49 | |||
| 50 | $resume_data = array( |
||
| 51 | 'reparser' => 0, |
||
| 52 | 'current' => $default_reparser->get_max_id() |
||
| 53 | |||
| 54 | ); |
||
| 55 | } |
||
| 56 | |||
| 57 | $fast_reparsers_size = sizeof($fast_reparsers); |
||
| 58 | $processed_records = 0; |
||
| 59 | while ($processed_records < $limit && $resume_data['reparser'] < $fast_reparsers_size) |
||
| 60 | { |
||
| 61 | $reparser = new $fast_reparsers[$resume_data['reparser']][0]( |
||
| 62 | $this->db, |
||
| 63 | $this->container->getParameter('core.table_prefix') . $fast_reparsers[$resume_data['reparser']][1] |
||
| 64 | ); |
||
| 65 | |||
| 66 | // New reparser |
||
| 67 | if ($resume_data['current'] === 0) |
||
| 68 | { |
||
| 69 | $resume_data['current'] = $reparser->get_max_id(); |
||
| 70 | } |
||
| 71 | |||
| 72 | $start = max(1, $resume_data['current'] + 1 - ($limit - $processed_records)); |
||
| 73 | $end = max(1, $resume_data['current']); |
||
| 74 | $reparser->reparse_range($start, $end); |
||
| 75 | |||
| 76 | $processed_records = $end - $start + 1; |
||
| 77 | $resume_data['current'] = $start - 1; |
||
| 78 | |||
| 79 | if ($start === 1) |
||
| 80 | { |
||
| 81 | // Prevent CLI command from running these reparsers again |
||
| 82 | $reparser_manager = $this->container->get('text_reparser.manager'); |
||
| 83 | $reparser_manager->update_resume_data($fast_reparsers[$resume_data['reparser']][0], 1, 0, $limit); |
||
| 84 | |||
| 85 | $resume_data['reparser']++; |
||
| 86 | } |
||
| 87 | } |
||
| 88 | |||
| 89 | if ($resume_data['reparser'] === $fast_reparsers_size) |
||
| 90 | { |
||
| 91 | return true; |
||
| 92 | } |
||
| 93 | |||
| 94 | return $resume_data; |
||
| 95 | } |
||
| 96 | } |
||
| 97 |