@@ -6,9 +6,9 @@ |
||
| 6 | 6 | |
| 7 | 7 | class Localization_Scanner_StringsCollection_Warning |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * @var array |
|
| 11 | - */ |
|
| 9 | + /** |
|
| 10 | + * @var array |
|
| 11 | + */ |
|
| 12 | 12 | protected $data; |
| 13 | 13 | |
| 14 | 14 | public function __construct(array $data) |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | |
| 69 | 69 | public function addHashes(array $hashes) : Localization_Writer |
| 70 | 70 | { |
| 71 | - foreach($hashes as $hash => $text) |
|
| 71 | + foreach ($hashes as $hash => $text) |
|
| 72 | 72 | { |
| 73 | 73 | $this->addHash($hash, $text); |
| 74 | 74 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | $hashes = $this->compileHashes(); |
| 91 | 91 | $lines = array(); |
| 92 | 92 | |
| 93 | - foreach($hashes as $entry) |
|
| 93 | + foreach ($hashes as $entry) |
|
| 94 | 94 | { |
| 95 | 95 | $lines[] = sprintf( |
| 96 | 96 | '%s= "%s"', |
@@ -106,16 +106,16 @@ discard block |
||
| 106 | 106 | |
| 107 | 107 | private function renderHead() : string |
| 108 | 108 | { |
| 109 | - $title = strtoupper($this->fileType).' TRANSLATION FILE FOR ' . strtoupper($this->locale->getLabel()); |
|
| 109 | + $title = strtoupper($this->fileType).' TRANSLATION FILE FOR '.strtoupper($this->locale->getLabel()); |
|
| 110 | 110 | |
| 111 | 111 | $lines = array(); |
| 112 | 112 | |
| 113 | 113 | $lines[] = '; -------------------------------------------------------'; |
| 114 | - $lines[] = '; '. $title; |
|
| 114 | + $lines[] = '; '.$title; |
|
| 115 | 115 | $lines[] = '; -------------------------------------------------------'; |
| 116 | 116 | $lines[] = '; '; |
| 117 | 117 | |
| 118 | - if($this->editable) |
|
| 118 | + if ($this->editable) |
|
| 119 | 119 | { |
| 120 | 120 | $lines[] = '; You may edit text directly in this file under the following conditions:'; |
| 121 | 121 | $lines[] = '; '; |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | { |
| 138 | 138 | $hashes = array(); |
| 139 | 139 | |
| 140 | - foreach($this->hashes as $hash => $text) |
|
| 140 | + foreach ($this->hashes as $hash => $text) |
|
| 141 | 141 | { |
| 142 | 142 | $hashes[] = array( |
| 143 | 143 | 'hash' => $hash, |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | { |
| 165 | 165 | $result = strnatcasecmp($a['text'], $b['text']); |
| 166 | 166 | |
| 167 | - if($result === 0) |
|
| 167 | + if ($result === 0) |
|
| 168 | 168 | { |
| 169 | 169 | return strnatcmp($a['hash'], $b['hash']); |
| 170 | 170 | } |
@@ -121,8 +121,7 @@ |
||
| 121 | 121 | $lines[] = '; '; |
| 122 | 122 | $lines[] = '; 1) Do not to modify the keys (left hand side of the = sign)'; |
| 123 | 123 | $lines[] = '; 2) Save the file as UTF-8 without BOM'; |
| 124 | - } |
|
| 125 | - else |
|
| 124 | + } else |
|
| 126 | 125 | { |
| 127 | 126 | $lines[] = '; Do NOT edit this file directly! It depends on the main translation file'; |
| 128 | 127 | $lines[] = '; and any changes will be lost. Edit the main file instead.'; |
@@ -20,29 +20,29 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | class Localization_Writer |
| 22 | 22 | { |
| 23 | - /** |
|
| 24 | - * @var boolean |
|
| 25 | - */ |
|
| 23 | + /** |
|
| 24 | + * @var boolean |
|
| 25 | + */ |
|
| 26 | 26 | private $editable = false; |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @var array<string,string> |
|
| 30 | - */ |
|
| 28 | + /** |
|
| 29 | + * @var array<string,string> |
|
| 30 | + */ |
|
| 31 | 31 | private $hashes = array(); |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @var Localization_Locale |
|
| 35 | - */ |
|
| 33 | + /** |
|
| 34 | + * @var Localization_Locale |
|
| 35 | + */ |
|
| 36 | 36 | private $locale; |
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @var string |
|
| 40 | - */ |
|
| 38 | + /** |
|
| 39 | + * @var string |
|
| 40 | + */ |
|
| 41 | 41 | private $fileType; |
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * @var string |
|
| 45 | - */ |
|
| 43 | + /** |
|
| 44 | + * @var string |
|
| 45 | + */ |
|
| 46 | 46 | private $filePath; |
| 47 | 47 | |
| 48 | 48 | public function __construct(Localization_Locale $locale, string $fileType, string $filePath) |
@@ -150,16 +150,16 @@ discard block |
||
| 150 | 150 | return $hashes; |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | - /** |
|
| 154 | - * Sort the strings to ensure they always appear in the same order: |
|
| 155 | - * first by text, and same strings by their hashes. This is important |
|
| 156 | - * for strings that have the same translation to avoid them changing |
|
| 157 | - * order between sorts. |
|
| 158 | - * |
|
| 159 | - * @param array $a |
|
| 160 | - * @param array $b |
|
| 161 | - * @return int |
|
| 162 | - */ |
|
| 153 | + /** |
|
| 154 | + * Sort the strings to ensure they always appear in the same order: |
|
| 155 | + * first by text, and same strings by their hashes. This is important |
|
| 156 | + * for strings that have the same translation to avoid them changing |
|
| 157 | + * order between sorts. |
|
| 158 | + * |
|
| 159 | + * @param array $a |
|
| 160 | + * @param array $b |
|
| 161 | + * @return int |
|
| 162 | + */ |
|
| 163 | 163 | public function callback_sortStrings(array $a, array $b) : int |
| 164 | 164 | { |
| 165 | 165 | $result = strnatcasecmp($a['text'], $b['text']); |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | { |
| 104 | 104 | $ext = FileHelper::getExtension($path); |
| 105 | 105 | |
| 106 | - if($this->isExtensionSupported($ext)) { |
|
| 106 | + if ($this->isExtensionSupported($ext)) { |
|
| 107 | 107 | return; |
| 108 | 108 | } |
| 109 | 109 | |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | { |
| 127 | 127 | $values = $this->getLanguageIDs(); |
| 128 | 128 | |
| 129 | - if(in_array($languageID, $values)) { |
|
| 129 | + if (in_array($languageID, $values)) { |
|
| 130 | 130 | return; |
| 131 | 131 | } |
| 132 | 132 | |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | { |
| 171 | 171 | $this->requireValidLanguageID($languageID); |
| 172 | 172 | |
| 173 | - if(!isset($this->languageParsers[$languageID])) |
|
| 173 | + if (!isset($this->languageParsers[$languageID])) |
|
| 174 | 174 | { |
| 175 | 175 | $this->languageParsers[$languageID] = $this->createLanguageInstance($languageID); |
| 176 | 176 | } |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | |
| 191 | 191 | $object = new $class($this); |
| 192 | 192 | |
| 193 | - if($object instanceof Localization_Parser_Language) |
|
| 193 | + if ($object instanceof Localization_Parser_Language) |
|
| 194 | 194 | { |
| 195 | 195 | return $object; |
| 196 | 196 | } |
@@ -30,14 +30,14 @@ discard block |
||
| 30 | 30 | const ERROR_UNSUPPORTED_FILE_EXTENSION = 40602; |
| 31 | 31 | const ERROR_INVALID_LANGUAGE_CLASS = 40603; |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @var Localization_Scanner |
|
| 35 | - */ |
|
| 33 | + /** |
|
| 34 | + * @var Localization_Scanner |
|
| 35 | + */ |
|
| 36 | 36 | protected $scanner; |
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @var Localization_Scanner_StringsCollection |
|
| 40 | - */ |
|
| 38 | + /** |
|
| 39 | + * @var Localization_Scanner_StringsCollection |
|
| 40 | + */ |
|
| 41 | 41 | protected $collection; |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -54,15 +54,15 @@ discard block |
||
| 54 | 54 | $this->collection = $scanner->getCollection(); |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Parses a source file. Must have a valid supported file extension. |
|
| 59 | - * |
|
| 60 | - * @param string $path |
|
| 61 | - * @return Localization_Parser_Language |
|
| 62 | - * @throws Localization_Exception |
|
| 63 | - * |
|
| 64 | - * @see Localization_Parser::ERROR_UNSUPPORTED_FILE_EXTENSION |
|
| 65 | - */ |
|
| 57 | + /** |
|
| 58 | + * Parses a source file. Must have a valid supported file extension. |
|
| 59 | + * |
|
| 60 | + * @param string $path |
|
| 61 | + * @return Localization_Parser_Language |
|
| 62 | + * @throws Localization_Exception |
|
| 63 | + * |
|
| 64 | + * @see Localization_Parser::ERROR_UNSUPPORTED_FILE_EXTENSION |
|
| 65 | + */ |
|
| 66 | 66 | public function parseFile(string $path) : Localization_Parser_Language |
| 67 | 67 | { |
| 68 | 68 | $this->requireValidFile($path); |
@@ -76,16 +76,16 @@ discard block |
||
| 76 | 76 | return $language; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * Parses the string for the specified language. |
|
| 81 | - * |
|
| 82 | - * @param string $languageID |
|
| 83 | - * @param string $code |
|
| 84 | - * @return Localization_Parser_Language |
|
| 85 | - * @throws Localization_Exception |
|
| 86 | - * |
|
| 87 | - * @see Localization_Parser::ERROR_INVALID_LANGUAGE_ID |
|
| 88 | - */ |
|
| 79 | + /** |
|
| 80 | + * Parses the string for the specified language. |
|
| 81 | + * |
|
| 82 | + * @param string $languageID |
|
| 83 | + * @param string $code |
|
| 84 | + * @return Localization_Parser_Language |
|
| 85 | + * @throws Localization_Exception |
|
| 86 | + * |
|
| 87 | + * @see Localization_Parser::ERROR_INVALID_LANGUAGE_ID |
|
| 88 | + */ |
|
| 89 | 89 | public function parseString(string $languageID, string $code) : Localization_Parser_Language |
| 90 | 90 | { |
| 91 | 91 | $this->requireValidLanguageID($languageID); |
@@ -144,18 +144,18 @@ discard block |
||
| 144 | 144 | ); |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - /** |
|
| 148 | - * Retrieves a list of all language IDs that are supported. |
|
| 149 | - * @return string[] IDs list like "PHP", "Javascript" |
|
| 150 | - */ |
|
| 147 | + /** |
|
| 148 | + * Retrieves a list of all language IDs that are supported. |
|
| 149 | + * @return string[] IDs list like "PHP", "Javascript" |
|
| 150 | + */ |
|
| 151 | 151 | public function getLanguageIDs() : array |
| 152 | 152 | { |
| 153 | 153 | return array_values($this->languageMappings); |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | - /** |
|
| 157 | - * @var array<string,Localization_Parser_Language> |
|
| 158 | - */ |
|
| 156 | + /** |
|
| 157 | + * @var array<string,Localization_Parser_Language> |
|
| 158 | + */ |
|
| 159 | 159 | protected $languageParsers = array(); |
| 160 | 160 | |
| 161 | 161 | /** |
@@ -209,12 +209,12 @@ discard block |
||
| 209 | 209 | ); |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | - /** |
|
| 213 | - * Whether the specified file extension is supported. |
|
| 214 | - * |
|
| 215 | - * @param string $ext |
|
| 216 | - * @return bool |
|
| 217 | - */ |
|
| 212 | + /** |
|
| 213 | + * Whether the specified file extension is supported. |
|
| 214 | + * |
|
| 215 | + * @param string $ext |
|
| 216 | + * @return bool |
|
| 217 | + */ |
|
| 218 | 218 | public function isExtensionSupported(string $ext) : bool |
| 219 | 219 | { |
| 220 | 220 | $ext = strtolower($ext); |
@@ -29,7 +29,7 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | private $hash; |
| 31 | 31 | |
| 32 | - public function __construct(string $text, int $line, string $explanation='') |
|
| 32 | + public function __construct(string $text, int $line, string $explanation = '') |
|
| 33 | 33 | { |
| 34 | 34 | $this->text = $text; |
| 35 | 35 | $this->line = $line; |
@@ -12,8 +12,8 @@ |
||
| 12 | 12 | const SERIALIZED_PROPERTIES = 'properties'; |
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | - * @var Localization_Scanner_StringsCollection |
|
| 16 | - */ |
|
| 15 | + * @var Localization_Scanner_StringsCollection |
|
| 16 | + */ |
|
| 17 | 17 | protected $collection; |
| 18 | 18 | |
| 19 | 19 | /** |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | |
| 88 | 88 | public function getProperty(string $name) : ?string |
| 89 | 89 | { |
| 90 | - if(isset($this->properties[$name])) { |
|
| 90 | + if (isset($this->properties[$name])) { |
|
| 91 | 91 | return $this->properties[$name]; |
| 92 | 92 | } |
| 93 | 93 | |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | Text::fromArray($array[self::SERIALIZED_TEXT]) |
| 142 | 142 | ); |
| 143 | 143 | |
| 144 | - foreach($array[self::SERIALIZED_PROPERTIES] as $name => $value) { |
|
| 144 | + foreach ($array[self::SERIALIZED_PROPERTIES] as $name => $value) { |
|
| 145 | 145 | $string->setProperty($name, $value); |
| 146 | 146 | } |
| 147 | 147 | |
@@ -54,7 +54,7 @@ |
||
| 54 | 54 | */ |
| 55 | 55 | public function getFloat() : float |
| 56 | 56 | { |
| 57 | - return floatval($this->number . '.' . $this->decimals); |
|
| 57 | + return floatval($this->number.'.'.$this->decimals); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
@@ -57,8 +57,8 @@ discard block |
||
| 57 | 57 | protected $reverseStrings = array(); |
| 58 | 58 | |
| 59 | 59 | /** |
| 60 | - * @var Localization_Source[] |
|
| 61 | - */ |
|
| 60 | + * @var Localization_Source[] |
|
| 61 | + */ |
|
| 62 | 62 | private $sources = array(); |
| 63 | 63 | |
| 64 | 64 | /** |
@@ -191,14 +191,14 @@ discard block |
||
| 191 | 191 | ); |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | - /** |
|
| 195 | - * Retrieves all available strings for the specified locale, |
|
| 196 | - * as hash => text value pairs. |
|
| 197 | - * |
|
| 198 | - * @param Localization_Locale $locale |
|
| 199 | - * @throws Localization_Exception |
|
| 200 | - * @return string[] |
|
| 201 | - */ |
|
| 194 | + /** |
|
| 195 | + * Retrieves all available strings for the specified locale, |
|
| 196 | + * as hash => text value pairs. |
|
| 197 | + * |
|
| 198 | + * @param Localization_Locale $locale |
|
| 199 | + * @throws Localization_Exception |
|
| 200 | + * @return string[] |
|
| 201 | + */ |
|
| 202 | 202 | public function getStrings(Localization_Locale $locale) : array |
| 203 | 203 | { |
| 204 | 204 | $this->load($locale); |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | */ |
| 80 | 80 | public function addSources(array $sources) : void |
| 81 | 81 | { |
| 82 | - foreach($sources as $source) { |
|
| 82 | + foreach ($sources as $source) { |
|
| 83 | 83 | $this->addSource($source); |
| 84 | 84 | } |
| 85 | 85 | } |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | $this->strings[$localeName] = array(); |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | - foreach($this->sources as $source) |
|
| 127 | + foreach ($this->sources as $source) |
|
| 128 | 128 | { |
| 129 | 129 | $file = $this->resolveStorageFile($locale, $source); |
| 130 | 130 | if (!file_exists($file)) { |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | |
| 134 | 134 | $data = parse_ini_file($file, false); |
| 135 | 135 | |
| 136 | - if($data === false) |
|
| 136 | + if ($data === false) |
|
| 137 | 137 | { |
| 138 | 138 | throw new Localization_Exception( |
| 139 | 139 | 'Malformatted localization file', |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | |
| 206 | 206 | $name = $locale->getName(); |
| 207 | 207 | |
| 208 | - if(isset($this->strings[$name])) { |
|
| 208 | + if (isset($this->strings[$name])) { |
|
| 209 | 209 | return $this->strings[$name]; |
| 210 | 210 | } |
| 211 | 211 | |
@@ -240,11 +240,11 @@ discard block |
||
| 240 | 240 | * @param Localization_Locale $locale |
| 241 | 241 | * @param boolean $editable |
| 242 | 242 | */ |
| 243 | - protected function renderStringsFile(string $type, Localization_Source $source, array $hashes, string $file, Localization_Locale $locale, bool $editable=true) : void |
|
| 243 | + protected function renderStringsFile(string $type, Localization_Source $source, array $hashes, string $file, Localization_Locale $locale, bool $editable = true) : void |
|
| 244 | 244 | { |
| 245 | 245 | $writer = new Localization_Writer($locale, $type, $file); |
| 246 | 246 | |
| 247 | - if($editable) |
|
| 247 | + if ($editable) |
|
| 248 | 248 | { |
| 249 | 249 | $writer->makeEditable(); |
| 250 | 250 | } |
@@ -253,14 +253,14 @@ discard block |
||
| 253 | 253 | |
| 254 | 254 | foreach ($hashes as $hash) |
| 255 | 255 | { |
| 256 | - if(!$hash->hasSourceID($sourceID)) { |
|
| 256 | + if (!$hash->hasSourceID($sourceID)) { |
|
| 257 | 257 | continue; |
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | $text = $this->getHashTranslation($hash->getHash(), $locale); |
| 261 | 261 | |
| 262 | 262 | // skip any empty strings |
| 263 | - if($text === null || trim($text) == '') { |
|
| 263 | + if ($text === null || trim($text) == '') { |
|
| 264 | 264 | continue; |
| 265 | 265 | } |
| 266 | 266 | |
@@ -338,7 +338,7 @@ discard block |
||
| 338 | 338 | { |
| 339 | 339 | // to avoid re-creating the hash for the same texts over and over, |
| 340 | 340 | // we keep track of the hashes we created, and re-use them. |
| 341 | - if(isset($this->reverseStrings[$text])) { |
|
| 341 | + if (isset($this->reverseStrings[$text])) { |
|
| 342 | 342 | $hash = $this->reverseStrings[$text]; |
| 343 | 343 | } else { |
| 344 | 344 | $hash = md5($text); |
@@ -403,15 +403,15 @@ discard block |
||
| 403 | 403 | * @param Localization_Locale|null $locale |
| 404 | 404 | * @return string|NULL |
| 405 | 405 | */ |
| 406 | - public function getHashTranslation(string $hash, ?Localization_Locale $locale=null) : ?string |
|
| 406 | + public function getHashTranslation(string $hash, ?Localization_Locale $locale = null) : ?string |
|
| 407 | 407 | { |
| 408 | - if(!$locale) { |
|
| 408 | + if (!$locale) { |
|
| 409 | 409 | $locale = $this->targetLocale; |
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | $localeName = $locale->getName(); |
| 413 | 413 | |
| 414 | - if(isset($this->strings[$localeName]) && isset($this->strings[$localeName][$hash])) { |
|
| 414 | + if (isset($this->strings[$localeName]) && isset($this->strings[$localeName][$hash])) { |
|
| 415 | 415 | return $this->strings[$localeName][$hash]; |
| 416 | 416 | } |
| 417 | 417 | |
@@ -429,10 +429,10 @@ discard block |
||
| 429 | 429 | { |
| 430 | 430 | $result = array(); |
| 431 | 431 | |
| 432 | - foreach($this->sources as $source) |
|
| 432 | + foreach ($this->sources as $source) |
|
| 433 | 433 | { |
| 434 | 434 | $localeFile = self::getClientStorageFile($locale, $source); |
| 435 | - if(!file_exists($localeFile)) { |
|
| 435 | + if (!file_exists($localeFile)) { |
|
| 436 | 436 | continue; |
| 437 | 437 | } |
| 438 | 438 | |
@@ -42,13 +42,13 @@ |
||
| 42 | 42 | * @param array|string $definition |
| 43 | 43 | * @param Localization_Parser_Token|null $parentToken |
| 44 | 44 | */ |
| 45 | - public function __construct($definition, ?Localization_Parser_Token $parentToken=null) |
|
| 45 | + public function __construct($definition, ?Localization_Parser_Token $parentToken = null) |
|
| 46 | 46 | { |
| 47 | 47 | $this->definition = $definition; |
| 48 | 48 | $this->parentToken = $parentToken; |
| 49 | 49 | |
| 50 | 50 | $names = $this->getFunctionNames(); |
| 51 | - foreach($names as $name) { |
|
| 51 | + foreach ($names as $name) { |
|
| 52 | 52 | $this->nameLookup[$name] = true; |
| 53 | 53 | } |
| 54 | 54 | |
@@ -8,14 +8,14 @@ discard block |
||
| 8 | 8 | |
| 9 | 9 | abstract class Localization_Parser_Token |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * @var array|string |
|
| 13 | - */ |
|
| 11 | + /** |
|
| 12 | + * @var array|string |
|
| 13 | + */ |
|
| 14 | 14 | protected $definition; |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @var Localization_Parser_Token|NULL |
|
| 18 | - */ |
|
| 16 | + /** |
|
| 17 | + * @var Localization_Parser_Token|NULL |
|
| 18 | + */ |
|
| 19 | 19 | protected $parentToken; |
| 20 | 20 | |
| 21 | 21 | /** |
@@ -98,6 +98,6 @@ discard block |
||
| 98 | 98 | 'value' => $this->getValue(), |
| 99 | 99 | 'line' => $this->getLine(), |
| 100 | 100 | 'isEncapsedString' => ConvertHelper::bool2string($this->isEncapsedString()) |
| 101 | - ); |
|
| 101 | + ); |
|
| 102 | 102 | } |
| 103 | 103 | } |
@@ -124,8 +124,7 @@ |
||
| 124 | 124 | try |
| 125 | 125 | { |
| 126 | 126 | $this->content = FileHelper::readContents($path); |
| 127 | - } |
|
| 128 | - catch (FileHelper_Exception $e) |
|
| 127 | + } catch (FileHelper_Exception $e) |
|
| 129 | 128 | { |
| 130 | 129 | throw new Localization_Exception( |
| 131 | 130 | sprintf('Source code file [%s] could not be read', basename($path)), |
@@ -23,49 +23,49 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | protected $parser; |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * The function names that are included in the search. |
|
| 28 | - * @var array |
|
| 29 | - */ |
|
| 26 | + /** |
|
| 27 | + * The function names that are included in the search. |
|
| 28 | + * @var array |
|
| 29 | + */ |
|
| 30 | 30 | protected $functionNames = array(); |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * The tokens definitions. |
|
| 34 | - * @var array |
|
| 35 | - */ |
|
| 32 | + /** |
|
| 33 | + * The tokens definitions. |
|
| 34 | + * @var array |
|
| 35 | + */ |
|
| 36 | 36 | protected $tokens = array(); |
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * The total amount of tokens found in the content. |
|
| 40 | - * @var integer |
|
| 41 | - */ |
|
| 38 | + /** |
|
| 39 | + * The total amount of tokens found in the content. |
|
| 40 | + * @var integer |
|
| 41 | + */ |
|
| 42 | 42 | protected $totalTokens = 0; |
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * All texts that have been collected. |
|
| 46 | - * @var Text[] |
|
| 47 | - */ |
|
| 44 | + /** |
|
| 45 | + * All texts that have been collected. |
|
| 46 | + * @var Text[] |
|
| 47 | + */ |
|
| 48 | 48 | protected $texts = array(); |
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @var string |
|
| 52 | - */ |
|
| 50 | + /** |
|
| 51 | + * @var string |
|
| 52 | + */ |
|
| 53 | 53 | protected $content = ''; |
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * @var string|NULL |
|
| 57 | - */ |
|
| 55 | + /** |
|
| 56 | + * @var string|NULL |
|
| 57 | + */ |
|
| 58 | 58 | protected $id; |
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * @var Localization_Parser_Warning[] |
|
| 62 | - */ |
|
| 60 | + /** |
|
| 61 | + * @var Localization_Parser_Warning[] |
|
| 62 | + */ |
|
| 63 | 63 | protected $warnings = array(); |
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * The source file that was parsed (if any) |
|
| 67 | - * @var string |
|
| 68 | - */ |
|
| 65 | + /** |
|
| 66 | + * The source file that was parsed (if any) |
|
| 67 | + * @var string |
|
| 68 | + */ |
|
| 69 | 69 | protected $sourceFile = ''; |
| 70 | 70 | |
| 71 | 71 | /** |
@@ -91,10 +91,10 @@ discard block |
||
| 91 | 91 | |
| 92 | 92 | abstract protected function getTokens() : array; |
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * Retrieves the ID of the language. |
|
| 96 | - * @return string E.g. "PHP", "Javascript" |
|
| 97 | - */ |
|
| 94 | + /** |
|
| 95 | + * Retrieves the ID of the language. |
|
| 96 | + * @return string E.g. "PHP", "Javascript" |
|
| 97 | + */ |
|
| 98 | 98 | public function getID() : string |
| 99 | 99 | { |
| 100 | 100 | if(!isset($this->id)) { |
@@ -114,12 +114,12 @@ discard block |
||
| 114 | 114 | return $this->sourceFile; |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * Parses the code from a file. |
|
| 119 | - * |
|
| 120 | - * @param string $path |
|
| 121 | - * @throws Localization_Exception |
|
| 122 | - */ |
|
| 117 | + /** |
|
| 118 | + * Parses the code from a file. |
|
| 119 | + * |
|
| 120 | + * @param string $path |
|
| 121 | + * @throws Localization_Exception |
|
| 122 | + */ |
|
| 123 | 123 | public function parseFile(string $path) : void |
| 124 | 124 | { |
| 125 | 125 | if(!file_exists($path)) |
@@ -156,10 +156,10 @@ discard block |
||
| 156 | 156 | $this->parse(); |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - /** |
|
| 160 | - * Parses a source code string. |
|
| 161 | - * @param string $content |
|
| 162 | - */ |
|
| 159 | + /** |
|
| 160 | + * Parses a source code string. |
|
| 161 | + * @param string $content |
|
| 162 | + */ |
|
| 163 | 163 | public function parseString(string $content) : void |
| 164 | 164 | { |
| 165 | 165 | $this->content = $content; |
@@ -214,11 +214,11 @@ discard block |
||
| 214 | 214 | $this->texts[] = new Text($text, $line, $explanation); |
| 215 | 215 | } |
| 216 | 216 | |
| 217 | - /** |
|
| 218 | - * Retrieves a list of all the function names that are |
|
| 219 | - * used as translation functions in the language. |
|
| 220 | - * @return array |
|
| 221 | - */ |
|
| 217 | + /** |
|
| 218 | + * Retrieves a list of all the function names that are |
|
| 219 | + * used as translation functions in the language. |
|
| 220 | + * @return array |
|
| 221 | + */ |
|
| 222 | 222 | public function getFunctionNames() : array |
| 223 | 223 | { |
| 224 | 224 | return $this->createToken('dummy')->getFunctionNames(); |
@@ -229,13 +229,13 @@ discard block |
||
| 229 | 229 | Localization::log(sprintf('%1$s parser | %2$s', $this->getID(), $message)); |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | - /** |
|
| 233 | - * Adds a warning message when a text cannot be parsed correctly for some reason. |
|
| 234 | - * |
|
| 235 | - * @param Localization_Parser_Token $token |
|
| 236 | - * @param string $message |
|
| 237 | - * @return Localization_Parser_Warning |
|
| 238 | - */ |
|
| 232 | + /** |
|
| 233 | + * Adds a warning message when a text cannot be parsed correctly for some reason. |
|
| 234 | + * |
|
| 235 | + * @param Localization_Parser_Token $token |
|
| 236 | + * @param string $message |
|
| 237 | + * @return Localization_Parser_Warning |
|
| 238 | + */ |
|
| 239 | 239 | protected function addWarning(Localization_Parser_Token $token, string $message) : Localization_Parser_Warning |
| 240 | 240 | { |
| 241 | 241 | $warning = new Localization_Parser_Warning($this, $token, $message); |
@@ -245,34 +245,34 @@ discard block |
||
| 245 | 245 | return $warning; |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | - /** |
|
| 249 | - * Whether any warnings were generated during parsing. |
|
| 250 | - * @return bool |
|
| 251 | - */ |
|
| 248 | + /** |
|
| 249 | + * Whether any warnings were generated during parsing. |
|
| 250 | + * @return bool |
|
| 251 | + */ |
|
| 252 | 252 | public function hasWarnings() : bool |
| 253 | 253 | { |
| 254 | 254 | return !empty($this->warnings); |
| 255 | 255 | } |
| 256 | 256 | |
| 257 | - /** |
|
| 258 | - * Retrieves all warnings that were generated during parsing, |
|
| 259 | - * if any. |
|
| 260 | - * |
|
| 261 | - * @return Localization_Parser_Warning[] |
|
| 262 | - */ |
|
| 257 | + /** |
|
| 258 | + * Retrieves all warnings that were generated during parsing, |
|
| 259 | + * if any. |
|
| 260 | + * |
|
| 261 | + * @return Localization_Parser_Warning[] |
|
| 262 | + */ |
|
| 263 | 263 | public function getWarnings() : array |
| 264 | 264 | { |
| 265 | 265 | return $this->warnings; |
| 266 | 266 | } |
| 267 | 267 | |
| 268 | - /** |
|
| 269 | - * Creates a token instance: this retrieves information on |
|
| 270 | - * the language token being parsed. |
|
| 271 | - * |
|
| 272 | - * @param array|string $definition The token definition. |
|
| 273 | - * @param Localization_Parser_Token|NULL $parentToken |
|
| 274 | - * @return Localization_Parser_Token |
|
| 275 | - */ |
|
| 268 | + /** |
|
| 269 | + * Creates a token instance: this retrieves information on |
|
| 270 | + * the language token being parsed. |
|
| 271 | + * |
|
| 272 | + * @param array|string $definition The token definition. |
|
| 273 | + * @param Localization_Parser_Token|NULL $parentToken |
|
| 274 | + * @return Localization_Parser_Token |
|
| 275 | + */ |
|
| 276 | 276 | protected function createToken($definition, Localization_Parser_Token $parentToken=null) : Localization_Parser_Token |
| 277 | 277 | { |
| 278 | 278 | $class = Localization_Parser_Token::class.'_'.$this->getID(); |
@@ -280,12 +280,12 @@ discard block |
||
| 280 | 280 | return new $class($definition, $parentToken); |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | - /** |
|
| 284 | - * Parses a translation function token. |
|
| 285 | - * |
|
| 286 | - * @param int $number |
|
| 287 | - * @param Localization_Parser_Token $token |
|
| 288 | - */ |
|
| 283 | + /** |
|
| 284 | + * Parses a translation function token. |
|
| 285 | + * |
|
| 286 | + * @param int $number |
|
| 287 | + * @param Localization_Parser_Token $token |
|
| 288 | + */ |
|
| 289 | 289 | protected function parseToken(int $number, Localization_Parser_Token $token) : void |
| 290 | 290 | { |
| 291 | 291 | $textParts = array(); |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | */ |
| 98 | 98 | public function getID() : string |
| 99 | 99 | { |
| 100 | - if(!isset($this->id)) { |
|
| 100 | + if (!isset($this->id)) { |
|
| 101 | 101 | $this->id = str_replace(Localization_Parser_Language::class.'_', '', get_class($this)); |
| 102 | 102 | } |
| 103 | 103 | |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | */ |
| 123 | 123 | public function parseFile(string $path) : void |
| 124 | 124 | { |
| 125 | - if(!file_exists($path)) |
|
| 125 | + if (!file_exists($path)) |
|
| 126 | 126 | { |
| 127 | 127 | throw new Localization_Exception( |
| 128 | 128 | sprintf('Source code file [%s] not found', basename($path)), |
@@ -175,12 +175,12 @@ discard block |
||
| 175 | 175 | $this->tokens = $this->getTokens(); |
| 176 | 176 | $this->totalTokens = count($this->tokens); |
| 177 | 177 | |
| 178 | - for($i = 0; $i < $this->totalTokens; $i++) |
|
| 178 | + for ($i = 0; $i < $this->totalTokens; $i++) |
|
| 179 | 179 | { |
| 180 | 180 | $token = $this->createToken($this->tokens[$i]); |
| 181 | 181 | |
| 182 | - if($token->isTranslationFunction()) { |
|
| 183 | - $this->parseToken($i+1, $token); |
|
| 182 | + if ($token->isTranslationFunction()) { |
|
| 183 | + $this->parseToken($i + 1, $token); |
|
| 184 | 184 | } |
| 185 | 185 | } |
| 186 | 186 | } |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | return self::$allowedContextTags; |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | - protected function addResult(string $text, int $line=0, string $explanation='') : void |
|
| 207 | + protected function addResult(string $text, int $line = 0, string $explanation = '') : void |
|
| 208 | 208 | { |
| 209 | 209 | $this->log(sprintf('Line [%1$s] | Found string [%2$s]', $line, $text)); |
| 210 | 210 | |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | * @param Localization_Parser_Token|NULL $parentToken |
| 274 | 274 | * @return Localization_Parser_Token |
| 275 | 275 | */ |
| 276 | - protected function createToken($definition, Localization_Parser_Token $parentToken=null) : Localization_Parser_Token |
|
| 276 | + protected function createToken($definition, Localization_Parser_Token $parentToken = null) : Localization_Parser_Token |
|
| 277 | 277 | { |
| 278 | 278 | $class = Localization_Parser_Token::class.'_'.$this->getID(); |
| 279 | 279 | |
@@ -293,48 +293,48 @@ discard block |
||
| 293 | 293 | $open = false; |
| 294 | 294 | $explanation = ''; |
| 295 | 295 | |
| 296 | - for($i = $number; $i < $max; $i++) |
|
| 296 | + for ($i = $number; $i < $max; $i++) |
|
| 297 | 297 | { |
| 298 | - if(!isset($this->tokens[$i])) { |
|
| 298 | + if (!isset($this->tokens[$i])) { |
|
| 299 | 299 | break; |
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | $subToken = $this->createToken($this->tokens[$i], $token); |
| 303 | 303 | |
| 304 | - if(!$open && $subToken->isOpeningFuncParams()) |
|
| 304 | + if (!$open && $subToken->isOpeningFuncParams()) |
|
| 305 | 305 | { |
| 306 | 306 | $open = true; |
| 307 | 307 | continue; |
| 308 | 308 | } |
| 309 | 309 | |
| 310 | - if($open && $subToken->isClosingFuncParams()) { |
|
| 310 | + if ($open && $subToken->isClosingFuncParams()) { |
|
| 311 | 311 | break; |
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | // additional parameters in the translation function, we don't want to capture these now. |
| 315 | - if($open && $subToken->isArgumentSeparator()) |
|
| 315 | + if ($open && $subToken->isArgumentSeparator()) |
|
| 316 | 316 | { |
| 317 | - if($token->isExplanationFunction()) { |
|
| 318 | - $leftover = array_slice($this->tokens, $i+1); |
|
| 317 | + if ($token->isExplanationFunction()) { |
|
| 318 | + $leftover = array_slice($this->tokens, $i + 1); |
|
| 319 | 319 | $explanation = $this->parseExplanation($token, $leftover); |
| 320 | 320 | } |
| 321 | 321 | break; |
| 322 | 322 | } |
| 323 | 323 | |
| 324 | - if($open && $subToken->isEncapsedString()) |
|
| 324 | + if ($open && $subToken->isEncapsedString()) |
|
| 325 | 325 | { |
| 326 | 326 | $textParts[] = $this->trimText(strval($subToken->getValue())); |
| 327 | 327 | continue; |
| 328 | 328 | } |
| 329 | 329 | |
| 330 | - if($open && $subToken->isVariableOrFunction()) { |
|
| 330 | + if ($open && $subToken->isVariableOrFunction()) { |
|
| 331 | 331 | $textParts = null; |
| 332 | 332 | $this->addWarning($subToken, t('Variables or functions are not supported in translation functions.')); |
| 333 | 333 | break; |
| 334 | 334 | } |
| 335 | 335 | } |
| 336 | 336 | |
| 337 | - if(empty($textParts)) { |
|
| 337 | + if (empty($textParts)) { |
|
| 338 | 338 | return; |
| 339 | 339 | } |
| 340 | 340 | |
@@ -348,38 +348,38 @@ discard block |
||
| 348 | 348 | $textParts = array(); |
| 349 | 349 | $max = 200; |
| 350 | 350 | |
| 351 | - for($i = 0; $i < $max; $i++) |
|
| 351 | + for ($i = 0; $i < $max; $i++) |
|
| 352 | 352 | { |
| 353 | - if(!isset($tokens[$i])) { |
|
| 353 | + if (!isset($tokens[$i])) { |
|
| 354 | 354 | break; |
| 355 | 355 | } |
| 356 | 356 | |
| 357 | 357 | $subToken = $this->createToken($tokens[$i], $token); |
| 358 | 358 | |
| 359 | - if($subToken->isClosingFuncParams()) { |
|
| 359 | + if ($subToken->isClosingFuncParams()) { |
|
| 360 | 360 | break; |
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | // additional parameters in the translation function, we don't want to capture these now. |
| 364 | - if($subToken->isArgumentSeparator()) |
|
| 364 | + if ($subToken->isArgumentSeparator()) |
|
| 365 | 365 | { |
| 366 | 366 | break; |
| 367 | 367 | } |
| 368 | 368 | |
| 369 | - if($subToken->isEncapsedString()) |
|
| 369 | + if ($subToken->isEncapsedString()) |
|
| 370 | 370 | { |
| 371 | 371 | $textParts[] = $this->trimText(strval($subToken->getValue())); |
| 372 | 372 | continue; |
| 373 | 373 | } |
| 374 | 374 | |
| 375 | - if($subToken->isVariableOrFunction()) { |
|
| 375 | + if ($subToken->isVariableOrFunction()) { |
|
| 376 | 376 | $textParts = null; |
| 377 | 377 | $this->addWarning($subToken, t('Variables or functions are not supported in translation functions.')); |
| 378 | 378 | break; |
| 379 | 379 | } |
| 380 | 380 | } |
| 381 | 381 | |
| 382 | - if(empty($textParts)) { |
|
| 382 | + if (empty($textParts)) { |
|
| 383 | 383 | return ''; |
| 384 | 384 | } |
| 385 | 385 | |
@@ -388,7 +388,7 @@ discard block |
||
| 388 | 388 | |
| 389 | 389 | protected function debug(string $text) : void |
| 390 | 390 | { |
| 391 | - if($this->debug) { |
|
| 391 | + if ($this->debug) { |
|
| 392 | 392 | echo $text; |
| 393 | 393 | } |
| 394 | 394 | } |