| Conditions | 11 |
| Paths | 28 |
| Total Lines | 52 |
| Code Lines | 31 |
| 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 |
||
| 74 | private function setUp(array $sectionArray, string $rawWikiText, string $dateRegexp): void |
||
| 75 | { |
||
| 76 | $this->data = []; |
||
| 77 | |||
| 78 | $lines = explode("\n", $rawWikiText); |
||
| 79 | |||
| 80 | $keys = join("|", $sectionArray); |
||
| 81 | |||
| 82 | $lastSection = ""; |
||
| 83 | |||
| 84 | foreach ($lines as $line) { |
||
| 85 | if (preg_match("/={1,6}\s?($keys)\s?={1,6}/i", $line, $matches)) { |
||
| 86 | $lastSection = strtolower($matches[1]); |
||
| 87 | } elseif ("" == $lastSection |
||
| 88 | && preg_match( |
||
| 89 | "/$dateRegexp/i", |
||
| 90 | $line, |
||
| 91 | $matches |
||
| 92 | ) |
||
| 93 | ) { |
||
| 94 | $this->end = $matches[1]; |
||
| 95 | } elseif ("" != $lastSection |
||
| 96 | && 0 === preg_match("/^\s*#?:.*/i", $line) |
||
| 97 | ) { |
||
| 98 | $this->findSig($line, $matches); |
||
| 99 | if (!isset($matches[1][0])) { |
||
| 100 | continue; |
||
| 101 | } |
||
| 102 | $foundUser = trim($matches[1][0][0]); |
||
| 103 | $this->data[$lastSection][] = $foundUser; |
||
| 104 | if (strtolower($foundUser) === strtolower($this->userLookingFor)) { |
||
|
|
|||
| 105 | $this->userSectionFound = $lastSection; |
||
| 106 | } |
||
| 107 | } |
||
| 108 | } |
||
| 109 | |||
| 110 | $final = []; // initialize the final array |
||
| 111 | $finalRaw = []; // Initialize the raw data array |
||
| 112 | |||
| 113 | foreach (array_keys($this->data) as $key) { |
||
| 114 | $finalRaw = array_merge($finalRaw, $this->data[$key]); |
||
| 115 | } |
||
| 116 | |||
| 117 | foreach ($finalRaw as $foundUsername) { |
||
| 118 | $final[] = $foundUsername; // group all array's elements |
||
| 119 | } |
||
| 120 | |||
| 121 | $final = array_count_values($final); // find repetition and its count |
||
| 122 | |||
| 123 | $final = array_diff($final, [1]); // remove single occurrences |
||
| 124 | |||
| 125 | $this->duplicates = array_keys($final); |
||
| 126 | } |
||
| 186 |