Passed
Branch master (06419d)
by Mihai
02:47
created
src/Polyglot.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@
 block discarded – undo
68 68
         $allowMissing = ($options['allowMissing'] ?? false) === true
69 69
             ? function (...$params) {
70 70
                 return $this->transformPhrase(...$params);
71
-              }
71
+                }
72 72
             : null;
73 73
         $this->onMissingKey = is_callable($options['onMissingKey'] ?? false) ? $options['onMissingKey'] : $allowMissing;
74 74
     }
Please login to merge, or discard this patch.
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
     /**
20 20
      * @var array
21 21
      */
22
-    private $phrases = [];
22
+    private $phrases=[];
23 23
 
24 24
     /**
25 25
      * @var string
@@ -56,21 +56,21 @@  discard block
 block discarded – undo
56 56
      *
57 57
      * @param array $options
58 58
      */
59
-    public function __construct(array $options = [])
59
+    public function __construct(array $options=[])
60 60
     {
61 61
         $this->extend($options['phrases'] ?? []);
62 62
         $this->locale($options['locale'] ?? 'en');
63 63
 
64
-        $this->delimiter = $options['delimiter'] ?? '||||';
65
-        $this->tokenRegex = $this->constructTokenRegex($options['interpolation'] ?? []);
66
-        $this->warn = $options['warn'] ?? static function(string $message) {};
64
+        $this->delimiter=$options['delimiter'] ?? '||||';
65
+        $this->tokenRegex=$this->constructTokenRegex($options['interpolation'] ?? []);
66
+        $this->warn=$options['warn'] ?? static function(string $message) {};
67 67
 
68
-        $allowMissing = ($options['allowMissing'] ?? false) === true
69
-            ? function (...$params) {
68
+        $allowMissing=($options['allowMissing'] ?? false) === true
69
+            ? function(...$params) {
70 70
                 return $this->transformPhrase(...$params);
71 71
               }
72 72
             : null;
73
-        $this->onMissingKey = is_callable($options['onMissingKey'] ?? false) ? $options['onMissingKey'] : $allowMissing;
73
+        $this->onMissingKey=is_callable($options['onMissingKey'] ?? false) ? $options['onMissingKey'] : $allowMissing;
74 74
     }
75 75
 
76 76
     /**
@@ -127,15 +127,15 @@  discard block
 block discarded – undo
127 127
      * @param array       $morePhrases
128 128
      * @param string|null $prefix
129 129
      */
130
-    public function extend(array $morePhrases = [], ?string $prefix = null): void
130
+    public function extend(array $morePhrases=[], ?string $prefix=null): void
131 131
     {
132 132
         foreach ($morePhrases as $key => $phrase) {
133
-            $prefixedKey = $prefix !== null ? $prefix . '.' . $key : $key;
133
+            $prefixedKey=$prefix !== null ? $prefix.'.'.$key : $key;
134 134
 
135 135
             if (is_array($phrase)) {
136 136
                 $this->extend($phrase, $prefixedKey);
137 137
             } else {
138
-                $this->phrases[$prefixedKey] = $phrase;
138
+                $this->phrases[$prefixedKey]=$phrase;
139 139
             }
140 140
         }
141 141
     }
@@ -157,13 +157,13 @@  discard block
 block discarded – undo
157 157
      * @param string|array $morePhrases
158 158
      * @param string|null  $prefix
159 159
      */
160
-    public function unset($morePhrases, ?string $prefix = null): void
160
+    public function unset($morePhrases, ?string $prefix=null) : void
161 161
     {
162 162
         if (is_string($morePhrases)) {
163 163
             unset($this->phrases[$morePhrases]);
164 164
         } else {
165 165
             foreach ($morePhrases as $key => $phrase) {
166
-                $prefixedKey = $prefix !== null ? $prefix . '.' . $key : $key;
166
+                $prefixedKey=$prefix !== null ? $prefix.'.'.$key : $key;
167 167
 
168 168
                 if (is_array($phrase)) {
169 169
                     $this->unset($phrase, $prefixedKey);
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
      */
185 185
     public function clear(): void
186 186
     {
187
-        $this->phrases = [];
187
+        $this->phrases=[];
188 188
     }
189 189
 
190 190
     /**
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
      * @param array       $newPhrases
198 198
      * @param string|null $prefix
199 199
      */
200
-    public function replace(array $newPhrases, ?string $prefix = null): void
200
+    public function replace(array $newPhrases, ?string $prefix=null): void
201 201
     {
202 202
         $this->clear();
203 203
         $this->extend($newPhrases, $prefix);
@@ -212,11 +212,11 @@  discard block
 block discarded – undo
212 212
      *
213 213
      * @return string
214 214
      */
215
-    public function locale(?string $locale = null): string
215
+    public function locale(?string $locale=null): string
216 216
     {
217 217
         if ($locale !== null) {
218
-            $this->currentLocale = $locale;
219
-            $this->pluralRule = RuleFactory::make($locale);
218
+            $this->currentLocale=$locale;
219
+            $this->pluralRule=RuleFactory::make($locale);
220 220
         }
221 221
 
222 222
         return $this->currentLocale;
@@ -270,27 +270,27 @@  discard block
 block discarded – undo
270 270
      *
271 271
      * @return string
272 272
      */
273
-    public function t(string $key, $options = []): string
273
+    public function t(string $key, $options=[]): string
274 274
     {
275
-        $phrase = '';
276
-        $result = '';
277
-        $options = is_int($options) ? ['smart_count' => $options] : $options;
275
+        $phrase='';
276
+        $result='';
277
+        $options=is_int($options) ? ['smart_count' => $options] : $options;
278 278
 
279 279
         if ($this->has($key) && is_string($this->phrases[$key])) {
280
-            $phrase = $this->phrases[$key];
281
-        } elseif(isset($options['_'])) {
282
-            $phrase = $options['_'];
280
+            $phrase=$this->phrases[$key];
281
+        } elseif (isset($options['_'])) {
282
+            $phrase=$options['_'];
283 283
         } elseif ($this->onMissingKey !== null) {
284
-            $result = call_user_func($this->onMissingKey, $key, $options, $this->currentLocale, $this->tokenRegex, $this);
284
+            $result=call_user_func($this->onMissingKey, $key, $options, $this->currentLocale, $this->tokenRegex, $this);
285 285
         } else {
286 286
             // warn missing translations
287
-            call_user_func($this->warn, 'Missing translation for key: "' . $key . '"');
287
+            call_user_func($this->warn, 'Missing translation for key: "'.$key.'"');
288 288
 
289
-            $result = $key;
289
+            $result=$key;
290 290
         }
291 291
 
292 292
         if (!empty($phrase)) {
293
-            $result = $this->transformPhrase($phrase, $options, $this->currentLocale, $this->tokenRegex);
293
+            $result=$this->transformPhrase($phrase, $options, $this->currentLocale, $this->tokenRegex);
294 294
         }
295 295
 
296 296
         return $result;
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
      *
327 327
      * @return string
328 328
      */
329
-    public function transformPhrase(string $phrase, $substitutions = null, string $locale = 'en', ?string $tokenRegex = null): string
329
+    public function transformPhrase(string $phrase, $substitutions=null, string $locale='en', ?string $tokenRegex=null): string
330 330
     {
331 331
         if (!is_string($phrase)) {
332 332
             throw new RuntimeException('Polyglot.transformPhrase expects argument #1 to be string');
@@ -336,29 +336,29 @@  discard block
 block discarded – undo
336 336
             return $phrase;
337 337
         }
338 338
 
339
-        $result = $phrase;
339
+        $result=$phrase;
340 340
 
341 341
         // allow number as a pluralization shortcut
342
-        $options = is_int($substitutions) ? ['smart_count' => $substitutions] : $substitutions;
342
+        $options=is_int($substitutions) ? ['smart_count' => $substitutions] : $substitutions;
343 343
 
344 344
         // Select plural form: based on a phrase text that contains `n`
345 345
         // plural forms separated by `delimiter`, a `locale`, and a `substitutions.smart_count`,
346 346
         // choose the correct plural form. This is only done if `count` is set.
347 347
         if (($options['smart_count'] ?? null) !== null && $result) {
348
-            $texts = explode($this->delimiter, $result);
349
-            $pluralRule = $locale !== $this->currentLocale ? RuleFactory::make($locale) : $this->pluralRule;
350
-            $pluralTypeIndex = $pluralRule->decide($options['smart_count']);
351
-            $result = trim($texts[$pluralTypeIndex] ?? $texts[0]);
348
+            $texts=explode($this->delimiter, $result);
349
+            $pluralRule=$locale !== $this->currentLocale ? RuleFactory::make($locale) : $this->pluralRule;
350
+            $pluralTypeIndex=$pluralRule->decide($options['smart_count']);
351
+            $result=trim($texts[$pluralTypeIndex] ?? $texts[0]);
352 352
         }
353 353
 
354
-        $interpolationRegex = $tokenRegex ?? $this->tokenRegex;
354
+        $interpolationRegex=$tokenRegex ?? $this->tokenRegex;
355 355
 
356 356
         return preg_replace_callback($interpolationRegex, static function($matches) use ($options) {
357 357
             if (array_key_exists($matches[1], $options) && $options[$matches[1]] !== null) {
358 358
                 return $options[$matches[1]];
359 359
             }
360 360
 
361
-            return ($options['interpolation']['prefix'] ?? '%{') . $matches[1] . ($options['interpolation']['suffix'] ?? '}');
361
+            return ($options['interpolation']['prefix'] ?? '%{').$matches[1].($options['interpolation']['suffix'] ?? '}');
362 362
         }, $result);
363 363
     }
364 364
 
@@ -369,15 +369,15 @@  discard block
 block discarded – undo
369 369
      *
370 370
      * @return string
371 371
      */
372
-    private function constructTokenRegex(array $options = []): string
372
+    private function constructTokenRegex(array $options=[]): string
373 373
     {
374
-        $prefix = $options['prefix'] ?? '%{';
375
-        $suffix = $options['suffix'] ?? '}';
374
+        $prefix=$options['prefix'] ?? '%{';
375
+        $suffix=$options['suffix'] ?? '}';
376 376
 
377 377
         if ($prefix === $this->delimiter || $suffix === $this->delimiter) {
378
-            throw new RuntimeException('"' . $this->delimiter . '" token is reserved for pluralization');
378
+            throw new RuntimeException('"'.$this->delimiter.'" token is reserved for pluralization');
379 379
         }
380 380
 
381
-        return '~' . preg_quote($prefix) . '(.*?)' . preg_quote($suffix) . '~';
381
+        return '~'.preg_quote($prefix).'(.*?)'.preg_quote($suffix).'~';
382 382
     }
383 383
 }
384 384
\ No newline at end of file
Please login to merge, or discard this patch.
src/Pluralization/Rules/Slovenian.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@
 block discarded – undo
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;
Please login to merge, or discard this patch.
src/Pluralization/Rules/Polish.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@
 block discarded – undo
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
     }
Please login to merge, or discard this patch.
src/Pluralization/Rules/Russian.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -15,8 +15,8 @@
 block discarded – undo
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;
Please login to merge, or discard this patch.
src/Pluralization/Rules/Arabic.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@
 block discarded – undo
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
         }
Please login to merge, or discard this patch.
src/Pluralization/RuleFactory.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@
 block discarded – undo
35 35
      */
36 36
     public static function make(string $locale): RuleInterface
37 37
     {
38
-        switch($locale) {
38
+        switch ($locale) {
39 39
             case 'ar':
40 40
                 return new Arabic();
41 41
 
Please login to merge, or discard this patch.