@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | |
| 107 | 107 | $texts = $language->getTexts(); |
| 108 | 108 | |
| 109 | - foreach($texts as $text) |
|
| 109 | + foreach ($texts as $text) |
|
| 110 | 110 | { |
| 111 | 111 | $this->collection->addFromFile( |
| 112 | 112 | $this->getID(), |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | |
| 119 | 119 | $warnings = $language->getWarnings(); |
| 120 | 120 | |
| 121 | - foreach($warnings as $warning) { |
|
| 121 | + foreach ($warnings as $warning) { |
|
| 122 | 122 | $this->collection->addWarning($warning); |
| 123 | 123 | } |
| 124 | 124 | } |
@@ -145,9 +145,9 @@ discard block |
||
| 145 | 145 | $amount = 0; |
| 146 | 146 | |
| 147 | 147 | $hashes = $this->getHashes($scanner); |
| 148 | - foreach($hashes as $hash) { |
|
| 148 | + foreach ($hashes as $hash) { |
|
| 149 | 149 | $text = $translator->getHashTranslation($hash->getHash()); |
| 150 | - if(empty($text)) { |
|
| 150 | + if (empty($text)) { |
|
| 151 | 151 | $amount++; |
| 152 | 152 | } |
| 153 | 153 | } |
@@ -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 | protected $languageMappings = array( |
@@ -51,15 +51,15 @@ discard block |
||
| 51 | 51 | $this->collection = $scanner->getCollection(); |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Parses a source file. Must have a valid supported file extension. |
|
| 56 | - * |
|
| 57 | - * @param string $path |
|
| 58 | - * @return Localization_Parser_Language |
|
| 59 | - * @throws Localization_Exception |
|
| 60 | - * |
|
| 61 | - * @see Localization_Parser::ERROR_UNSUPPORTED_FILE_EXTENSION |
|
| 62 | - */ |
|
| 54 | + /** |
|
| 55 | + * Parses a source file. Must have a valid supported file extension. |
|
| 56 | + * |
|
| 57 | + * @param string $path |
|
| 58 | + * @return Localization_Parser_Language |
|
| 59 | + * @throws Localization_Exception |
|
| 60 | + * |
|
| 61 | + * @see Localization_Parser::ERROR_UNSUPPORTED_FILE_EXTENSION |
|
| 62 | + */ |
|
| 63 | 63 | public function parseFile(string $path) : Localization_Parser_Language |
| 64 | 64 | { |
| 65 | 65 | $this->requireValidFile($path); |
@@ -73,16 +73,16 @@ discard block |
||
| 73 | 73 | return $language; |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * Parses the string for the specified language. |
|
| 78 | - * |
|
| 79 | - * @param string $languageID |
|
| 80 | - * @param string $code |
|
| 81 | - * @return Localization_Parser_Language |
|
| 82 | - * @throws Localization_Exception |
|
| 83 | - * |
|
| 84 | - * @see Localization_Parser::ERROR_INVALID_LANGUAGE_ID |
|
| 85 | - */ |
|
| 76 | + /** |
|
| 77 | + * Parses the string for the specified language. |
|
| 78 | + * |
|
| 79 | + * @param string $languageID |
|
| 80 | + * @param string $code |
|
| 81 | + * @return Localization_Parser_Language |
|
| 82 | + * @throws Localization_Exception |
|
| 83 | + * |
|
| 84 | + * @see Localization_Parser::ERROR_INVALID_LANGUAGE_ID |
|
| 85 | + */ |
|
| 86 | 86 | public function parseString(string $languageID, string $code) : Localization_Parser_Language |
| 87 | 87 | { |
| 88 | 88 | $this->requireValidLanguageID($languageID); |
@@ -141,18 +141,18 @@ discard block |
||
| 141 | 141 | ); |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - /** |
|
| 145 | - * Retrieves a list of all language IDs that are supported. |
|
| 146 | - * @return string[] IDs list like "PHP", "Javascript" |
|
| 147 | - */ |
|
| 144 | + /** |
|
| 145 | + * Retrieves a list of all language IDs that are supported. |
|
| 146 | + * @return string[] IDs list like "PHP", "Javascript" |
|
| 147 | + */ |
|
| 148 | 148 | public function getLanguageIDs() : array |
| 149 | 149 | { |
| 150 | 150 | return array_values($this->languageMappings); |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | - /** |
|
| 154 | - * @var array<string,Localization_Parser_Language> |
|
| 155 | - */ |
|
| 153 | + /** |
|
| 154 | + * @var array<string,Localization_Parser_Language> |
|
| 155 | + */ |
|
| 156 | 156 | protected $languageParsers = array(); |
| 157 | 157 | |
| 158 | 158 | /** |
@@ -206,12 +206,12 @@ discard block |
||
| 206 | 206 | ); |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | - /** |
|
| 210 | - * Whether the specified file extension is supported. |
|
| 211 | - * |
|
| 212 | - * @param string $ext |
|
| 213 | - * @return bool |
|
| 214 | - */ |
|
| 209 | + /** |
|
| 210 | + * Whether the specified file extension is supported. |
|
| 211 | + * |
|
| 212 | + * @param string $ext |
|
| 213 | + * @return bool |
|
| 214 | + */ |
|
| 215 | 215 | public function isExtensionSupported(string $ext) : bool |
| 216 | 216 | { |
| 217 | 217 | $ext = strtolower($ext); |
@@ -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 | } |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | |
| 58 | 58 | public function addSources($sources) |
| 59 | 59 | { |
| 60 | - foreach($sources as $source) { |
|
| 60 | + foreach ($sources as $source) { |
|
| 61 | 61 | $this->addSource($source); |
| 62 | 62 | } |
| 63 | 63 | } |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | $this->strings[$localeName] = array(); |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - foreach($this->sources as $source) |
|
| 111 | + foreach ($this->sources as $source) |
|
| 112 | 112 | { |
| 113 | 113 | $file = $this->resolveStorageFile($locale, $source); |
| 114 | 114 | if (!file_exists($file)) { |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | |
| 118 | 118 | $data = parse_ini_file($file, false); |
| 119 | 119 | |
| 120 | - if($data === false) |
|
| 120 | + if ($data === false) |
|
| 121 | 121 | { |
| 122 | 122 | throw new Localization_Exception( |
| 123 | 123 | 'Malformatted localization file', |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | |
| 190 | 190 | $name = $locale->getName(); |
| 191 | 191 | |
| 192 | - if(isset($this->strings[$name])) { |
|
| 192 | + if (isset($this->strings[$name])) { |
|
| 193 | 193 | return $this->strings[$name]; |
| 194 | 194 | } |
| 195 | 195 | |
@@ -219,11 +219,11 @@ discard block |
||
| 219 | 219 | * @param boolean $editable |
| 220 | 220 | * @throws Localization_Exception |
| 221 | 221 | */ |
| 222 | - protected function renderStringsFile($type, Localization_Source $source, $hashes, $file, Localization_Locale $locale, $editable=true) |
|
| 222 | + protected function renderStringsFile($type, Localization_Source $source, $hashes, $file, Localization_Locale $locale, $editable = true) |
|
| 223 | 223 | { |
| 224 | 224 | $writer = new Localization_Writer($locale, $type, $file); |
| 225 | 225 | |
| 226 | - if($editable) |
|
| 226 | + if ($editable) |
|
| 227 | 227 | { |
| 228 | 228 | $writer->makeEditable(); |
| 229 | 229 | } |
@@ -232,14 +232,14 @@ discard block |
||
| 232 | 232 | |
| 233 | 233 | foreach ($hashes as $hash) |
| 234 | 234 | { |
| 235 | - if(!$hash->hasSourceID($sourceID)) { |
|
| 235 | + if (!$hash->hasSourceID($sourceID)) { |
|
| 236 | 236 | continue; |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | $text = $this->getHashTranslation($hash->getHash(), $locale); |
| 240 | 240 | |
| 241 | 241 | // skip any empty strings |
| 242 | - if($text === null || trim($text) == '') { |
|
| 242 | + if ($text === null || trim($text) == '') { |
|
| 243 | 243 | continue; |
| 244 | 244 | } |
| 245 | 245 | |
@@ -317,7 +317,7 @@ discard block |
||
| 317 | 317 | { |
| 318 | 318 | // to avoid re-creating the hash for the same texts over and over, |
| 319 | 319 | // we keep track of the hashes we created, and re-use them. |
| 320 | - if(isset($this->reverseStrings[$text])) { |
|
| 320 | + if (isset($this->reverseStrings[$text])) { |
|
| 321 | 321 | $hash = $this->reverseStrings[$text]; |
| 322 | 322 | } else { |
| 323 | 323 | $hash = md5($text); |
@@ -380,15 +380,15 @@ discard block |
||
| 380 | 380 | * @param string $hash |
| 381 | 381 | * @return string|NULL |
| 382 | 382 | */ |
| 383 | - public function getHashTranslation($hash, Localization_Locale $locale=null) |
|
| 383 | + public function getHashTranslation($hash, Localization_Locale $locale = null) |
|
| 384 | 384 | { |
| 385 | - if(!$locale) { |
|
| 385 | + if (!$locale) { |
|
| 386 | 386 | $locale = $this->targetLocale; |
| 387 | 387 | } |
| 388 | 388 | |
| 389 | 389 | $localeName = $locale->getName(); |
| 390 | 390 | |
| 391 | - if(isset($this->strings[$localeName]) && isset($this->strings[$localeName][$hash])) { |
|
| 391 | + if (isset($this->strings[$localeName]) && isset($this->strings[$localeName][$hash])) { |
|
| 392 | 392 | return $this->strings[$localeName][$hash]; |
| 393 | 393 | } |
| 394 | 394 | |
@@ -405,10 +405,10 @@ discard block |
||
| 405 | 405 | { |
| 406 | 406 | $result = array(); |
| 407 | 407 | |
| 408 | - foreach($this->sources as $source) |
|
| 408 | + foreach ($this->sources as $source) |
|
| 409 | 409 | { |
| 410 | 410 | $localeFile = self::getClientStorageFile($locale, $source); |
| 411 | - if(!file_exists($localeFile)) { |
|
| 411 | + if (!file_exists($localeFile)) { |
|
| 412 | 412 | continue; |
| 413 | 413 | } |
| 414 | 414 | |
@@ -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; |
@@ -15,12 +15,12 @@ |
||
| 15 | 15 | protected function parseDefinition() : void |
| 16 | 16 | { |
| 17 | 17 | // some entries are strings, like parentheses, semicolons and the like. |
| 18 | - if(is_string($this->definition)) |
|
| 18 | + if (is_string($this->definition)) |
|
| 19 | 19 | { |
| 20 | 20 | $this->token = $this->definition; |
| 21 | 21 | $this->value = null; |
| 22 | 22 | |
| 23 | - if(isset($this->parentToken)) { |
|
| 23 | + if (isset($this->parentToken)) { |
|
| 24 | 24 | $this->line = $this->parentToken->getLine(); |
| 25 | 25 | } |
| 26 | 26 | } |
@@ -19,8 +19,7 @@ |
||
| 19 | 19 | if(isset($this->parentToken)) { |
| 20 | 20 | $this->line = $this->parentToken->getLine(); |
| 21 | 21 | } |
| 22 | - } |
|
| 23 | - else |
|
| 22 | + } else |
|
| 24 | 23 | { |
| 25 | 24 | $this->token = JTokenizer::getTokenName($this->definition[0]); |
| 26 | 25 | $this->value = $this->definition[1]; |
@@ -6,14 +6,14 @@ discard block |
||
| 6 | 6 | |
| 7 | 7 | abstract class Localization_Parser_Token |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * @var array|string |
|
| 11 | - */ |
|
| 9 | + /** |
|
| 10 | + * @var array|string |
|
| 11 | + */ |
|
| 12 | 12 | protected $definition; |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * @var Localization_Parser_Token |
|
| 16 | - */ |
|
| 14 | + /** |
|
| 15 | + * @var Localization_Parser_Token |
|
| 16 | + */ |
|
| 17 | 17 | protected $parentToken; |
| 18 | 18 | |
| 19 | 19 | protected $token; |
@@ -86,6 +86,6 @@ discard block |
||
| 86 | 86 | 'value' => $this->getValue(), |
| 87 | 87 | 'line' => $this->getLine(), |
| 88 | 88 | 'isEncapsedString' => ConvertHelper::bool2string($this->isEncapsedString()) |
| 89 | - ); |
|
| 89 | + ); |
|
| 90 | 90 | } |
| 91 | 91 | } |
@@ -33,13 +33,13 @@ |
||
| 33 | 33 | */ |
| 34 | 34 | protected $nameLookup = array(); |
| 35 | 35 | |
| 36 | - public function __construct($definition, Localization_Parser_Token $parentToken=null) |
|
| 36 | + public function __construct($definition, Localization_Parser_Token $parentToken = null) |
|
| 37 | 37 | { |
| 38 | 38 | $this->definition = $definition; |
| 39 | 39 | $this->parentToken = $parentToken; |
| 40 | 40 | |
| 41 | 41 | $names = $this->getFunctionNames(); |
| 42 | - foreach($names as $name) { |
|
| 42 | + foreach ($names as $name) { |
|
| 43 | 43 | $this->nameLookup[$name] = true; |
| 44 | 44 | } |
| 45 | 45 | |
@@ -21,49 +21,49 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | protected $parser; |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * The function names that are included in the search. |
|
| 26 | - * @var array |
|
| 27 | - */ |
|
| 24 | + /** |
|
| 25 | + * The function names that are included in the search. |
|
| 26 | + * @var array |
|
| 27 | + */ |
|
| 28 | 28 | protected $functionNames = array(); |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * The tokens definitions. |
|
| 32 | - * @var array |
|
| 33 | - */ |
|
| 30 | + /** |
|
| 31 | + * The tokens definitions. |
|
| 32 | + * @var array |
|
| 33 | + */ |
|
| 34 | 34 | protected $tokens = array(); |
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * The total amount of tokens found in the content. |
|
| 38 | - * @var integer |
|
| 39 | - */ |
|
| 36 | + /** |
|
| 37 | + * The total amount of tokens found in the content. |
|
| 38 | + * @var integer |
|
| 39 | + */ |
|
| 40 | 40 | protected $totalTokens = 0; |
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * All texts that have been collected. |
|
| 44 | - * @var Text[] |
|
| 45 | - */ |
|
| 42 | + /** |
|
| 43 | + * All texts that have been collected. |
|
| 44 | + * @var Text[] |
|
| 45 | + */ |
|
| 46 | 46 | protected $texts = array(); |
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * @var string |
|
| 50 | - */ |
|
| 48 | + /** |
|
| 49 | + * @var string |
|
| 50 | + */ |
|
| 51 | 51 | protected $content = ''; |
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @var string|NULL |
|
| 55 | - */ |
|
| 53 | + /** |
|
| 54 | + * @var string|NULL |
|
| 55 | + */ |
|
| 56 | 56 | protected $id; |
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * @var Localization_Parser_Warning[] |
|
| 60 | - */ |
|
| 58 | + /** |
|
| 59 | + * @var Localization_Parser_Warning[] |
|
| 60 | + */ |
|
| 61 | 61 | protected $warnings = array(); |
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * The source file that was parsed (if any) |
|
| 65 | - * @var string |
|
| 66 | - */ |
|
| 63 | + /** |
|
| 64 | + * The source file that was parsed (if any) |
|
| 65 | + * @var string |
|
| 66 | + */ |
|
| 67 | 67 | protected $sourceFile = ''; |
| 68 | 68 | |
| 69 | 69 | public function __construct(Localization_Parser $parser) |
@@ -74,10 +74,10 @@ discard block |
||
| 74 | 74 | |
| 75 | 75 | abstract protected function getTokens() : array; |
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * Retrieves the ID of the language. |
|
| 79 | - * @return string E.g. "PHP", "Javascript" |
|
| 80 | - */ |
|
| 77 | + /** |
|
| 78 | + * Retrieves the ID of the language. |
|
| 79 | + * @return string E.g. "PHP", "Javascript" |
|
| 80 | + */ |
|
| 81 | 81 | public function getID() : string |
| 82 | 82 | { |
| 83 | 83 | if(!isset($this->id)) { |
@@ -97,12 +97,12 @@ discard block |
||
| 97 | 97 | return $this->sourceFile; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * Parses the code from a file. |
|
| 102 | - * |
|
| 103 | - * @param string $path |
|
| 104 | - * @throws Localization_Exception |
|
| 105 | - */ |
|
| 100 | + /** |
|
| 101 | + * Parses the code from a file. |
|
| 102 | + * |
|
| 103 | + * @param string $path |
|
| 104 | + * @throws Localization_Exception |
|
| 105 | + */ |
|
| 106 | 106 | public function parseFile(string $path) : void |
| 107 | 107 | { |
| 108 | 108 | if(!file_exists($path)) |
@@ -135,10 +135,10 @@ discard block |
||
| 135 | 135 | ); |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | - /** |
|
| 139 | - * Parses a source code string. |
|
| 140 | - * @param string $content |
|
| 141 | - */ |
|
| 138 | + /** |
|
| 139 | + * Parses a source code string. |
|
| 140 | + * @param string $content |
|
| 141 | + */ |
|
| 142 | 142 | public function parseString($content) : void |
| 143 | 143 | { |
| 144 | 144 | $this->content = $content; |
@@ -179,11 +179,11 @@ discard block |
||
| 179 | 179 | $this->texts[] = new Text($text, $line, $explanation); |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | - /** |
|
| 183 | - * Retrieves a list of all the function names that are |
|
| 184 | - * used as translation functions in the language. |
|
| 185 | - * @return array |
|
| 186 | - */ |
|
| 182 | + /** |
|
| 183 | + * Retrieves a list of all the function names that are |
|
| 184 | + * used as translation functions in the language. |
|
| 185 | + * @return array |
|
| 186 | + */ |
|
| 187 | 187 | public function getFunctionNames() : array |
| 188 | 188 | { |
| 189 | 189 | return $this->createToken('dummy')->getFunctionNames(); |
@@ -194,13 +194,13 @@ discard block |
||
| 194 | 194 | Localization::log(sprintf('%1$s parser | %2$s', $this->getID(), $message)); |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | - /** |
|
| 198 | - * Adds a warning message when a text cannot be parsed correctly for some reason. |
|
| 199 | - * |
|
| 200 | - * @param Localization_Parser_Token $token |
|
| 201 | - * @param string $message |
|
| 202 | - * @return Localization_Parser_Warning |
|
| 203 | - */ |
|
| 197 | + /** |
|
| 198 | + * Adds a warning message when a text cannot be parsed correctly for some reason. |
|
| 199 | + * |
|
| 200 | + * @param Localization_Parser_Token $token |
|
| 201 | + * @param string $message |
|
| 202 | + * @return Localization_Parser_Warning |
|
| 203 | + */ |
|
| 204 | 204 | protected function addWarning(Localization_Parser_Token $token, string $message) : Localization_Parser_Warning |
| 205 | 205 | { |
| 206 | 206 | $warning = new Localization_Parser_Warning($this, $token, $message); |
@@ -210,34 +210,34 @@ discard block |
||
| 210 | 210 | return $warning; |
| 211 | 211 | } |
| 212 | 212 | |
| 213 | - /** |
|
| 214 | - * Whether any warnings were generated during parsing. |
|
| 215 | - * @return bool |
|
| 216 | - */ |
|
| 213 | + /** |
|
| 214 | + * Whether any warnings were generated during parsing. |
|
| 215 | + * @return bool |
|
| 216 | + */ |
|
| 217 | 217 | public function hasWarnings() : bool |
| 218 | 218 | { |
| 219 | 219 | return !empty($this->warnings); |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | - /** |
|
| 223 | - * Retrieves all warnings that were generated during parsing, |
|
| 224 | - * if any. |
|
| 225 | - * |
|
| 226 | - * @return Localization_Parser_Warning[] |
|
| 227 | - */ |
|
| 222 | + /** |
|
| 223 | + * Retrieves all warnings that were generated during parsing, |
|
| 224 | + * if any. |
|
| 225 | + * |
|
| 226 | + * @return Localization_Parser_Warning[] |
|
| 227 | + */ |
|
| 228 | 228 | public function getWarnings() : array |
| 229 | 229 | { |
| 230 | 230 | return $this->warnings; |
| 231 | 231 | } |
| 232 | 232 | |
| 233 | - /** |
|
| 234 | - * Creates a token instance: this retrieves information on |
|
| 235 | - * the language token being parsed. |
|
| 236 | - * |
|
| 237 | - * @param array|string $definition The token definition. |
|
| 238 | - * @param Localization_Parser_Token|NULL $parentToken |
|
| 239 | - * @return Localization_Parser_Token |
|
| 240 | - */ |
|
| 233 | + /** |
|
| 234 | + * Creates a token instance: this retrieves information on |
|
| 235 | + * the language token being parsed. |
|
| 236 | + * |
|
| 237 | + * @param array|string $definition The token definition. |
|
| 238 | + * @param Localization_Parser_Token|NULL $parentToken |
|
| 239 | + * @return Localization_Parser_Token |
|
| 240 | + */ |
|
| 241 | 241 | protected function createToken($definition, Localization_Parser_Token $parentToken=null) : Localization_Parser_Token |
| 242 | 242 | { |
| 243 | 243 | $class = Localization_Parser_Token::class.'_'.$this->getID(); |
@@ -245,12 +245,12 @@ discard block |
||
| 245 | 245 | return new $class($definition, $parentToken); |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | - /** |
|
| 249 | - * Parses a translation function token. |
|
| 250 | - * |
|
| 251 | - * @param int $number |
|
| 252 | - * @param Localization_Parser_Token $token |
|
| 253 | - */ |
|
| 248 | + /** |
|
| 249 | + * Parses a translation function token. |
|
| 250 | + * |
|
| 251 | + * @param int $number |
|
| 252 | + * @param Localization_Parser_Token $token |
|
| 253 | + */ |
|
| 254 | 254 | protected function parseToken(int $number, Localization_Parser_Token $token) : void |
| 255 | 255 | { |
| 256 | 256 | $textParts = array(); |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | */ |
| 81 | 81 | public function getID() : string |
| 82 | 82 | { |
| 83 | - if(!isset($this->id)) { |
|
| 83 | + if (!isset($this->id)) { |
|
| 84 | 84 | $this->id = str_replace(Localization_Parser_Language::class.'_', '', get_class($this)); |
| 85 | 85 | } |
| 86 | 86 | |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | */ |
| 106 | 106 | public function parseFile(string $path) : void |
| 107 | 107 | { |
| 108 | - if(!file_exists($path)) |
|
| 108 | + if (!file_exists($path)) |
|
| 109 | 109 | { |
| 110 | 110 | throw new Localization_Exception( |
| 111 | 111 | sprintf('Source code file [%s] not found', basename($path)), |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | $this->sourceFile = $path; |
| 121 | 121 | $this->content = file_get_contents($path); |
| 122 | 122 | |
| 123 | - if($this->content !== false) { |
|
| 123 | + if ($this->content !== false) { |
|
| 124 | 124 | $this->parse(); |
| 125 | 125 | return; |
| 126 | 126 | } |
@@ -154,12 +154,12 @@ discard block |
||
| 154 | 154 | $this->tokens = $this->getTokens(); |
| 155 | 155 | $this->totalTokens = count($this->tokens); |
| 156 | 156 | |
| 157 | - for($i = 0; $i < $this->totalTokens; $i++) |
|
| 157 | + for ($i = 0; $i < $this->totalTokens; $i++) |
|
| 158 | 158 | { |
| 159 | 159 | $token = $this->createToken($this->tokens[$i]); |
| 160 | 160 | |
| 161 | - if($token->isTranslationFunction()) { |
|
| 162 | - $this->parseToken($i+1, $token); |
|
| 161 | + if ($token->isTranslationFunction()) { |
|
| 162 | + $this->parseToken($i + 1, $token); |
|
| 163 | 163 | } |
| 164 | 164 | } |
| 165 | 165 | } |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | return $this->texts; |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | - protected function addResult(string $text, int $line=0, string $explanation='') |
|
| 175 | + protected function addResult(string $text, int $line = 0, string $explanation = '') |
|
| 176 | 176 | { |
| 177 | 177 | $this->log(sprintf('Line [%1$s] | Found string [%2$s]', $line, $text)); |
| 178 | 178 | |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | * @param Localization_Parser_Token|NULL $parentToken |
| 239 | 239 | * @return Localization_Parser_Token |
| 240 | 240 | */ |
| 241 | - protected function createToken($definition, Localization_Parser_Token $parentToken=null) : Localization_Parser_Token |
|
| 241 | + protected function createToken($definition, Localization_Parser_Token $parentToken = null) : Localization_Parser_Token |
|
| 242 | 242 | { |
| 243 | 243 | $class = Localization_Parser_Token::class.'_'.$this->getID(); |
| 244 | 244 | |
@@ -258,48 +258,48 @@ discard block |
||
| 258 | 258 | $open = false; |
| 259 | 259 | $explanation = ''; |
| 260 | 260 | |
| 261 | - for($i = $number; $i < $max; $i++) |
|
| 261 | + for ($i = $number; $i < $max; $i++) |
|
| 262 | 262 | { |
| 263 | - if(!isset($this->tokens[$i])) { |
|
| 263 | + if (!isset($this->tokens[$i])) { |
|
| 264 | 264 | break; |
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | $subToken = $this->createToken($this->tokens[$i], $token); |
| 268 | 268 | |
| 269 | - if(!$open && $subToken->isOpeningFuncParams()) |
|
| 269 | + if (!$open && $subToken->isOpeningFuncParams()) |
|
| 270 | 270 | { |
| 271 | 271 | $open = true; |
| 272 | 272 | continue; |
| 273 | 273 | } |
| 274 | 274 | |
| 275 | - if($open && $subToken->isClosingFuncParams()) { |
|
| 275 | + if ($open && $subToken->isClosingFuncParams()) { |
|
| 276 | 276 | break; |
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | // additional parameters in the translation function, we don't want to capture these now. |
| 280 | - if($open && $subToken->isArgumentSeparator()) |
|
| 280 | + if ($open && $subToken->isArgumentSeparator()) |
|
| 281 | 281 | { |
| 282 | - if($token->isExplanationFunction()) { |
|
| 283 | - $leftover = array_slice($this->tokens, $i+1); |
|
| 282 | + if ($token->isExplanationFunction()) { |
|
| 283 | + $leftover = array_slice($this->tokens, $i + 1); |
|
| 284 | 284 | $explanation = $this->parseExplanation($token, $leftover); |
| 285 | 285 | } |
| 286 | 286 | break; |
| 287 | 287 | } |
| 288 | 288 | |
| 289 | - if($open && $subToken->isEncapsedString()) |
|
| 289 | + if ($open && $subToken->isEncapsedString()) |
|
| 290 | 290 | { |
| 291 | 291 | $textParts[] = $this->trimText($subToken->getValue()); |
| 292 | 292 | continue; |
| 293 | 293 | } |
| 294 | 294 | |
| 295 | - if($open && $subToken->isVariableOrFunction()) { |
|
| 295 | + if ($open && $subToken->isVariableOrFunction()) { |
|
| 296 | 296 | $textParts = null; |
| 297 | 297 | $this->addWarning($subToken, t('Variables or functions are not supported in translation functions.')); |
| 298 | 298 | break; |
| 299 | 299 | } |
| 300 | 300 | } |
| 301 | 301 | |
| 302 | - if(empty($textParts)) { |
|
| 302 | + if (empty($textParts)) { |
|
| 303 | 303 | return; |
| 304 | 304 | } |
| 305 | 305 | |
@@ -313,38 +313,38 @@ discard block |
||
| 313 | 313 | $textParts = array(); |
| 314 | 314 | $max = 200; |
| 315 | 315 | |
| 316 | - for($i = 0; $i < $max; $i++) |
|
| 316 | + for ($i = 0; $i < $max; $i++) |
|
| 317 | 317 | { |
| 318 | - if(!isset($tokens[$i])) { |
|
| 318 | + if (!isset($tokens[$i])) { |
|
| 319 | 319 | break; |
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | $subToken = $this->createToken($tokens[$i], $token); |
| 323 | 323 | |
| 324 | - if($subToken->isClosingFuncParams()) { |
|
| 324 | + if ($subToken->isClosingFuncParams()) { |
|
| 325 | 325 | break; |
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | // additional parameters in the translation function, we don't want to capture these now. |
| 329 | - if($subToken->isArgumentSeparator()) |
|
| 329 | + if ($subToken->isArgumentSeparator()) |
|
| 330 | 330 | { |
| 331 | 331 | break; |
| 332 | 332 | } |
| 333 | 333 | |
| 334 | - if($subToken->isEncapsedString()) |
|
| 334 | + if ($subToken->isEncapsedString()) |
|
| 335 | 335 | { |
| 336 | 336 | $textParts[] = $this->trimText($subToken->getValue()); |
| 337 | 337 | continue; |
| 338 | 338 | } |
| 339 | 339 | |
| 340 | - if($subToken->isVariableOrFunction()) { |
|
| 340 | + if ($subToken->isVariableOrFunction()) { |
|
| 341 | 341 | $textParts = null; |
| 342 | 342 | $this->addWarning($subToken, t('Variables or functions are not supported in translation functions.')); |
| 343 | 343 | break; |
| 344 | 344 | } |
| 345 | 345 | } |
| 346 | 346 | |
| 347 | - if(empty($textParts)) { |
|
| 347 | + if (empty($textParts)) { |
|
| 348 | 348 | return ''; |
| 349 | 349 | } |
| 350 | 350 | |
@@ -353,7 +353,7 @@ discard block |
||
| 353 | 353 | |
| 354 | 354 | protected function debug($text) |
| 355 | 355 | { |
| 356 | - if($this->debug) { |
|
| 356 | + if ($this->debug) { |
|
| 357 | 357 | echo $text; |
| 358 | 358 | } |
| 359 | 359 | } |
@@ -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 | |