@@ -15,7 +15,7 @@ |
||
15 | 15 | */ |
16 | 16 | public function decide(int $n): int |
17 | 17 | { |
18 | - $lastTwo = $n % 100; |
|
18 | + $lastTwo=$n % 100; |
|
19 | 19 | |
20 | 20 | if ($lastTwo === 1) { |
21 | 21 | return 0; |
@@ -19,7 +19,7 @@ |
||
19 | 19 | return 0; |
20 | 20 | } |
21 | 21 | |
22 | - $end = $n % 10; |
|
22 | + $end=$n % 10; |
|
23 | 23 | |
24 | 24 | return 2 <= $end && $end <= 4 && ($n % 100 < 10 || $n % 100 >= 20) ? 1 : 2; |
25 | 25 | } |
@@ -15,8 +15,8 @@ |
||
15 | 15 | */ |
16 | 16 | public function decide(int $n): int |
17 | 17 | { |
18 | - $lastTwo = $n % 100; |
|
19 | - $end = $lastTwo % 10; |
|
18 | + $lastTwo=$n % 100; |
|
19 | + $end=$lastTwo % 10; |
|
20 | 20 | |
21 | 21 | if ($lastTwo !== 11 && $end === 1) { |
22 | 22 | return 0; |
@@ -20,7 +20,7 @@ |
||
20 | 20 | return $n; |
21 | 21 | } |
22 | 22 | |
23 | - $lastTwo = $n % 100; |
|
23 | + $lastTwo=$n % 100; |
|
24 | 24 | if ($lastTwo >= 3 && $lastTwo <= 10) { |
25 | 25 | return 3; |
26 | 26 | } |
@@ -68,7 +68,7 @@ |
||
68 | 68 | $allowMissing = ($options['allowMissing'] ?? false) === true |
69 | 69 | ? static function ($key, $options, $locale, $tokenRegex, Polyglot $polyglot) { |
70 | 70 | return $polyglot->transformPhrase($key, $options, $locale, $tokenRegex); |
71 | - } |
|
71 | + } |
|
72 | 72 | : null; |
73 | 73 | $this->onMissingKey = is_callable($options['onMissingKey'] ?? false) ? $options['onMissingKey'] : $allowMissing; |
74 | 74 | } |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | /** |
20 | 20 | * @var array |
21 | 21 | */ |
22 | - private $phrases = []; |
|
22 | + private $phrases=[]; |
|
23 | 23 | |
24 | 24 | /** |
25 | 25 | * @var string |
@@ -61,23 +61,23 @@ discard block |
||
61 | 61 | * |
62 | 62 | * @param array $options |
63 | 63 | */ |
64 | - public function __construct(array $options = []) |
|
64 | + public function __construct(array $options=[]) |
|
65 | 65 | { |
66 | 66 | $this->extend($options['phrases'] ?? []); |
67 | 67 | |
68 | - $this->customPluralRules = $options['pluralRules'] ?? []; |
|
68 | + $this->customPluralRules=$options['pluralRules'] ?? []; |
|
69 | 69 | $this->locale($options['locale'] ?? 'en'); |
70 | 70 | |
71 | - $this->delimiter = $options['delimiter'] ?? '||||'; |
|
72 | - $this->tokenRegex = $this->constructTokenRegex($options['interpolation'] ?? []); |
|
73 | - $this->warn = $options['warn'] ?? static function() {}; |
|
71 | + $this->delimiter=$options['delimiter'] ?? '||||'; |
|
72 | + $this->tokenRegex=$this->constructTokenRegex($options['interpolation'] ?? []); |
|
73 | + $this->warn=$options['warn'] ?? static function() {}; |
|
74 | 74 | |
75 | - $allowMissing = ($options['allowMissing'] ?? false) === true |
|
76 | - ? static function ($key, $options, $locale, $tokenRegex, Polyglot $polyglot) { |
|
75 | + $allowMissing=($options['allowMissing'] ?? false) === true |
|
76 | + ? static function($key, $options, $locale, $tokenRegex, Polyglot $polyglot) { |
|
77 | 77 | return $polyglot->transformPhrase($key, $options, $locale, $tokenRegex); |
78 | 78 | } |
79 | 79 | : null; |
80 | - $this->onMissingKey = is_callable($options['onMissingKey'] ?? false) ? $options['onMissingKey'] : $allowMissing; |
|
80 | + $this->onMissingKey=is_callable($options['onMissingKey'] ?? false) ? $options['onMissingKey'] : $allowMissing; |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -134,15 +134,15 @@ discard block |
||
134 | 134 | * @param array $morePhrases |
135 | 135 | * @param string|null $prefix |
136 | 136 | */ |
137 | - public function extend(array $morePhrases = [], ?string $prefix = null): void |
|
137 | + public function extend(array $morePhrases=[], ?string $prefix=null): void |
|
138 | 138 | { |
139 | 139 | foreach ($morePhrases as $key => $phrase) { |
140 | - $prefixedKey = $prefix !== null ? $prefix . '.' . $key : $key; |
|
140 | + $prefixedKey=$prefix !== null ? $prefix.'.'.$key : $key; |
|
141 | 141 | |
142 | 142 | if (is_array($phrase)) { |
143 | 143 | $this->extend($phrase, $prefixedKey); |
144 | 144 | } else { |
145 | - $this->phrases[$prefixedKey] = $phrase; |
|
145 | + $this->phrases[$prefixedKey]=$phrase; |
|
146 | 146 | } |
147 | 147 | } |
148 | 148 | } |
@@ -164,13 +164,13 @@ discard block |
||
164 | 164 | * @param string|array $morePhrases |
165 | 165 | * @param string|null $prefix |
166 | 166 | */ |
167 | - public function unset($morePhrases, ?string $prefix = null): void |
|
167 | + public function unset($morePhrases, ?string $prefix=null) : void |
|
168 | 168 | { |
169 | 169 | if (is_string($morePhrases)) { |
170 | 170 | unset($this->phrases[$morePhrases]); |
171 | 171 | } else { |
172 | 172 | foreach ($morePhrases as $key => $phrase) { |
173 | - $prefixedKey = $prefix !== null ? $prefix . '.' . $key : $key; |
|
173 | + $prefixedKey=$prefix !== null ? $prefix.'.'.$key : $key; |
|
174 | 174 | |
175 | 175 | if (is_array($phrase)) { |
176 | 176 | $this->unset($phrase, $prefixedKey); |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | */ |
192 | 192 | public function clear(): void |
193 | 193 | { |
194 | - $this->phrases = []; |
|
194 | + $this->phrases=[]; |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | /** |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | * @param array $newPhrases |
205 | 205 | * @param string|null $prefix |
206 | 206 | */ |
207 | - public function replace(array $newPhrases, ?string $prefix = null): void |
|
207 | + public function replace(array $newPhrases, ?string $prefix=null): void |
|
208 | 208 | { |
209 | 209 | $this->clear(); |
210 | 210 | $this->extend($newPhrases, $prefix); |
@@ -219,11 +219,11 @@ discard block |
||
219 | 219 | * |
220 | 220 | * @return string |
221 | 221 | */ |
222 | - public function locale(?string $locale = null): string |
|
222 | + public function locale(?string $locale=null): string |
|
223 | 223 | { |
224 | 224 | if ($locale !== null) { |
225 | - $this->currentLocale = $locale; |
|
226 | - $this->pluralRule = RuleFactory::make($locale, $this->customPluralRules); |
|
225 | + $this->currentLocale=$locale; |
|
226 | + $this->pluralRule=RuleFactory::make($locale, $this->customPluralRules); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | return $this->currentLocale; |
@@ -277,27 +277,27 @@ discard block |
||
277 | 277 | * |
278 | 278 | * @return string |
279 | 279 | */ |
280 | - public function t(string $key, $options = []): string |
|
280 | + public function t(string $key, $options=[]): string |
|
281 | 281 | { |
282 | - $phrase = ''; |
|
283 | - $result = ''; |
|
284 | - $options = is_int($options) ? ['smart_count' => $options] : $options; |
|
282 | + $phrase=''; |
|
283 | + $result=''; |
|
284 | + $options=is_int($options) ? ['smart_count' => $options] : $options; |
|
285 | 285 | |
286 | 286 | if ($this->has($key) && is_string($this->phrases[$key])) { |
287 | - $phrase = $this->phrases[$key]; |
|
288 | - } elseif(isset($options['_'])) { |
|
289 | - $phrase = $options['_']; |
|
287 | + $phrase=$this->phrases[$key]; |
|
288 | + } elseif (isset($options['_'])) { |
|
289 | + $phrase=$options['_']; |
|
290 | 290 | } elseif ($this->onMissingKey !== null) { |
291 | - $result = call_user_func($this->onMissingKey, $key, $options, $this->currentLocale, $this->tokenRegex, $this); |
|
291 | + $result=call_user_func($this->onMissingKey, $key, $options, $this->currentLocale, $this->tokenRegex, $this); |
|
292 | 292 | } else { |
293 | 293 | // warn missing translations |
294 | - call_user_func($this->warn, 'Missing translation for key: "' . $key . '"'); |
|
294 | + call_user_func($this->warn, 'Missing translation for key: "'.$key.'"'); |
|
295 | 295 | |
296 | - $result = $key; |
|
296 | + $result=$key; |
|
297 | 297 | } |
298 | 298 | |
299 | 299 | if (!empty($phrase)) { |
300 | - $result = $this->transformPhrase($phrase, $options, $this->currentLocale, $this->tokenRegex); |
|
300 | + $result=$this->transformPhrase($phrase, $options, $this->currentLocale, $this->tokenRegex); |
|
301 | 301 | } |
302 | 302 | |
303 | 303 | return $result; |
@@ -333,35 +333,35 @@ discard block |
||
333 | 333 | * |
334 | 334 | * @return string |
335 | 335 | */ |
336 | - public function transformPhrase(string $phrase, $substitutions = null, string $locale = 'en', ?string $tokenRegex = null): string |
|
336 | + public function transformPhrase(string $phrase, $substitutions=null, string $locale='en', ?string $tokenRegex=null): string |
|
337 | 337 | { |
338 | 338 | if ($substitutions === null) { |
339 | 339 | return $phrase; |
340 | 340 | } |
341 | 341 | |
342 | - $result = $phrase; |
|
342 | + $result=$phrase; |
|
343 | 343 | |
344 | 344 | // allow number as a pluralization shortcut |
345 | - $options = is_int($substitutions) ? ['smart_count' => $substitutions] : $substitutions; |
|
345 | + $options=is_int($substitutions) ? ['smart_count' => $substitutions] : $substitutions; |
|
346 | 346 | |
347 | 347 | // Select plural form: based on a phrase text that contains `n` |
348 | 348 | // plural forms separated by `delimiter`, a `locale`, and a `substitutions.smart_count`, |
349 | 349 | // choose the correct plural form. This is only done if `count` is set. |
350 | 350 | if (($options['smart_count'] ?? null) !== null && $result) { |
351 | - $texts = explode($this->delimiter, $result); |
|
352 | - $pluralRule = $locale !== $this->currentLocale ? RuleFactory::make($locale, $this->customPluralRules) : $this->pluralRule; |
|
353 | - $pluralTypeIndex = $pluralRule->decide($options['smart_count']); |
|
354 | - $result = trim($texts[$pluralTypeIndex] ?? $texts[0]); |
|
351 | + $texts=explode($this->delimiter, $result); |
|
352 | + $pluralRule=$locale !== $this->currentLocale ? RuleFactory::make($locale, $this->customPluralRules) : $this->pluralRule; |
|
353 | + $pluralTypeIndex=$pluralRule->decide($options['smart_count']); |
|
354 | + $result=trim($texts[$pluralTypeIndex] ?? $texts[0]); |
|
355 | 355 | } |
356 | 356 | |
357 | - $interpolationRegex = $tokenRegex ?? $this->tokenRegex; |
|
357 | + $interpolationRegex=$tokenRegex ?? $this->tokenRegex; |
|
358 | 358 | |
359 | 359 | return preg_replace_callback($interpolationRegex, static function($matches) use ($options) { |
360 | 360 | if (array_key_exists($matches[1], $options) && $options[$matches[1]] !== null) { |
361 | 361 | return $options[$matches[1]]; |
362 | 362 | } |
363 | 363 | |
364 | - return ($options['interpolation']['prefix'] ?? '%{') . $matches[1] . ($options['interpolation']['suffix'] ?? '}'); |
|
364 | + return ($options['interpolation']['prefix'] ?? '%{').$matches[1].($options['interpolation']['suffix'] ?? '}'); |
|
365 | 365 | }, $result); |
366 | 366 | } |
367 | 367 | |
@@ -372,15 +372,15 @@ discard block |
||
372 | 372 | * |
373 | 373 | * @return string |
374 | 374 | */ |
375 | - private function constructTokenRegex(array $options = []): string |
|
375 | + private function constructTokenRegex(array $options=[]): string |
|
376 | 376 | { |
377 | - $prefix = $options['prefix'] ?? '%{'; |
|
378 | - $suffix = $options['suffix'] ?? '}'; |
|
377 | + $prefix=$options['prefix'] ?? '%{'; |
|
378 | + $suffix=$options['suffix'] ?? '}'; |
|
379 | 379 | |
380 | 380 | if ($prefix === $this->delimiter || $suffix === $this->delimiter) { |
381 | - throw new RuntimeException('"' . $this->delimiter . '" token is reserved for pluralization'); |
|
381 | + throw new RuntimeException('"'.$this->delimiter.'" token is reserved for pluralization'); |
|
382 | 382 | } |
383 | 383 | |
384 | - return '~' . preg_quote($prefix) . '(.*?)' . preg_quote($suffix) . '~'; |
|
384 | + return '~'.preg_quote($prefix).'(.*?)'.preg_quote($suffix).'~'; |
|
385 | 385 | } |
386 | 386 | } |
387 | 387 | \ No newline at end of file |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | /** |
31 | 31 | * @var array |
32 | 32 | */ |
33 | - private static $localesRulesMapping = [ |
|
33 | + private static $localesRulesMapping=[ |
|
34 | 34 | 'ar' => Arabic::class, |
35 | 35 | 'bs-Latn-BA' => BosnianSerbian::class, |
36 | 36 | 'bs-Cyrl-BA' => BosnianSerbian::class, |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | * |
71 | 71 | * @return RuleInterface |
72 | 72 | */ |
73 | - public static function make(string $locale, array $customPluralRules = []): RuleInterface |
|
73 | + public static function make(string $locale, array $customPluralRules=[]): RuleInterface |
|
74 | 74 | { |
75 | 75 | if (isset($customPluralRules[$locale])) { |
76 | 76 | if (!is_object($customPluralRules[$locale]) || !$customPluralRules[$locale] instanceof RuleInterface) { |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | return $customPluralRules[$locale]; |
82 | 82 | } |
83 | 83 | |
84 | - $rule = self::$localesRulesMapping[$locale] ?? German::class; |
|
84 | + $rule=self::$localesRulesMapping[$locale] ?? German::class; |
|
85 | 85 | |
86 | 86 | return new $rule(); |
87 | 87 | } |