| Conditions | 11 |
| Paths | 6 |
| Total Lines | 43 |
| Code Lines | 26 |
| 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 |
||
| 117 | private function checkAltered(array $data, string $text): int |
||
| 118 | { |
||
| 119 | if ($data === []) { |
||
| 120 | return 99; |
||
| 121 | } |
||
| 122 | $found = 0; |
||
| 123 | $count = 0; |
||
| 124 | $text = mb_strtolower($text); |
||
| 125 | foreach ($data as $dat) { |
||
| 126 | if (1 === (int) $dat['skip'] || empty($dat['edited'])) { |
||
| 127 | continue; |
||
| 128 | } |
||
| 129 | $count++; |
||
| 130 | if (empty($dat['opti'])) { |
||
| 131 | echo 'opti vide'; |
||
| 132 | continue; |
||
| 133 | } |
||
| 134 | |||
| 135 | // compte pas différence Unicode entre BD et wiki |
||
| 136 | $opti = Normalizer::normalize($dat['opti']); // hack |
||
| 137 | // compte pas les changements de typo majuscule/minuscule |
||
| 138 | $optiLower = mb_strtolower($opti); |
||
| 139 | // compte pas la correction sur ouvrage avec commentaire HTML |
||
| 140 | $optiComment = WikiTextUtil::removeHTMLcomments($opti); |
||
| 141 | // compte pas la suppression de langue=fr : provisoire (fix on SQL) |
||
| 142 | $optiLanfr = preg_replace('#\|[\n ]*langue=fr[\n ]*#', '', $opti); |
||
| 143 | |||
| 144 | if (!empty($opti) |
||
| 145 | && (mb_strpos($text, $opti) !== false |
||
| 146 | || mb_strpos(mb_strtolower($text), $optiLower) !== false |
||
| 147 | || mb_strpos($text, $optiComment) !== false |
||
| 148 | || mb_strpos($text, $optiLanfr) !== false) |
||
| 149 | ) { |
||
| 150 | echo '+'; |
||
| 151 | $found++; |
||
| 152 | } else { |
||
| 153 | echo '-'; |
||
| 154 | } |
||
| 155 | // ici update DB |
||
| 156 | |||
| 157 | } |
||
| 158 | |||
| 159 | return (int)round(($count - $found) / count($data) * 100); |
||
| 160 | } |
||
| 163 |