Passed
Push — master ( 8482a1...034aeb )
by Sebastian
15:02
created
src/Mailcode/Exception.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@
 block discarded – undo
21 21
 
22 22
     public function __construct(string $message, ?string $details = null, $code = null, $previous = null)
23 23
     {
24
-        if(defined('TESTS_ROOT') && !empty($details)) {
24
+        if (defined('TESTS_ROOT') && !empty($details)) {
25 25
             $message .= PHP_EOL.
26 26
                 'Details:'.PHP_EOL.
27 27
                 $details;
Please login to merge, or discard this patch.
src/Mailcode/Traits/Commands/Validation/NamespaceTrait.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 
39 39
         if (!$token instanceof Mailcode_Parser_Statement_Tokenizer_Token_StringLiteral) {
40 40
             $this->validationResult->makeError(
41
-                t('Invalid namespace token:') . ' ' . t('Expected a string.'),
41
+                t('Invalid namespace token:').' '.t('Expected a string.'),
42 42
                 NamespaceInterface::VALIDATION_NAMESPACE_WRONG_TYPE
43 43
             );
44 44
             return;
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
     {
62 62
         $token = $this->getNamespaceToken();
63 63
 
64
-        if($token !== null) {
64
+        if ($token !== null) {
65 65
             return $token;
66 66
         }
67 67
 
Please login to merge, or discard this patch.
src/Mailcode/Commands/LogicKeywords.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -63,9 +63,9 @@  discard block
 block discarded – undo
63 63
     
64 64
     private function parse() : void
65 65
     {
66
-        foreach($this->names as $name)
66
+        foreach ($this->names as $name)
67 67
         {
68
-            if(stripos($this->paramsString, $name) === false) {
68
+            if (stripos($this->paramsString, $name) === false) {
69 69
                 continue;
70 70
             }
71 71
 
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
         $names = $this->getDetectedNames();
82 82
         $amount = count($names);
83 83
         
84
-        if($amount > 1)
84
+        if ($amount > 1)
85 85
         {
86 86
             $this->makeError(
87 87
                 t(
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
     
102 102
     private function splitParams() : void
103 103
     {
104
-        if(empty($this->keywords))
104
+        if (empty($this->keywords))
105 105
         {
106 106
             $this->mainParams = $this->paramsString;
107 107
             
@@ -110,13 +110,13 @@  discard block
 block discarded – undo
110 110
         
111 111
         $params = $this->detectParameters();
112 112
         
113
-        foreach($this->keywords as $keyword)
113
+        foreach ($this->keywords as $keyword)
114 114
         {
115 115
             $kParams = (string)array_shift($params);
116 116
             
117 117
             $keyword->setParamsString($kParams);
118 118
             
119
-            if(!$keyword->isValid())
119
+            if (!$keyword->isValid())
120 120
             {
121 121
                 $this->makeError(
122 122
                     t('Error #%1$s:', $keyword->getCode()).' '.$keyword->getErrorMessage(),
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
         $params = $this->paramsString;
137 137
         $stack = array();
138 138
         
139
-        foreach($this->keywords as $keyword)
139
+        foreach ($this->keywords as $keyword)
140 140
         {
141 141
             $params = $this->detectParamsKeyword($params, $keyword, $stack);
142 142
         }
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
         $search = $keyword->getMatchedString();
161 161
         $pos = strpos($params, $search, 0);
162 162
         
163
-        if($pos === false)
163
+        if ($pos === false)
164 164
         {
165 165
             throw new Mailcode_Exception(
166 166
                 'Keyword matched string not found',
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
         
174 174
         $store = substr($params, 0, $pos);
175 175
 
176
-        if($store === false)
176
+        if ($store === false)
177 177
         {
178 178
             throw new Mailcode_Exception(
179 179
                 'Keyword substring not found',
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
             );
183 183
         }
184 184
 
185
-        $params = trim(substr($params, $pos+$length));
185
+        $params = trim(substr($params, $pos + $length));
186 186
         
187 187
         $stack[] = $store;
188 188
         
@@ -209,11 +209,11 @@  discard block
 block discarded – undo
209 209
     {
210 210
         $names = array();
211 211
         
212
-        foreach($this->keywords as $keyword)
212
+        foreach ($this->keywords as $keyword)
213 213
         {
214 214
             $name = $keyword->getName();
215 215
             
216
-            if(!in_array($name, $names, true)) {
216
+            if (!in_array($name, $names, true)) {
217 217
                 $names[] = $name;
218 218
             }
219 219
         }
@@ -245,14 +245,14 @@  discard block
 block discarded – undo
245 245
         $matches = array();
246 246
         preg_match_all($regex, $this->paramsString, $matches, PREG_PATTERN_ORDER);
247 247
         
248
-        if(empty($matches[0][0])) {
248
+        if (empty($matches[0][0])) {
249 249
             return array();
250 250
         }
251 251
         
252 252
         $amount = count($matches[0]);
253 253
         $result = array();
254 254
         
255
-        for($i=0; $i < $amount; $i++)
255
+        for ($i = 0; $i < $amount; $i++)
256 256
         {
257 257
             $result[] = $this->createKeyword(
258 258
                 $name, 
@@ -269,22 +269,22 @@  discard block
 block discarded – undo
269 269
         return !empty($this->keywords);
270 270
     }
271 271
     
272
-    public function appendAND(string $paramsString, string $type='') : Mailcode_Commands_LogicKeywords_Keyword
272
+    public function appendAND(string $paramsString, string $type = '') : Mailcode_Commands_LogicKeywords_Keyword
273 273
     {
274 274
         return $this->appendKeyword('and', $paramsString, $type);
275 275
     }
276 276
     
277
-    public function appendOR(string $paramsString, string $type='') : Mailcode_Commands_LogicKeywords_Keyword
277
+    public function appendOR(string $paramsString, string $type = '') : Mailcode_Commands_LogicKeywords_Keyword
278 278
     {
279 279
         return $this->appendKeyword('or', $paramsString, $type);
280 280
     }
281 281
     
282
-    public function appendKeyword(string $name, string $paramsString, string $type='') : Mailcode_Commands_LogicKeywords_Keyword
282
+    public function appendKeyword(string $name, string $paramsString, string $type = '') : Mailcode_Commands_LogicKeywords_Keyword
283 283
     {
284 284
         $keyword = $this->createKeyword($name, $type);
285 285
         $keyword->setParamsString($paramsString);
286 286
         
287
-        if(!$keyword->isValid())
287
+        if (!$keyword->isValid())
288 288
         {
289 289
             throw new Mailcode_Exception(
290 290
                 'Cannot append invalid logic keyword',
@@ -305,13 +305,13 @@  discard block
 block discarded – undo
305 305
         return $keyword;
306 306
     }
307 307
     
308
-    private function createKeyword(string $name, string $type='', string $matchedString='') : Mailcode_Commands_LogicKeywords_Keyword
308
+    private function createKeyword(string $name, string $type = '', string $matchedString = '') : Mailcode_Commands_LogicKeywords_Keyword
309 309
     {
310
-        if(empty($matchedString))
310
+        if (empty($matchedString))
311 311
         {
312 312
             $matchedString = $name;
313 313
             
314
-            if(!empty($type))
314
+            if (!empty($type))
315 315
             {
316 316
                 $matchedString .= ' '.$type;
317 317
             }
Please login to merge, or discard this patch.
src/Mailcode/ClassCache.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
      * @return class-string[]
28 28
      * @throws FileHelper_Exception
29 29
      */
30
-    public static function findClassesInFolder($folder, bool $recursive=false, ?string $instanceOf=null) : array
30
+    public static function findClassesInFolder($folder, bool $recursive = false, ?string $instanceOf = null) : array
31 31
     {
32 32
         return self::createCache()
33 33
             ->findClassesInFolder(
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 
43 43
     private static function createCache() : ClassRepositoryManager
44 44
     {
45
-        if(!isset(self::$cache)) {
45
+        if (!isset(self::$cache)) {
46 46
             self::$cache = ClassRepositoryManager::create(Mailcode::getCacheFolder());
47 47
         }
48 48
 
Please login to merge, or discard this patch.
src/Mailcode/Translator.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 
34 34
     public static function create() : Mailcode_Translator
35 35
     {
36
-        if(is_null(self::$instance)) {
36
+        if (is_null(self::$instance)) {
37 37
             self::$instance = new self();
38 38
         }
39 39
 
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 
43 43
     public function __construct()
44 44
     {
45
-        foreach($this->resolveSyntaxClasses() as $class) {
45
+        foreach ($this->resolveSyntaxClasses() as $class) {
46 46
             $syntax = new $class();
47 47
             $this->syntaxes[$syntax->getTypeID()] = $syntax;
48 48
         }
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
      */
57 57
     public function createSyntax(string $name) : SyntaxInterface
58 58
     {
59
-        if(isset($this->syntaxes[$name])) {
59
+        if (isset($this->syntaxes[$name])) {
60 60
             return $this->syntaxes[$name];
61 61
         }
62 62
 
Please login to merge, or discard this patch.
src/Mailcode/Parser/Statement/Tokenizer.php 1 patch
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -125,9 +125,9 @@  discard block
 block discarded – undo
125 125
     {
126 126
         $result = array();
127 127
         
128
-        foreach($this->tokensOrdered as $token)
128
+        foreach ($this->tokensOrdered as $token)
129 129
         {
130
-            if($token instanceof Mailcode_Parser_Statement_Tokenizer_Token_Unknown)
130
+            if ($token instanceof Mailcode_Parser_Statement_Tokenizer_Token_Unknown)
131 131
             {
132 132
                 $result[] = $token;
133 133
             }
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
     {
141 141
         $unknown = $this->getUnknown();
142 142
         
143
-        if(!empty($unknown))
143
+        if (!empty($unknown))
144 144
         {
145 145
             return array_shift($unknown);
146 146
         }
@@ -152,16 +152,16 @@  discard block
 block discarded – undo
152 152
     {
153 153
         $parts = array();
154 154
 
155
-        foreach($this->tokensOrdered as $token)
155
+        foreach ($this->tokensOrdered as $token)
156 156
         {
157 157
             $string = $token->getNormalized();
158 158
             
159
-            if($string === '') {
159
+            if ($string === '') {
160 160
                 continue;
161 161
             }
162 162
 
163 163
             // Only add spaces between tokens if they require spacing
164
-            if($token->hasSpacing()) {
164
+            if ($token->hasSpacing()) {
165 165
                 $string .= ' ';
166 166
             }
167 167
 
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
         $statement = trim($statement);
188 188
         $tokens = array();
189 189
 
190
-        foreach($this->tokenClasses as $tokenClass)
190
+        foreach ($this->tokenClasses as $tokenClass)
191 191
         {
192 192
             $processor = $this->createProcessor($tokenClass, $statement, $tokens);
193 193
             $processor->process();
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
     {
212 212
         $instance = new $className($this, $statement, $tokens);
213 213
 
214
-        if($instance instanceof Mailcode_Parser_Statement_Tokenizer_Process)
214
+        if ($instance instanceof Mailcode_Parser_Statement_Tokenizer_Process)
215 215
         {
216 216
             return $instance;
217 217
         }
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
      * @param mixed $subject
233 233
      * @return Mailcode_Parser_Statement_Tokenizer_Token
234 234
      */
235
-    public function createToken(string $type, string $matchedText, $subject=null) : Mailcode_Parser_Statement_Tokenizer_Token
235
+    public function createToken(string $type, string $matchedText, $subject = null) : Mailcode_Parser_Statement_Tokenizer_Token
236 236
     {
237 237
         $tokenID = $this->generateID();
238 238
 
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
 
241 241
         $token = new $class($tokenID, $matchedText, $subject, $this->getSourceCommand());
242 242
 
243
-        if($token instanceof Mailcode_Parser_Statement_Tokenizer_Token)
243
+        if ($token instanceof Mailcode_Parser_Statement_Tokenizer_Token)
244 244
         {
245 245
             return $token;
246 246
         }
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
 
270 270
         $token = $this->createToken('Keyword', $name);
271 271
 
272
-        if($token instanceof Mailcode_Parser_Statement_Tokenizer_Token_Keyword)
272
+        if ($token instanceof Mailcode_Parser_Statement_Tokenizer_Token_Keyword)
273 273
         {
274 274
             return $token;
275 275
         }
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
     {
295 295
         $token = $this->createToken('StringLiteral', SpecialChars::encodeAll($text));
296 296
 
297
-        if($token instanceof Mailcode_Parser_Statement_Tokenizer_Token_StringLiteral)
297
+        if ($token instanceof Mailcode_Parser_Statement_Tokenizer_Token_StringLiteral)
298 298
         {
299 299
             return $token;
300 300
         }
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
     {
311 311
         $token = $this->createToken('Number', $number);
312 312
 
313
-        if($token instanceof Mailcode_Parser_Statement_Tokenizer_Token_Number)
313
+        if ($token instanceof Mailcode_Parser_Statement_Tokenizer_Token_Number)
314 314
         {
315 315
             return $token;
316 316
         }
@@ -352,7 +352,7 @@  discard block
 block discarded – undo
352 352
     public function removeToken(Mailcode_Parser_Statement_Tokenizer_Token $token) : Mailcode_Parser_Statement_Tokenizer
353 353
     {
354 354
         $name = $this->findNameToken($token);
355
-        if($name !== null) {
355
+        if ($name !== null) {
356 356
             $this->removeToken($name);
357 357
         }
358 358
 
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
 
363 363
         foreach ($this->tokensOrdered as $checkToken)
364 364
         {
365
-            if($checkToken->getID() === $tokenID)
365
+            if ($checkToken->getID() === $tokenID)
366 366
             {
367 367
                 $removed = true;
368 368
                 continue;
@@ -373,7 +373,7 @@  discard block
 block discarded – undo
373 373
 
374 374
         $this->tokensOrdered = $keep;
375 375
 
376
-        if($removed)
376
+        if ($removed)
377 377
         {
378 378
             $this->eventHandler->handleTokenRemoved($token);
379 379
         }
@@ -418,7 +418,7 @@  discard block
 block discarded – undo
418 418
     {
419 419
         static $alphas;
420 420
 
421
-        if(!isset($alphas))
421
+        if (!isset($alphas))
422 422
         {
423 423
             $alphas = range('A', 'Z');
424 424
         }
@@ -427,12 +427,12 @@  discard block
 block discarded – undo
427 427
 
428 428
         $result = '';
429 429
 
430
-        for($i=0; $i < $amount; $i++)
430
+        for ($i = 0; $i < $amount; $i++)
431 431
         {
432 432
             $result .= $alphas[array_rand($alphas)];
433 433
         }
434 434
 
435
-        if(!in_array($result, self::$ids))
435
+        if (!in_array($result, self::$ids))
436 436
         {
437 437
             self::$ids[] = $result;
438 438
             return $result;
@@ -468,12 +468,12 @@  discard block
 block discarded – undo
468 468
     {
469 469
         $targetID = $targetToken->getID();
470 470
 
471
-        foreach($this->tokensOrdered as $idx => $token)
471
+        foreach ($this->tokensOrdered as $idx => $token)
472 472
         {
473
-            if($token->getID() === $targetID)
473
+            if ($token->getID() === $targetID)
474 474
             {
475
-                $prev = $this->tokensOrdered[$idx-1] ?? null;
476
-                if($prev instanceof Mailcode_Parser_Statement_Tokenizer_Token_ParamName)
475
+                $prev = $this->tokensOrdered[$idx - 1] ?? null;
476
+                if ($prev instanceof Mailcode_Parser_Statement_Tokenizer_Token_ParamName)
477 477
                 {
478 478
                     return $prev;
479 479
                 }
@@ -497,7 +497,7 @@  discard block
 block discarded – undo
497 497
     public function injectParamName(Mailcode_Parser_Statement_Tokenizer_Token $targetToken, string $name) : Mailcode_Parser_Statement_Tokenizer_Token_ParamName
498 498
     {
499 499
         $existing = $this->findNameToken($targetToken);
500
-        if($existing) {
500
+        if ($existing) {
501 501
             $this->removeToken($existing);
502 502
         }
503 503
 
@@ -518,9 +518,9 @@  discard block
 block discarded – undo
518 518
         $tokens = array();
519 519
         $found = false;
520 520
 
521
-        foreach($this->tokensOrdered as $token)
521
+        foreach ($this->tokensOrdered as $token)
522 522
         {
523
-            if($token->getID() === $targetID)
523
+            if ($token->getID() === $targetID)
524 524
             {
525 525
                 $tokens[] = $newToken;
526 526
                 $found = true;
@@ -529,7 +529,7 @@  discard block
 block discarded – undo
529 529
             $tokens[] = $token;
530 530
         }
531 531
 
532
-        if($found) {
532
+        if ($found) {
533 533
             $this->tokensOrdered = $tokens;
534 534
 
535 535
             return $this;
Please login to merge, or discard this patch.
src/Mailcode.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 
46 46
     public static function getCacheFolder() : FolderInfo
47 47
     {
48
-        if(isset(self::$cacheFolder)) {
48
+        if (isset(self::$cacheFolder)) {
49 49
             return self::$cacheFolder;
50 50
         }
51 51
 
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
     */
94 94
     public function getParser() : Mailcode_Parser
95 95
     {
96
-        if(!isset($this->parser)) 
96
+        if (!isset($this->parser)) 
97 97
         {
98 98
             $this->parser = new Mailcode_Parser($this);
99 99
         }
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
     */
110 110
     public function getCommands() : Mailcode_Commands
111 111
     {
112
-        if(!isset($this->commands)) 
112
+        if (!isset($this->commands)) 
113 113
         {
114 114
             $this->commands = new Mailcode_Commands();
115 115
         }
@@ -134,14 +134,14 @@  discard block
 block discarded – undo
134 134
      * @param Mailcode_Commands_Command|null $sourceCommand
135 135
      * @return Mailcode_Variables_Collection_Regular
136 136
      */
137
-    public function findVariables(string $subject, ?Mailcode_Commands_Command $sourceCommand=null) : Mailcode_Variables_Collection_Regular
137
+    public function findVariables(string $subject, ?Mailcode_Commands_Command $sourceCommand = null) : Mailcode_Variables_Collection_Regular
138 138
     {
139 139
         return $this->createVariables()->parseString($subject, $sourceCommand);
140 140
     }
141 141
     
142 142
     public function createVariables() : Mailcode_Variables
143 143
     {
144
-        if(!isset($this->variables))
144
+        if (!isset($this->variables))
145 145
         {
146 146
             $this->variables = new Mailcode_Variables();
147 147
         }
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
         return self::$logger;
201 201
     }
202 202
 
203
-    public static function setDebugging(bool $enabled=true) : void
203
+    public static function setDebugging(bool $enabled = true) : void
204 204
     {
205 205
         self::$debug = $enabled;
206 206
     }
@@ -215,9 +215,9 @@  discard block
 block discarded – undo
215 215
      * @param array<string|int,mixed> $context
216 216
      * @return void
217 217
      */
218
-    public static function debug(string $message, array $context=array()) : void
218
+    public static function debug(string $message, array $context = array()) : void
219 219
     {
220
-        if(self::$debug && isset(self::$logger))
220
+        if (self::$debug && isset(self::$logger))
221 221
         {
222 222
             self::$logger->debug($message, $context);
223 223
         }
Please login to merge, or discard this patch.
tools/extractPhoneCountries.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -12,10 +12,10 @@  discard block
 block discarded – undo
12 12
 
13 13
 declare(strict_types=1);
14 14
 
15
-use AppUtils\ConvertHelper\JSONConverter;use AppUtils\CSVHelper;
16
-use AppUtils\CSVHelper_Exception;use AppUtils\FileHelper;
17
-use AppUtils\FileHelper_Exception;use libphonenumber\PhoneNumberFormat;
18
-use libphonenumber\PhoneNumberUtil;use Mailcode\Mailcode;use function AppLocalize\pts;
15
+use AppUtils\ConvertHelper\JSONConverter; use AppUtils\CSVHelper;
16
+use AppUtils\CSVHelper_Exception; use AppUtils\FileHelper;
17
+use AppUtils\FileHelper_Exception; use libphonenumber\PhoneNumberFormat;
18
+use libphonenumber\PhoneNumberUtil; use Mailcode\Mailcode; use function AppLocalize\pts;
19 19
 
20 20
 require_once 'prepend.php';
21 21
 
@@ -94,14 +94,14 @@  discard block
 block discarded – undo
94 94
 
95 95
         $meta = $phoneNumberUtil->getMetadataForRegion($code);
96 96
         if (!$meta) {
97
-            die('No metadata for ' . $code);
97
+            die('No metadata for '.$code);
98 98
         }
99 99
 
100 100
         $exampleNumber = $phoneNumberUtil->getExampleNumber($code);
101 101
 
102 102
         // PHPStan complains about this, but the method can return null - it's not documented correctly.
103
-        if($exampleNumber === null) {
104
-            die('No example number for ' . $code);
103
+        if ($exampleNumber === null) {
104
+            die('No example number for '.$code);
105 105
         }
106 106
 
107 107
         $local = $phoneNumberUtil->formatInOriginalFormat($exampleNumber, $code);
Please login to merge, or discard this patch.