Conditions | 10 |
Paths | 30 |
Total Lines | 42 |
Code Lines | 20 |
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 |
||
83 | private function tableRows() |
||
84 | { |
||
85 | $allLanguages = $this->manager->languages(); |
||
86 | |||
87 | $filesContent = []; |
||
88 | |||
89 | $output = []; |
||
90 | |||
91 | foreach ($this->files as $fileName => $fileLanguages) { |
||
92 | foreach ($fileLanguages as $languageKey => $filePath) { |
||
93 | $lines = $filesContent[$fileName][$languageKey] = Arr::dot($this->manager->getFileContent($filePath)); |
||
94 | |||
95 | foreach ($lines as $key => $line) { |
||
96 | if (!is_array($line) && stripos($line, $this->argument('keyword')) !== false) { |
||
|
|||
97 | $output[$fileName.'.'.$key][$languageKey] = "<bg=yellow;fg=black>{$line}</>"; |
||
98 | } |
||
99 | } |
||
100 | } |
||
101 | } |
||
102 | |||
103 | // Now that we collected all values that matches the keyword argument |
||
104 | // in a close match, we collect the values for the rest of the |
||
105 | // languages for the found keys to complete the table view. |
||
106 | foreach ($output as $fullKey => $values) { |
||
107 | list($fileName, $key) = explode('.', $fullKey, 2); |
||
108 | |||
109 | $original = []; |
||
110 | |||
111 | foreach ($allLanguages as $languageKey) { |
||
112 | $original[$languageKey] = |
||
113 | isset($values[$languageKey]) |
||
114 | ? $values[$languageKey] |
||
115 | : isset($filesContent[$fileName][$languageKey][$key]) ? $filesContent[$fileName][$languageKey][$key] : ''; |
||
116 | } |
||
117 | |||
118 | // Sort the language values based on language name |
||
119 | ksort($original); |
||
120 | |||
121 | $output[$fullKey] = array_merge(['key' => "<fg=yellow>$fullKey</>"], $original); |
||
122 | } |
||
123 | |||
124 | return array_values($output); |
||
125 | } |
||
127 |