@@ -20,13 +20,13 @@ |
||
20 | 20 | */ |
21 | 21 | class Mailcode_Collection_Error_Message extends Mailcode_Collection_Error |
22 | 22 | { |
23 | - public function __construct(string $matchedText, int $code, string $message, ?object $subject=null) |
|
23 | + public function __construct(string $matchedText, int $code, string $message, ?object $subject = null) |
|
24 | 24 | { |
25 | 25 | $this->matchedText = $matchedText; |
26 | 26 | $this->code = $code; |
27 | 27 | $this->message = $message; |
28 | 28 | |
29 | - if($subject instanceof Mailcode_Commands_Command) |
|
29 | + if ($subject instanceof Mailcode_Commands_Command) |
|
30 | 30 | { |
31 | 31 | $this->command = $subject; |
32 | 32 | } |
@@ -20,19 +20,19 @@ |
||
20 | 20 | */ |
21 | 21 | abstract class Mailcode_Collection_Error |
22 | 22 | { |
23 | - /** |
|
24 | - * @var integer |
|
25 | - */ |
|
23 | + /** |
|
24 | + * @var integer |
|
25 | + */ |
|
26 | 26 | protected int $code = 0; |
27 | 27 | |
28 | - /** |
|
29 | - * @var string |
|
30 | - */ |
|
28 | + /** |
|
29 | + * @var string |
|
30 | + */ |
|
31 | 31 | protected string $matchedText = ''; |
32 | 32 | |
33 | - /** |
|
34 | - * @var string |
|
35 | - */ |
|
33 | + /** |
|
34 | + * @var string |
|
35 | + */ |
|
36 | 36 | protected string $message = ''; |
37 | 37 | |
38 | 38 | protected ?Mailcode_Commands_Command $command = null; |
@@ -40,7 +40,7 @@ |
||
40 | 40 | $value = $this->instantiator->quoteString($value); |
41 | 41 | } |
42 | 42 | |
43 | - $params = $variableName . ' = ' . $value; |
|
43 | + $params = $variableName.' = '.$value; |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | $cmd = $this->commands->createCommand( |
@@ -30,7 +30,7 @@ |
||
30 | 30 | return $this->variables->createVariableByName($fullName); |
31 | 31 | } |
32 | 32 | |
33 | - public function pathName(string $path, ?string $name=null) : Mailcode_Variables_Variable |
|
33 | + public function pathName(string $path, ?string $name = null) : Mailcode_Variables_Variable |
|
34 | 34 | { |
35 | 35 | return $this->variables->createVariable($path, $name); |
36 | 36 | } |
@@ -27,9 +27,9 @@ discard block |
||
27 | 27 | private ?Mailcode_Factory_CommandSets_Set_ElseIf $elseIf = null; |
28 | 28 | private ?Mailcode_Factory_CommandSets_Set_Variables $variables = null; |
29 | 29 | |
30 | - public function if() : Mailcode_Factory_CommandSets_Set_If |
|
30 | + public function if () : Mailcode_Factory_CommandSets_Set_If |
|
31 | 31 | { |
32 | - if(!isset($this->if)) |
|
32 | + if (!isset($this->if)) |
|
33 | 33 | { |
34 | 34 | $this->if = new Mailcode_Factory_CommandSets_Set_If(); |
35 | 35 | } |
@@ -37,9 +37,9 @@ discard block |
||
37 | 37 | return $this->if; |
38 | 38 | } |
39 | 39 | |
40 | - public function elseIf() : Mailcode_Factory_CommandSets_Set_ElseIf |
|
40 | + public function elseIf () : Mailcode_Factory_CommandSets_Set_ElseIf |
|
41 | 41 | { |
42 | - if(!isset($this->elseIf)) |
|
42 | + if (!isset($this->elseIf)) |
|
43 | 43 | { |
44 | 44 | $this->elseIf = new Mailcode_Factory_CommandSets_Set_ElseIf(); |
45 | 45 | } |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | |
50 | 50 | public function show() : Mailcode_Factory_CommandSets_Set_Show |
51 | 51 | { |
52 | - if(!isset($this->show)) |
|
52 | + if (!isset($this->show)) |
|
53 | 53 | { |
54 | 54 | $this->show = new Mailcode_Factory_CommandSets_Set_Show(); |
55 | 55 | } |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | |
60 | 60 | public function misc() : Mailcode_Factory_CommandSets_Set_Misc |
61 | 61 | { |
62 | - if(!isset($this->misc)) |
|
62 | + if (!isset($this->misc)) |
|
63 | 63 | { |
64 | 64 | $this->misc = new Mailcode_Factory_CommandSets_Set_Misc(); |
65 | 65 | } |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | |
70 | 70 | public function set() : Mailcode_Factory_CommandSets_Set_Set |
71 | 71 | { |
72 | - if(!isset($this->set)) |
|
72 | + if (!isset($this->set)) |
|
73 | 73 | { |
74 | 74 | $this->set = new Mailcode_Factory_CommandSets_Set_Set(); |
75 | 75 | } |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | |
80 | 80 | public function var() : Mailcode_Factory_CommandSets_Set_Variables |
81 | 81 | { |
82 | - if(!isset($this->variables)) |
|
82 | + if (!isset($this->variables)) |
|
83 | 83 | { |
84 | 84 | $this->variables = new Mailcode_Factory_CommandSets_Set_Variables(); |
85 | 85 | } |
@@ -51,14 +51,14 @@ discard block |
||
51 | 51 | Mailcode_Parser_Statement_Tokenizer_Process_SetNames::class, |
52 | 52 | ); |
53 | 53 | |
54 | - /** |
|
55 | - * @var Mailcode_Parser_Statement |
|
56 | - */ |
|
54 | + /** |
|
55 | + * @var Mailcode_Parser_Statement |
|
56 | + */ |
|
57 | 57 | protected Mailcode_Parser_Statement $statement; |
58 | 58 | |
59 | - /** |
|
60 | - * @var string |
|
61 | - */ |
|
59 | + /** |
|
60 | + * @var string |
|
61 | + */ |
|
62 | 62 | protected string $tokenized = ''; |
63 | 63 | |
64 | 64 | /** |
@@ -66,9 +66,9 @@ discard block |
||
66 | 66 | */ |
67 | 67 | protected array $tokensOrdered = array(); |
68 | 68 | |
69 | - /** |
|
70 | - * @var string[] |
|
71 | - */ |
|
69 | + /** |
|
70 | + * @var string[] |
|
71 | + */ |
|
72 | 72 | protected static array $ids = array(); |
73 | 73 | |
74 | 74 | /** |
@@ -91,12 +91,12 @@ discard block |
||
91 | 91 | return $this->statement->getSourceCommand(); |
92 | 92 | } |
93 | 93 | |
94 | - /** |
|
95 | - * Retrieves all tokens detected in the statement string, in |
|
96 | - * the order they were found. |
|
97 | - * |
|
98 | - * @return Mailcode_Parser_Statement_Tokenizer_Token[] |
|
99 | - */ |
|
94 | + /** |
|
95 | + * Retrieves all tokens detected in the statement string, in |
|
96 | + * the order they were found. |
|
97 | + * |
|
98 | + * @return Mailcode_Parser_Statement_Tokenizer_Token[] |
|
99 | + */ |
|
100 | 100 | public function getTokens() : array |
101 | 101 | { |
102 | 102 | return $this->tokensOrdered; |
@@ -107,11 +107,11 @@ discard block |
||
107 | 107 | return !empty($this->tokensOrdered); |
108 | 108 | } |
109 | 109 | |
110 | - /** |
|
111 | - * Whether there were any unknown tokens in the statement. |
|
112 | - * |
|
113 | - * @return bool |
|
114 | - */ |
|
110 | + /** |
|
111 | + * Whether there were any unknown tokens in the statement. |
|
112 | + * |
|
113 | + * @return bool |
|
114 | + */ |
|
115 | 115 | public function hasUnknown() : bool |
116 | 116 | { |
117 | 117 | $unknown = $this->getUnknown(); |
@@ -119,11 +119,11 @@ discard block |
||
119 | 119 | return !empty($unknown); |
120 | 120 | } |
121 | 121 | |
122 | - /** |
|
123 | - * Retrieves all unknown content tokens, if any. |
|
124 | - * |
|
125 | - * @return Mailcode_Parser_Statement_Tokenizer_Token_Unknown[] |
|
126 | - */ |
|
122 | + /** |
|
123 | + * Retrieves all unknown content tokens, if any. |
|
124 | + * |
|
125 | + * @return Mailcode_Parser_Statement_Tokenizer_Token_Unknown[] |
|
126 | + */ |
|
127 | 127 | public function getUnknown() : array |
128 | 128 | { |
129 | 129 | $result = array(); |
@@ -410,13 +410,13 @@ discard block |
||
410 | 410 | return $this; |
411 | 411 | } |
412 | 412 | |
413 | - /** |
|
414 | - * Generates a unique alphabet-based ID without numbers |
|
415 | - * to use as token name, to avoid conflicts with the |
|
416 | - * numbers detection. |
|
417 | - * |
|
418 | - * @return string |
|
419 | - */ |
|
413 | + /** |
|
414 | + * Generates a unique alphabet-based ID without numbers |
|
415 | + * to use as token name, to avoid conflicts with the |
|
416 | + * numbers detection. |
|
417 | + * |
|
418 | + * @return string |
|
419 | + */ |
|
420 | 420 | protected function generateID() : string |
421 | 421 | { |
422 | 422 | static $alphas; |
@@ -128,9 +128,9 @@ discard block |
||
128 | 128 | { |
129 | 129 | $result = array(); |
130 | 130 | |
131 | - foreach($this->tokensOrdered as $token) |
|
131 | + foreach ($this->tokensOrdered as $token) |
|
132 | 132 | { |
133 | - if($token instanceof Mailcode_Parser_Statement_Tokenizer_Token_Unknown) |
|
133 | + if ($token instanceof Mailcode_Parser_Statement_Tokenizer_Token_Unknown) |
|
134 | 134 | { |
135 | 135 | $result[] = $token; |
136 | 136 | } |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | { |
144 | 144 | $unknown = $this->getUnknown(); |
145 | 145 | |
146 | - if(!empty($unknown)) |
|
146 | + if (!empty($unknown)) |
|
147 | 147 | { |
148 | 148 | return array_shift($unknown); |
149 | 149 | } |
@@ -155,16 +155,16 @@ discard block |
||
155 | 155 | { |
156 | 156 | $parts = array(); |
157 | 157 | |
158 | - foreach($this->tokensOrdered as $token) |
|
158 | + foreach ($this->tokensOrdered as $token) |
|
159 | 159 | { |
160 | 160 | $string = $token->getNormalized(); |
161 | 161 | |
162 | - if($string === '') { |
|
162 | + if ($string === '') { |
|
163 | 163 | continue; |
164 | 164 | } |
165 | 165 | |
166 | 166 | // Only add spaces between tokens if they require spacing |
167 | - if($token->hasSpacing()) { |
|
167 | + if ($token->hasSpacing()) { |
|
168 | 168 | $string .= ' '; |
169 | 169 | } |
170 | 170 | |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | $statement = trim($statement); |
191 | 191 | $tokens = array(); |
192 | 192 | |
193 | - foreach($this->tokenClasses as $tokenClass) |
|
193 | + foreach ($this->tokenClasses as $tokenClass) |
|
194 | 194 | { |
195 | 195 | $processor = $this->createProcessor($tokenClass, $statement, $tokens); |
196 | 196 | $processor->process(); |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | { |
215 | 215 | $instance = new $className($this, $statement, $tokens); |
216 | 216 | |
217 | - if($instance instanceof Mailcode_Parser_Statement_Tokenizer_Process) |
|
217 | + if ($instance instanceof Mailcode_Parser_Statement_Tokenizer_Process) |
|
218 | 218 | { |
219 | 219 | return $instance; |
220 | 220 | } |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | * @param mixed $subject |
236 | 236 | * @return Mailcode_Parser_Statement_Tokenizer_Token |
237 | 237 | */ |
238 | - public function createToken(string $type, string $matchedText, $subject=null) : Mailcode_Parser_Statement_Tokenizer_Token |
|
238 | + public function createToken(string $type, string $matchedText, $subject = null) : Mailcode_Parser_Statement_Tokenizer_Token |
|
239 | 239 | { |
240 | 240 | $tokenID = $this->generateID(); |
241 | 241 | |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | |
244 | 244 | $token = new $class($tokenID, $matchedText, $subject, $this->getSourceCommand()); |
245 | 245 | |
246 | - if($token instanceof Mailcode_Parser_Statement_Tokenizer_Token) |
|
246 | + if ($token instanceof Mailcode_Parser_Statement_Tokenizer_Token) |
|
247 | 247 | { |
248 | 248 | return $token; |
249 | 249 | } |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | |
273 | 273 | $token = $this->createToken('Keyword', $name); |
274 | 274 | |
275 | - if($token instanceof Mailcode_Parser_Statement_Tokenizer_Token_Keyword) |
|
275 | + if ($token instanceof Mailcode_Parser_Statement_Tokenizer_Token_Keyword) |
|
276 | 276 | { |
277 | 277 | return $token; |
278 | 278 | } |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | { |
298 | 298 | $token = $this->createToken('StringLiteral', SpecialChars::encodeAll($text)); |
299 | 299 | |
300 | - if($token instanceof Mailcode_Parser_Statement_Tokenizer_Token_StringLiteral) |
|
300 | + if ($token instanceof Mailcode_Parser_Statement_Tokenizer_Token_StringLiteral) |
|
301 | 301 | { |
302 | 302 | return $token; |
303 | 303 | } |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | { |
314 | 314 | $token = $this->createToken('Number', $number); |
315 | 315 | |
316 | - if($token instanceof Mailcode_Parser_Statement_Tokenizer_Token_Number) |
|
316 | + if ($token instanceof Mailcode_Parser_Statement_Tokenizer_Token_Number) |
|
317 | 317 | { |
318 | 318 | return $token; |
319 | 319 | } |
@@ -355,7 +355,7 @@ discard block |
||
355 | 355 | public function removeToken(Mailcode_Parser_Statement_Tokenizer_Token $token) : Mailcode_Parser_Statement_Tokenizer |
356 | 356 | { |
357 | 357 | $name = $this->findNameToken($token); |
358 | - if($name !== null) { |
|
358 | + if ($name !== null) { |
|
359 | 359 | $this->removeToken($name); |
360 | 360 | } |
361 | 361 | |
@@ -365,7 +365,7 @@ discard block |
||
365 | 365 | |
366 | 366 | foreach ($this->tokensOrdered as $checkToken) |
367 | 367 | { |
368 | - if($checkToken->getID() === $tokenID) |
|
368 | + if ($checkToken->getID() === $tokenID) |
|
369 | 369 | { |
370 | 370 | $removed = true; |
371 | 371 | continue; |
@@ -376,7 +376,7 @@ discard block |
||
376 | 376 | |
377 | 377 | $this->tokensOrdered = $keep; |
378 | 378 | |
379 | - if($removed) |
|
379 | + if ($removed) |
|
380 | 380 | { |
381 | 381 | $this->eventHandler->handleTokenRemoved($token); |
382 | 382 | } |
@@ -421,7 +421,7 @@ discard block |
||
421 | 421 | { |
422 | 422 | static $alphas; |
423 | 423 | |
424 | - if(!isset($alphas)) |
|
424 | + if (!isset($alphas)) |
|
425 | 425 | { |
426 | 426 | $alphas = range('A', 'Z'); |
427 | 427 | } |
@@ -430,12 +430,12 @@ discard block |
||
430 | 430 | |
431 | 431 | $result = ''; |
432 | 432 | |
433 | - for($i=0; $i < $amount; $i++) |
|
433 | + for ($i = 0; $i < $amount; $i++) |
|
434 | 434 | { |
435 | 435 | $result .= $alphas[array_rand($alphas)]; |
436 | 436 | } |
437 | 437 | |
438 | - if(!in_array($result, self::$ids)) |
|
438 | + if (!in_array($result, self::$ids)) |
|
439 | 439 | { |
440 | 440 | self::$ids[] = $result; |
441 | 441 | return $result; |
@@ -471,12 +471,12 @@ discard block |
||
471 | 471 | { |
472 | 472 | $targetID = $targetToken->getID(); |
473 | 473 | |
474 | - foreach($this->tokensOrdered as $idx => $token) |
|
474 | + foreach ($this->tokensOrdered as $idx => $token) |
|
475 | 475 | { |
476 | - if($token->getID() === $targetID) |
|
476 | + if ($token->getID() === $targetID) |
|
477 | 477 | { |
478 | - $prev = $this->tokensOrdered[$idx-1] ?? null; |
|
479 | - if($prev instanceof Mailcode_Parser_Statement_Tokenizer_Token_ParamName) |
|
478 | + $prev = $this->tokensOrdered[$idx - 1] ?? null; |
|
479 | + if ($prev instanceof Mailcode_Parser_Statement_Tokenizer_Token_ParamName) |
|
480 | 480 | { |
481 | 481 | return $prev; |
482 | 482 | } |
@@ -500,7 +500,7 @@ discard block |
||
500 | 500 | public function injectParamName(Mailcode_Parser_Statement_Tokenizer_Token $targetToken, string $name) : Mailcode_Parser_Statement_Tokenizer_Token_ParamName |
501 | 501 | { |
502 | 502 | $existing = $this->findNameToken($targetToken); |
503 | - if($existing) { |
|
503 | + if ($existing) { |
|
504 | 504 | $this->removeToken($existing); |
505 | 505 | } |
506 | 506 | |
@@ -521,9 +521,9 @@ discard block |
||
521 | 521 | $tokens = array(); |
522 | 522 | $found = false; |
523 | 523 | |
524 | - foreach($this->tokensOrdered as $token) |
|
524 | + foreach ($this->tokensOrdered as $token) |
|
525 | 525 | { |
526 | - if($token->getID() === $targetID) |
|
526 | + if ($token->getID() === $targetID) |
|
527 | 527 | { |
528 | 528 | $tokens[] = $newToken; |
529 | 529 | $found = true; |
@@ -532,7 +532,7 @@ discard block |
||
532 | 532 | $tokens[] = $token; |
533 | 533 | } |
534 | 534 | |
535 | - if($found) { |
|
535 | + if ($found) { |
|
536 | 536 | $this->tokensOrdered = $tokens; |
537 | 537 | |
538 | 538 | return $this; |
@@ -555,7 +555,7 @@ discard block |
||
555 | 555 | echo 'Statement: ['.$this->getNormalized().']'.PHP_EOL; |
556 | 556 | echo 'Tokens:'.PHP_EOL; |
557 | 557 | |
558 | - foreach($this->tokensOrdered as $idx => $token) |
|
558 | + foreach ($this->tokensOrdered as $idx => $token) |
|
559 | 559 | { |
560 | 560 | echo '- #'.$idx.' '.$token->getID().''.PHP_EOL; |
561 | 561 | echo ' Type: '.$token->getTypeID().PHP_EOL; |
@@ -313,9 +313,9 @@ |
||
313 | 313 | { |
314 | 314 | $tokens = $this->tokenizer->getTokens(); |
315 | 315 | |
316 | - foreach($tokens as $token) |
|
316 | + foreach ($tokens as $token) |
|
317 | 317 | { |
318 | - if($token->getName() === $name) |
|
318 | + if ($token->getName() === $name) |
|
319 | 319 | { |
320 | 320 | return $token; |
321 | 321 | } |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | * @param mixed $subject |
37 | 37 | * @param Mailcode_Commands_Command|null $sourceCommand |
38 | 38 | */ |
39 | - public function __construct(string $tokenID, string $matchedText, $subject=null, ?Mailcode_Commands_Command $sourceCommand=null) |
|
39 | + public function __construct(string $tokenID, string $matchedText, $subject = null, ?Mailcode_Commands_Command $sourceCommand = null) |
|
40 | 40 | { |
41 | 41 | $this->tokenID = $tokenID; |
42 | 42 | $this->matchedText = $matchedText; |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | */ |
64 | 64 | public function getName() : string |
65 | 65 | { |
66 | - if(isset($this->nameToken)) { |
|
66 | + if (isset($this->nameToken)) { |
|
67 | 67 | return $this->nameToken->getParamName(); |
68 | 68 | } |
69 | 69 |
@@ -35,11 +35,11 @@ discard block |
||
35 | 35 | } |
36 | 36 | |
37 | 37 | /** |
38 | - * Retrieves the text with the surrounding quotes, |
|
39 | - * and special characters escaped for Mailcode. |
|
40 | - * |
|
41 | - * @return string |
|
42 | - */ |
|
38 | + * Retrieves the text with the surrounding quotes, |
|
39 | + * and special characters escaped for Mailcode. |
|
40 | + * |
|
41 | + * @return string |
|
42 | + */ |
|
43 | 43 | public function getNormalized() : string |
44 | 44 | { |
45 | 45 | return '"'.SpecialChars::escape($this->text).'"'; |
@@ -50,21 +50,21 @@ discard block |
||
50 | 50 | return true; |
51 | 51 | } |
52 | 52 | |
53 | - /** |
|
54 | - * Retrieves the text with the surrounding quotes. |
|
55 | - * @return string |
|
56 | - */ |
|
53 | + /** |
|
54 | + * Retrieves the text with the surrounding quotes. |
|
55 | + * @return string |
|
56 | + */ |
|
57 | 57 | public function getValue() : string |
58 | 58 | { |
59 | 59 | return $this->getNormalized(); |
60 | 60 | } |
61 | 61 | |
62 | - /** |
|
63 | - * Retrieves the text without the surrounding quotes, |
|
64 | - * and special Mailcode characters not escaped. |
|
65 | - * |
|
66 | - * @return string |
|
67 | - */ |
|
62 | + /** |
|
63 | + * Retrieves the text without the surrounding quotes, |
|
64 | + * and special Mailcode characters not escaped. |
|
65 | + * |
|
66 | + * @return string |
|
67 | + */ |
|
68 | 68 | public function getText() : string |
69 | 69 | { |
70 | 70 | return SpecialChars::decode($this->text); |