| Conditions | 10 |
| Paths | 61 |
| Total Lines | 74 |
| Code Lines | 46 |
| 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 |
||
| 81 | private function generatePoFileFromTrad4All(string $englishName, string $isocode): void |
||
| 82 | { |
||
| 83 | $kernel = $this->container->get('kernel'); |
||
|
|
|||
| 84 | $updateRootPath = $this->getUpdateRootPath(); |
||
| 85 | |||
| 86 | $langPath = $updateRootPath.'/main/lang/'.$englishName.'/trad4all.inc.php'; |
||
| 87 | $destinationFilePath = $kernel->getProjectDir().'/var/translations/messages.'.$isocode.'.po'; |
||
| 88 | $originalFile = $updateRootPath.'/main/lang/english/trad4all.inc.php'; |
||
| 89 | |||
| 90 | if (!file_exists($langPath)) { |
||
| 91 | error_log("Original file not found: $langPath"); |
||
| 92 | |||
| 93 | return; |
||
| 94 | } |
||
| 95 | |||
| 96 | $terms = SubLanguageManager::get_all_language_variable_in_file( |
||
| 97 | $originalFile, |
||
| 98 | true |
||
| 99 | ); |
||
| 100 | |||
| 101 | foreach ($terms as $index => $translation) { |
||
| 102 | $terms[$index] = trim(rtrim($translation, ';'), '"'); |
||
| 103 | } |
||
| 104 | |||
| 105 | $header = 'msgid ""'."\n".'msgstr ""'."\n". |
||
| 106 | '"Project-Id-Version: chamilo\n"'."\n". |
||
| 107 | '"Language: '.$isocode.'\n"'."\n". |
||
| 108 | '"Content-Type: text/plain; charset=UTF-8\n"'."\n". |
||
| 109 | '"Content-Transfer-Encoding: 8bit\n"'."\n\n"; |
||
| 110 | file_put_contents($destinationFilePath, $header); |
||
| 111 | |||
| 112 | $originalTermsInLanguage = SubLanguageManager::get_all_language_variable_in_file( |
||
| 113 | $langPath, |
||
| 114 | true |
||
| 115 | ); |
||
| 116 | |||
| 117 | $termsInLanguage = []; |
||
| 118 | foreach ($originalTermsInLanguage as $id => $content) { |
||
| 119 | if (!isset($termsInLanguage[$id])) { |
||
| 120 | $termsInLanguage[$id] = trim(rtrim($content, ';'), '"'); |
||
| 121 | } |
||
| 122 | } |
||
| 123 | |||
| 124 | $bigString = ''; |
||
| 125 | $doneTranslations = []; |
||
| 126 | foreach ($terms as $term => $englishTranslation) { |
||
| 127 | if (isset($doneTranslations[$englishTranslation])) { |
||
| 128 | continue; |
||
| 129 | } |
||
| 130 | $doneTranslations[$englishTranslation] = true; |
||
| 131 | $translatedTerm = $termsInLanguage[$term] ?? ''; |
||
| 132 | |||
| 133 | // Here we apply a little correction to avoid unterminated strings |
||
| 134 | // when a string ends with a \" |
||
| 135 | if (preg_match('/\\\$/', $englishTranslation)) { |
||
| 136 | $englishTranslation .= '"'; |
||
| 137 | } |
||
| 138 | |||
| 139 | $search = ['\{', '\}', '\(', '\)', '\;']; |
||
| 140 | $replace = ['\\\{', '\\\}', '\\\(', '\\\)', '\\\;']; |
||
| 141 | $englishTranslation = str_replace($search, $replace, $englishTranslation); |
||
| 142 | if (preg_match('/\\\$/', $translatedTerm)) { |
||
| 143 | $translatedTerm .= '"'; |
||
| 144 | } |
||
| 145 | $translatedTerm = str_replace($search, $replace, $translatedTerm); |
||
| 146 | if (empty($translatedTerm)) { |
||
| 147 | continue; |
||
| 148 | } |
||
| 149 | // Now build the line |
||
| 150 | $bigString .= 'msgid "'.$englishTranslation.'"'."\n".'msgstr "'.$translatedTerm.'"'."\n\n"; |
||
| 151 | } |
||
| 152 | file_put_contents($destinationFilePath, $bigString, FILE_APPEND); |
||
| 153 | |||
| 154 | error_log("Done generating gettext file in $destinationFilePath !\n"); |
||
| 155 | } |
||
| 188 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.