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