Passed
Push — master ( a60ac2...b0c01a )
by
unknown
09:12
created
src/Mailcode/Parser/Safeguard/Formatting.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
     
132 132
     public function applyFormatting() : void
133 133
     {
134
-        if($this->applied)
134
+        if ($this->applied)
135 135
         {
136 136
             return;
137 137
         }
@@ -146,9 +146,9 @@  discard block
 block discarded – undo
146 146
 
147 147
     private function applyFormatTypes() : void
148 148
     {
149
-        foreach($this->formatters as $formatter)
149
+        foreach ($this->formatters as $formatter)
150 150
         {
151
-            if($formatter instanceof Mailcode_Parser_Safeguard_Formatter_FormatType)
151
+            if ($formatter instanceof Mailcode_Parser_Safeguard_Formatter_FormatType)
152 152
             {
153 153
                 $formatter->format();
154 154
             }
@@ -157,9 +157,9 @@  discard block
 block discarded – undo
157 157
     
158 158
     private function applyReplaceTypes() : void
159 159
     {
160
-        foreach($this->formatters as $formatter)
160
+        foreach ($this->formatters as $formatter)
161 161
         {
162
-            if($formatter instanceof Mailcode_Parser_Safeguard_Formatter_ReplacerType)
162
+            if ($formatter instanceof Mailcode_Parser_Safeguard_Formatter_ReplacerType)
163 163
             {
164 164
                 $formatter->replace();
165 165
             }
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
     
169 169
     private function validateFormatters() : void
170 170
     {
171
-        if(empty($this->formatters))
171
+        if (empty($this->formatters))
172 172
         {
173 173
             throw new Mailcode_Exception(
174 174
                 'No formatters selected',
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
         
180 180
         $amount = $this->countReplacers();
181 181
         
182
-        if($amount > 1) 
182
+        if ($amount > 1) 
183 183
         {
184 184
             throw new Mailcode_Exception(
185 185
                 'More than one replacer formatter selected',
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
         }
190 190
         
191 191
         // by default, at minimum the normalized formatter must be selected.
192
-        if($amount === 0)
192
+        if ($amount === 0)
193 193
         {
194 194
             $this->replaceWithNormalized();
195 195
         }
@@ -204,9 +204,9 @@  discard block
 block discarded – undo
204 204
     {
205 205
         $count = 0;
206 206
         
207
-        foreach($this->formatters as $formatter)
207
+        foreach ($this->formatters as $formatter)
208 208
         {
209
-            if($formatter instanceof Mailcode_Parser_Safeguard_Formatter_ReplacerType)
209
+            if ($formatter instanceof Mailcode_Parser_Safeguard_Formatter_ReplacerType)
210 210
             {
211 211
                 $count++;
212 212
             }
Please login to merge, or discard this patch.
Indentation   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -32,29 +32,29 @@  discard block
 block discarded – undo
32 32
     public const ERROR_TOO_MANY_REPLACERS = 65902;
33 33
     public const ERROR_NO_FORMATTERS_ADDED = 65903;
34 34
     
35
-   /**
36
-    * @var Mailcode_Parser_Safeguard
37
-    */
35
+    /**
36
+     * @var Mailcode_Parser_Safeguard
37
+     */
38 38
     private $safeguard;
39 39
     
40
-   /**
41
-    * @var Mailcode_Parser_Safeguard_Formatter[]
42
-    */
40
+    /**
41
+     * @var Mailcode_Parser_Safeguard_Formatter[]
42
+     */
43 43
     private $formatters = array();
44 44
     
45
-   /**
46
-    * @var Mailcode_StringContainer
47
-    */
45
+    /**
46
+     * @var Mailcode_StringContainer
47
+     */
48 48
     private $subject;
49 49
     
50
-   /**
51
-    * @var boolean
52
-    */
50
+    /**
51
+     * @var boolean
52
+     */
53 53
     private $applied = false;
54 54
     
55
-   /**
56
-    * @var boolean
57
-    */
55
+    /**
56
+     * @var boolean
57
+     */
58 58
     private $partial = false;
59 59
     
60 60
     public function __construct(Mailcode_Parser_Safeguard $safeguard, Mailcode_StringContainer $subject)
@@ -96,17 +96,17 @@  discard block
 block discarded – undo
96 96
         return $formatter;
97 97
     }
98 98
     
99
-   /**
100
-    * Adds a formatter that will surround all variables with
101
-    * markup to highlight them independently of command syntax
102
-    * highlighting.
103
-    * 
104
-    * This is used to mark variables visually even after commands
105
-    * have been replaced by the target system's post processing.
106
-    * Can be combined with a replacer and other formats.
107
-    * 
108
-    * @return Mailcode_Parser_Safeguard_Formatter_Type_MarkVariables
109
-    */
99
+    /**
100
+     * Adds a formatter that will surround all variables with
101
+     * markup to highlight them independently of command syntax
102
+     * highlighting.
103
+     * 
104
+     * This is used to mark variables visually even after commands
105
+     * have been replaced by the target system's post processing.
106
+     * Can be combined with a replacer and other formats.
107
+     * 
108
+     * @return Mailcode_Parser_Safeguard_Formatter_Type_MarkVariables
109
+     */
110 110
     public function formatWithMarkedVariables() : Mailcode_Parser_Safeguard_Formatter_Type_MarkVariables
111 111
     {
112 112
         $formatter = $this->createMarkVariables();
@@ -200,11 +200,11 @@  discard block
 block discarded – undo
200 200
         }
201 201
     }
202 202
     
203
-   /**
204
-    * Counts the amount of replacer formatters that have been added.
205
-    * 
206
-    * @return int
207
-    */
203
+    /**
204
+     * Counts the amount of replacer formatters that have been added.
205
+     * 
206
+     * @return int
207
+     */
208 208
     private function countReplacers() : int
209 209
     {
210 210
         $count = 0;
@@ -220,37 +220,37 @@  discard block
 block discarded – undo
220 220
         return $count;
221 221
     }
222 222
 
223
-   /**
224
-    * Creates a formatter that adds HTML syntax highlighting
225
-    * for all commands in the specified string, intelligently
226
-    * checking the location of the commands to ensure that they
227
-    * can be syntax highlighted.
228
-    * 
229
-    * For example, commands in HTML attributes will not be
230
-    * highlighted, as this would break the HTML.
231
-    *  
232
-    * @return Mailcode_Parser_Safeguard_Formatter_Type_HTMLHighlighting
233
-    */
223
+    /**
224
+     * Creates a formatter that adds HTML syntax highlighting
225
+     * for all commands in the specified string, intelligently
226
+     * checking the location of the commands to ensure that they
227
+     * can be syntax highlighted.
228
+     * 
229
+     * For example, commands in HTML attributes will not be
230
+     * highlighted, as this would break the HTML.
231
+     *  
232
+     * @return Mailcode_Parser_Safeguard_Formatter_Type_HTMLHighlighting
233
+     */
234 234
     public function createHTMLHighlighting() : Mailcode_Parser_Safeguard_Formatter_Type_HTMLHighlighting
235 235
     {
236 236
         return new Mailcode_Parser_Safeguard_Formatter_Type_HTMLHighlighting($this);
237 237
     }
238 238
 
239
-   /**
240
-    * Creates the formatter that ensures that all commands
241
-    * are placed on a separate line in the subject string.
242
-    */
239
+    /**
240
+     * Creates the formatter that ensures that all commands
241
+     * are placed on a separate line in the subject string.
242
+     */
243 243
     public function createSingleLines() : Mailcode_Parser_Safeguard_Formatter_Type_SingleLines
244 244
     {
245 245
         return new Mailcode_Parser_Safeguard_Formatter_Type_SingleLines($this);
246 246
     }
247 247
     
248
-   /**
249
-    * Creates the formatter that replaces all commands by
250
-    * their normalized variants.
251
-    * 
252
-    * @return Mailcode_Parser_Safeguard_Formatter_Type_Normalized
253
-    */
248
+    /**
249
+     * Creates the formatter that replaces all commands by
250
+     * their normalized variants.
251
+     * 
252
+     * @return Mailcode_Parser_Safeguard_Formatter_Type_Normalized
253
+     */
254 254
     public function createNormalized() : Mailcode_Parser_Safeguard_Formatter_Type_Normalized
255 255
     {
256 256
         return new Mailcode_Parser_Safeguard_Formatter_Type_Normalized($this);
@@ -278,26 +278,26 @@  discard block
 block discarded – undo
278 278
         return $this->subject->getString();
279 279
     }
280 280
 
281
-   /**
282
-    * Whether the formatting is done partially: missing placeholders
283
-    * will simply be ignored.
284
-    * 
285
-    * @return bool
286
-    */
281
+    /**
282
+     * Whether the formatting is done partially: missing placeholders
283
+     * will simply be ignored.
284
+     * 
285
+     * @return bool
286
+     */
287 287
     public function isPartial() : bool
288 288
     {
289 289
         return $this->partial;
290 290
     }
291 291
     
292
-   /**
293
-    * The formatting will ignore missing placeholders. Use this if the
294
-    * formatting will be done on a text that may not contain all of the
295
-    * initial placeholders anymore.
296
-    * 
297
-    * This is like the safeguard's makeWholePartial() method.
298
-    * 
299
-    * @return Mailcode_Parser_Safeguard_Formatting
300
-    */
292
+    /**
293
+     * The formatting will ignore missing placeholders. Use this if the
294
+     * formatting will be done on a text that may not contain all of the
295
+     * initial placeholders anymore.
296
+     * 
297
+     * This is like the safeguard's makeWholePartial() method.
298
+     * 
299
+     * @return Mailcode_Parser_Safeguard_Formatting
300
+     */
301 301
     public function makePartial() : Mailcode_Parser_Safeguard_Formatting
302 302
     {
303 303
         $this->partial = true;
Please login to merge, or discard this patch.
src/Mailcode/Parser/Safeguard.php 3 patches
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -260,8 +260,7 @@
 block discarded – undo
260 260
         if($highlighted)
261 261
         {
262 262
             $formatting->replaceWithHTMLHighlighting();
263
-        }
264
-        else 
263
+        } else 
265 264
         {
266 265
             $formatting->replaceWithNormalized();
267 266
         }
Please login to merge, or discard this patch.
Indentation   +146 added lines, -146 removed lines patch added patch discarded remove patch
@@ -54,40 +54,40 @@  discard block
 block discarded – undo
54 54
     public const ERROR_NO_PLACEHOLDER_FOR_COMMAND = 47805;
55 55
     public const ERROR_NO_FIRST_PLACEHOLDER = 47806;
56 56
 
57
-   /**
58
-    * @var Mailcode_Parser
59
-    */
57
+    /**
58
+     * @var Mailcode_Parser
59
+     */
60 60
     protected Mailcode_Parser $parser;
61 61
     
62
-   /**
63
-    * @var Mailcode_Collection
64
-    */
62
+    /**
63
+     * @var Mailcode_Collection
64
+     */
65 65
     protected Mailcode_Collection $commands;
66 66
     
67
-   /**
68
-    * @var string
69
-    */
67
+    /**
68
+     * @var string
69
+     */
70 70
     protected string $originalString;
71 71
     
72
-   /**
73
-    * @var Mailcode_Collection
74
-    */
72
+    /**
73
+     * @var Mailcode_Collection
74
+     */
75 75
     protected Mailcode_Collection $collection;
76 76
     
77
-   /**
78
-    * Counter for the placeholders, global for all placeholders.
79
-    * @var integer
80
-    */
77
+    /**
78
+     * Counter for the placeholders, global for all placeholders.
79
+     * @var integer
80
+     */
81 81
     private static int $counter = 0;
82 82
     
83
-   /**
84
-    * @var Mailcode_Parser_Safeguard_PlaceholderCollection|NULL
85
-    */
83
+    /**
84
+     * @var Mailcode_Parser_Safeguard_PlaceholderCollection|NULL
85
+     */
86 86
     protected ?Mailcode_Parser_Safeguard_PlaceholderCollection $placeholders = null;
87 87
     
88
-   /**
89
-    * @var string
90
-    */
88
+    /**
89
+     * @var string
90
+     */
91 91
     protected string $delimiter = '999';
92 92
     
93 93
     public function __construct(Mailcode_Parser $parser, string $subject)
@@ -106,28 +106,28 @@  discard block
 block discarded – undo
106 106
         self::$counter = 0;
107 107
     }
108 108
     
109
-   /**
110
-    * Retrieves the string the safeguard was created for.
111
-    * 
112
-    * @return string
113
-    */
109
+    /**
110
+     * Retrieves the string the safeguard was created for.
111
+     * 
112
+     * @return string
113
+     */
114 114
     public function getOriginalString() : string
115 115
     {
116 116
         return $this->originalString;
117 117
     }
118 118
     
119
-   /**
120
-    * Sets the delimiter character sequence used to prepend
121
-    * and append to the placeholders.
122
-    * 
123
-    * The delimiter's default is "999".
124
-    *
125
-    * Minimum characters: 2
126
-    * Invalid characters: Any characters that get URL encoded
127
-    *
128
-    * @param string $delimiter
129
-    * @return Mailcode_Parser_Safeguard
130
-    */
119
+    /**
120
+     * Sets the delimiter character sequence used to prepend
121
+     * and append to the placeholders.
122
+     * 
123
+     * The delimiter's default is "999".
124
+     *
125
+     * Minimum characters: 2
126
+     * Invalid characters: Any characters that get URL encoded
127
+     *
128
+     * @param string $delimiter
129
+     * @return Mailcode_Parser_Safeguard
130
+     */
131 131
     public function setDelimiter(string $delimiter) : Mailcode_Parser_Safeguard
132 132
     {
133 133
         $validator = new Mailcode_Parser_Safeguard_DelimiterValidator($delimiter);
@@ -143,15 +143,15 @@  discard block
 block discarded – undo
143 143
         return $this->delimiter;
144 144
     }
145 145
     
146
-   /**
147
-    * Retrieves the safe string in which all commands have been replaced
148
-    * by placeholder strings.
149
-    *
150
-    * @return string
151
-    * @throws Mailcode_Exception 
152
-    *
153
-    * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS
154
-    */
146
+    /**
147
+     * Retrieves the safe string in which all commands have been replaced
148
+     * by placeholder strings.
149
+     *
150
+     * @return string
151
+     * @throws Mailcode_Exception 
152
+     *
153
+     * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS
154
+     */
155 155
     public function makeSafe() : string
156 156
     {
157 157
         $this->requireValidCollection();
@@ -159,16 +159,16 @@  discard block
 block discarded – undo
159 159
         return $this->makeSafePartial();
160 160
     }
161 161
     
162
-   /**
163
-    * Like makeSafe(), but allows partial (invalid) commands: use this
164
-    * if the subject string may contain only part of the whole set of
165
-    * commands. 
166
-    * 
167
-    * Example: parsing a text with an opening if statement, without the 
168
-    * matching end statement.
169
-    * 
170
-    * @return string
171
-    */
162
+    /**
163
+     * Like makeSafe(), but allows partial (invalid) commands: use this
164
+     * if the subject string may contain only part of the whole set of
165
+     * commands. 
166
+     * 
167
+     * Example: parsing a text with an opening if statement, without the 
168
+     * matching end statement.
169
+     * 
170
+     * @return string
171
+     */
172 172
     public function makeSafePartial() : string
173 173
     {
174 174
         $placeholders = $this->getPlaceholdersCollection()->getAll();
@@ -218,13 +218,13 @@  discard block
 block discarded – undo
218 218
         $analyzer->analyze();
219 219
     }
220 220
     
221
-   /**
222
-    * Creates a formatting handler, which can be used to specify
223
-    * which formatting to use for the commands in the subject string.
224
-    * 
225
-    * @param Mailcode_StringContainer|string $subject
226
-    * @return Mailcode_Parser_Safeguard_Formatting
227
-    */
221
+    /**
222
+     * Creates a formatting handler, which can be used to specify
223
+     * which formatting to use for the commands in the subject string.
224
+     * 
225
+     * @param Mailcode_StringContainer|string $subject
226
+     * @return Mailcode_Parser_Safeguard_Formatting
227
+     */
228 228
     public function createFormatting($subject) : Mailcode_Parser_Safeguard_Formatting
229 229
     {
230 230
         if(is_string($subject))
@@ -249,11 +249,11 @@  discard block
 block discarded – undo
249 249
     }
250 250
 
251 251
     /**
252
-    * Retrieves all placeholders that have to be added to
253
-    * the subject text.
254
-    * 
255
-    * @return Mailcode_Parser_Safeguard_PlaceholderCollection
256
-    */
252
+     * Retrieves all placeholders that have to be added to
253
+     * the subject text.
254
+     * 
255
+     * @return Mailcode_Parser_Safeguard_PlaceholderCollection
256
+     */
257 257
     public function getPlaceholdersCollection() : Mailcode_Parser_Safeguard_PlaceholderCollection
258 258
     {
259 259
         if(isset($this->placeholders))
@@ -313,16 +313,16 @@  discard block
 block discarded – undo
313 313
         return $formatting->toString();
314 314
     }
315 315
 
316
-   /**
317
-    * Makes the string whole again after transforming or filtering it,
318
-    * by replacing the command placeholders with the original commands.
319
-    *
320
-    * @param string $string
321
-    * @return string
322
-    * @throws Mailcode_Exception
323
-    *
324
-    * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS
325
-    */
316
+    /**
317
+     * Makes the string whole again after transforming or filtering it,
318
+     * by replacing the command placeholders with the original commands.
319
+     *
320
+     * @param string $string
321
+     * @return string
322
+     * @throws Mailcode_Exception
323
+     *
324
+     * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS
325
+     */
326 326
     public function makeWhole(string $string) : string
327 327
     {
328 328
         return $this->restore(
@@ -332,15 +332,15 @@  discard block
 block discarded – undo
332 332
         );
333 333
     }
334 334
     
335
-   /**
336
-    * Like `makeWhole()`, but ignores missing command placeholders.
337
-    *
338
-    * @param string $string
339
-    * @return string
340
-    * @throws Mailcode_Exception
341
-    *
342
-    * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS
343
-    */
335
+    /**
336
+     * Like `makeWhole()`, but ignores missing command placeholders.
337
+     *
338
+     * @param string $string
339
+     * @return string
340
+     * @throws Mailcode_Exception
341
+     *
342
+     * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS
343
+     */
344 344
     public function makeWholePartial(string $string) : string
345 345
     {
346 346
         return $this->restore(
@@ -350,19 +350,19 @@  discard block
 block discarded – undo
350 350
         );
351 351
     }
352 352
 
353
-   /**
354
-    * Like `makeWhole()`, but replaces the commands with a syntax
355
-    * highlighted version, meant for human readable texts only.
356
-    * 
357
-    * Note: the commands lose their functionality (They cannot be 
358
-    * parsed from that string again).
359
-    *
360
-    * @param string $string
361
-    * @return string
362
-    * @throws Mailcode_Exception
363
-    *
364
-    * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS
365
-    */
353
+    /**
354
+     * Like `makeWhole()`, but replaces the commands with a syntax
355
+     * highlighted version, meant for human readable texts only.
356
+     * 
357
+     * Note: the commands lose their functionality (They cannot be 
358
+     * parsed from that string again).
359
+     *
360
+     * @param string $string
361
+     * @return string
362
+     * @throws Mailcode_Exception
363
+     *
364
+     * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS
365
+     */
366 366
     public function makeHighlighted(string $string) : string
367 367
     {
368 368
         return $this->restore(
@@ -372,15 +372,15 @@  discard block
 block discarded – undo
372 372
         );
373 373
     }
374 374
     
375
-   /**
376
-    * Like `makeHighlighted()`, but ignores missing command placeholders.
377
-    * 
378
-    * @param string $string
379
-    * @return string
380
-    * @throws Mailcode_Exception
381
-    *
382
-    * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS
383
-    */
375
+    /**
376
+     * Like `makeHighlighted()`, but ignores missing command placeholders.
377
+     * 
378
+     * @param string $string
379
+     * @return string
380
+     * @throws Mailcode_Exception
381
+     *
382
+     * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS
383
+     */
384 384
     public function makeHighlightedPartial(string $string) : string
385 385
     {
386 386
         return $this->restore(
@@ -390,11 +390,11 @@  discard block
 block discarded – undo
390 390
         );
391 391
     }
392 392
     
393
-   /**
394
-    * Retrieves the command collection contained in the string.
395
-    * 
396
-    * @return Mailcode_Collection
397
-    */
393
+    /**
394
+     * Retrieves the command collection contained in the string.
395
+     * 
396
+     * @return Mailcode_Collection
397
+     */
398 398
     public function getCollection() : Mailcode_Collection
399 399
     {
400 400
         if(isset($this->collection))
@@ -418,11 +418,11 @@  discard block
 block discarded – undo
418 418
         return $this->getCollection()->isValid();
419 419
     }
420 420
     
421
-   /**
422
-    * @throws Mailcode_Exception
423
-    * 
424
-    * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS
425
-    */
421
+    /**
422
+     * @throws Mailcode_Exception
423
+     * 
424
+     * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS
425
+     */
426 426
     protected function requireValidCollection() : void
427 427
     {
428 428
         if($this->getCollection()->isValid())
@@ -445,13 +445,13 @@  discard block
 block discarded – undo
445 445
         throw $exception;
446 446
     }
447 447
     
448
-   /**
449
-    * Retrieves a list of all placeholder IDs used in the text.
450
-    * 
451
-    * @return string[]
452
-    *
453
-    * @deprecated Use the placeholder collection instead {@see Mailcode_Parser_Safeguard::getPlaceholdersCollection()}.
454
-    */
448
+    /**
449
+     * Retrieves a list of all placeholder IDs used in the text.
450
+     * 
451
+     * @return string[]
452
+     *
453
+     * @deprecated Use the placeholder collection instead {@see Mailcode_Parser_Safeguard::getPlaceholdersCollection()}.
454
+     */
455 455
     public function getPlaceholderStrings() : array
456 456
     {
457 457
         return $this->getPlaceholdersCollection()->getStrings();
@@ -462,29 +462,29 @@  discard block
 block discarded – undo
462 462
         return $this->getPlaceholdersCollection()->isStringPlaceholder($subject);
463 463
     }
464 464
     
465
-   /**
466
-    * Retrieves a placeholder instance by its ID.
467
-    * 
468
-    * @param int $id
469
-    * @throws Mailcode_Exception If the placeholder was not found.
470
-    * @return Mailcode_Parser_Safeguard_Placeholder
471
-    *
472
-    * @deprecated Use the placeholder collection instead {@see Mailcode_Parser_Safeguard::getPlaceholdersCollection()}.
473
-    */
465
+    /**
466
+     * Retrieves a placeholder instance by its ID.
467
+     * 
468
+     * @param int $id
469
+     * @throws Mailcode_Exception If the placeholder was not found.
470
+     * @return Mailcode_Parser_Safeguard_Placeholder
471
+     *
472
+     * @deprecated Use the placeholder collection instead {@see Mailcode_Parser_Safeguard::getPlaceholdersCollection()}.
473
+     */
474 474
     public function getPlaceholderByID(int $id) : Mailcode_Parser_Safeguard_Placeholder
475 475
     {
476 476
         return $this->getPlaceholdersCollection()->getByID($id);
477 477
     }
478 478
     
479
-   /**
480
-    * Retrieves a placeholder instance by its replacement text.
481
-    * 
482
-    * @param string $string
483
-    * @throws Mailcode_Exception
484
-    * @return Mailcode_Parser_Safeguard_Placeholder
485
-    *
486
-    * @deprecated Use the placeholder collection instead {@see Mailcode_Parser_Safeguard::getPlaceholdersCollection()}.
487
-    */
479
+    /**
480
+     * Retrieves a placeholder instance by its replacement text.
481
+     * 
482
+     * @param string $string
483
+     * @throws Mailcode_Exception
484
+     * @return Mailcode_Parser_Safeguard_Placeholder
485
+     *
486
+     * @deprecated Use the placeholder collection instead {@see Mailcode_Parser_Safeguard::getPlaceholdersCollection()}.
487
+     */
488 488
     public function getPlaceholderByString(string $string) : Mailcode_Parser_Safeguard_Placeholder
489 489
     {
490 490
         return $this->getPlaceholdersCollection()->getByString($string);
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
         $placeholders = $this->getPlaceholdersCollection()->getAll();
175 175
         $string = $this->originalString;
176 176
         
177
-        foreach($placeholders as $placeholder)
177
+        foreach ($placeholders as $placeholder)
178 178
         {
179 179
             $string = $this->makePlaceholderSafe($string, $placeholder);
180 180
         }
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
     {
189 189
         $pos = mb_strpos($string, $placeholder->getOriginalText());
190 190
 
191
-        if($pos === false)
191
+        if ($pos === false)
192 192
         {
193 193
             throw new Mailcode_Exception(
194 194
                 'Placeholder original text not found',
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
     */
228 228
     public function createFormatting($subject) : Mailcode_Parser_Safeguard_Formatting
229 229
     {
230
-        if(is_string($subject))
230
+        if (is_string($subject))
231 231
         {
232 232
             $subject = Mailcode::create()->createString($subject);
233 233
         }
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
     */
257 257
     public function getPlaceholdersCollection() : Mailcode_Parser_Safeguard_PlaceholderCollection
258 258
     {
259
-        if(isset($this->placeholders))
259
+        if (isset($this->placeholders))
260 260
         {
261 261
             return $this->placeholders;
262 262
         }
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
         $placeholders = array();
265 265
         $commands = $this->getCollection()->getCommands();
266 266
         
267
-        foreach($commands as $command)
267
+        foreach ($commands as $command)
268 268
         {
269 269
             self::$counter++;
270 270
             
@@ -287,21 +287,21 @@  discard block
 block discarded – undo
287 287
      * @return string
288 288
      * @throws Mailcode_Exception
289 289
      */
290
-    protected function restore(string $string, bool $partial=false, bool $highlighted=false) : string
290
+    protected function restore(string $string, bool $partial = false, bool $highlighted = false) : string
291 291
     {
292
-        if(!$partial)
292
+        if (!$partial)
293 293
         {
294 294
             $this->requireValidCollection();
295 295
         }
296 296
         
297 297
         $formatting = $this->createFormatting($string);
298 298
 
299
-        if($partial)
299
+        if ($partial)
300 300
         {
301 301
             $formatting->makePartial();
302 302
         }
303 303
         
304
-        if($highlighted)
304
+        if ($highlighted)
305 305
         {
306 306
             $formatting->replaceWithHTMLHighlighting();
307 307
         }
@@ -397,7 +397,7 @@  discard block
 block discarded – undo
397 397
     */
398 398
     public function getCollection() : Mailcode_Collection
399 399
     {
400
-        if(isset($this->collection))
400
+        if (isset($this->collection))
401 401
         {
402 402
             return $this->collection;
403 403
         }
@@ -425,7 +425,7 @@  discard block
 block discarded – undo
425 425
     */
426 426
     protected function requireValidCollection() : void
427 427
     {
428
-        if($this->getCollection()->isValid())
428
+        if ($this->getCollection()->isValid())
429 429
         {
430 430
             return;
431 431
         }
Please login to merge, or discard this patch.
src/Mailcode/StringContainer.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -88,12 +88,12 @@  discard block
 block discarded – undo
88 88
     public function updateString(string $subject) : bool
89 89
     {
90 90
         // avoid triggering an update if there are no changes in the string
91
-        if($subject === $this->subject)
91
+        if ($subject === $this->subject)
92 92
         {
93 93
             return false;
94 94
         }
95 95
         
96
-        if($this->updating)
96
+        if ($this->updating)
97 97
         {
98 98
             throw new Mailcode_Exception(
99 99
                 'Cannot modify subject string during update',
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
         $this->subject = $subject;
108 108
         $this->length = mb_strlen($this->subject);
109 109
         
110
-        foreach($this->listeners as $listener)
110
+        foreach ($this->listeners as $listener)
111 111
         {
112 112
             $listener($this);
113 113
         }
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
     {
143 143
         self::$listenerCounter++;
144 144
         
145
-        if(!is_callable($callback))
145
+        if (!is_callable($callback))
146 146
         {
147 147
             throw new Mailcode_Exception(
148 148
                 'Not a valid callable',
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
     */
173 173
     public function removeListener(int $listenerID) : void
174 174
     {
175
-        if(isset($this->listeners[$listenerID]))
175
+        if (isset($this->listeners[$listenerID]))
176 176
         {
177 177
             unset($this->listeners[$listenerID]);
178 178
         }
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
         return mb_strpos($this->subject, $needle);
204 204
     }
205 205
     
206
-    public function getSubstr(int $start, ?int $length=null) : string
206
+    public function getSubstr(int $start, ?int $length = null) : string
207 207
     {
208 208
         return mb_substr($this->subject, $start, $length);
209 209
     }
Please login to merge, or discard this patch.
Indentation   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -26,39 +26,39 @@  discard block
 block discarded – undo
26 26
     public const ERROR_INVALID_CALLABLE = 65701;
27 27
     public const ERROR_UPDATE_CALLED_DURING_UPDATE_OPERATION = 65702;
28 28
     
29
-   /**
30
-    * @var string
31
-    */
29
+    /**
30
+     * @var string
31
+     */
32 32
     private $subject;
33 33
     
34
-   /**
35
-    * @var integer
36
-    */
34
+    /**
35
+     * @var integer
36
+     */
37 37
     private static $listenerCounter = 0;
38 38
     
39
-   /**
40
-    * @var callable[]
41
-    */
39
+    /**
40
+     * @var callable[]
41
+     */
42 42
     private $listeners = array();
43 43
     
44
-   /**
45
-    * @var boolean
46
-    */
44
+    /**
45
+     * @var boolean
46
+     */
47 47
     private $updating = false;
48 48
     
49
-   /**
50
-    * @var integer
51
-    */
49
+    /**
50
+     * @var integer
51
+     */
52 52
     private static $idCounter = 0;
53 53
     
54
-   /**
55
-    * @var integer
56
-    */
54
+    /**
55
+     * @var integer
56
+     */
57 57
     private $id;
58 58
     
59
-   /**
60
-    * @var integer
61
-    */
59
+    /**
60
+     * @var integer
61
+     */
62 62
     private $length;
63 63
     
64 64
     public function __construct(string $subject)
@@ -75,16 +75,16 @@  discard block
 block discarded – undo
75 75
         return $this->id;
76 76
     }
77 77
     
78
-   /**
79
-    * Updates the string with the specified string.
80
-    * Notifies all listeners of the change.
81
-    * 
82
-    * @param string $subject
83
-    * @throws Mailcode_Exception
84
-    * @return bool Whether the string had modifications.
85
-    * 
86
-    * @see Mailcode_StringContainer::ERROR_UPDATE_CALLED_DURING_UPDATE_OPERATION
87
-    */
78
+    /**
79
+     * Updates the string with the specified string.
80
+     * Notifies all listeners of the change.
81
+     * 
82
+     * @param string $subject
83
+     * @throws Mailcode_Exception
84
+     * @return bool Whether the string had modifications.
85
+     * 
86
+     * @see Mailcode_StringContainer::ERROR_UPDATE_CALLED_DURING_UPDATE_OPERATION
87
+     */
88 88
     public function updateString(string $subject) : bool
89 89
     {
90 90
         // avoid triggering an update if there are no changes in the string
@@ -117,27 +117,27 @@  discard block
 block discarded – undo
117 117
         return true;
118 118
     }
119 119
     
120
-   /**
121
-    * Retrieves the stored string.
122
-    * 
123
-    * @return string
124
-    */
120
+    /**
121
+     * Retrieves the stored string.
122
+     * 
123
+     * @return string
124
+     */
125 125
     public function getString() : string
126 126
     {
127 127
         return $this->subject;
128 128
     }
129 129
     
130
-   /**
131
-    * Adds a listener that will be informed every time the string is modified.
132
-    * The callback gets the string container instance as parameter.
133
-    * 
134
-    * @param callable $callback
135
-    * @throws Mailcode_Exception If it is not a valid callable.
136
-    * @return int The listener number, to be able to remove it using `removeListener()`.
137
-    * 
138
-    * @see Mailcode_StringContainer::removeListener()
139
-    * @see Mailcode_StringContainer::ERROR_INVALID_CALLABLE
140
-    */
130
+    /**
131
+     * Adds a listener that will be informed every time the string is modified.
132
+     * The callback gets the string container instance as parameter.
133
+     * 
134
+     * @param callable $callback
135
+     * @throws Mailcode_Exception If it is not a valid callable.
136
+     * @return int The listener number, to be able to remove it using `removeListener()`.
137
+     * 
138
+     * @see Mailcode_StringContainer::removeListener()
139
+     * @see Mailcode_StringContainer::ERROR_INVALID_CALLABLE
140
+     */
141 141
     public function addListener($callback) : int
142 142
     {
143 143
         self::$listenerCounter++;
@@ -164,12 +164,12 @@  discard block
 block discarded – undo
164 164
         return $this->length;
165 165
     }
166 166
     
167
-   /**
168
-    * Removes an existing listener by its ID.
169
-    * Has no effect if it does not exist, or has already been removed.
170
-    * 
171
-    * @param int $listenerID
172
-    */
167
+    /**
168
+     * Removes an existing listener by its ID.
169
+     * Has no effect if it does not exist, or has already been removed.
170
+     * 
171
+     * @param int $listenerID
172
+     */
173 173
     public function removeListener(int $listenerID) : void
174 174
     {
175 175
         if(isset($this->listeners[$listenerID]))
@@ -178,13 +178,13 @@  discard block
 block discarded – undo
178 178
         }
179 179
     }
180 180
     
181
-   /**
182
-    * Replaces all substrings matching needle with the replacement text.
183
-    *  
184
-    * @param string $needle
185
-    * @param string $replacement
186
-    * @return bool
187
-    */
181
+    /**
182
+     * Replaces all substrings matching needle with the replacement text.
183
+     *  
184
+     * @param string $needle
185
+     * @param string $replacement
186
+     * @return bool
187
+     */
188 188
     public function replaceSubstrings(string $needle, string $replacement) : bool
189 189
     {
190 190
         $string = str_replace($needle, $replacement, $this->subject);
@@ -192,12 +192,12 @@  discard block
 block discarded – undo
192 192
         return $this->updateString($string);
193 193
     }
194 194
 
195
-   /**
196
-    * Get the position of a substring in the string.
197
-    * 
198
-    * @param string $needle
199
-    * @return int|bool The zero-based position, or false if not found.
200
-    */
195
+    /**
196
+     * Get the position of a substring in the string.
197
+     * 
198
+     * @param string $needle
199
+     * @return int|bool The zero-based position, or false if not found.
200
+     */
201 201
     public function getSubstrPosition(string $needle)
202 202
     {
203 203
         return mb_strpos($this->subject, $needle);
Please login to merge, or discard this patch.
src/Mailcode/Parser/Safeguard/Formatter.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
         
78 78
         $instance = new $class($this, $placeholder);
79 79
         
80
-        if($instance instanceof Mailcode_Parser_Safeguard_Formatter_Location)
80
+        if ($instance instanceof Mailcode_Parser_Safeguard_Formatter_Location)
81 81
         {
82 82
             return $instance;
83 83
         }
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
         
106 106
         $result = array();
107 107
         
108
-        foreach($placeholders as $placeholder)
108
+        foreach ($placeholders as $placeholder)
109 109
         {
110 110
             $result[] = $this->createLocation($placeholder);
111 111
         }
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
     {
124 124
         $eol = ConvertHelper::detectEOLCharacter($subject);
125 125
         
126
-        if($eol)
126
+        if ($eol)
127 127
         {
128 128
             $this->log(sprintf(
129 129
                 'Detected EOL character: %s.', 
Please login to merge, or discard this patch.
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -27,19 +27,19 @@  discard block
 block discarded – undo
27 27
 {
28 28
     public const ERROR_INVALID_LOCATION_INSTANCE = 65601;
29 29
     
30
-   /**
31
-    * @var Mailcode_Parser_Safeguard_Formatting
32
-    */
30
+    /**
31
+     * @var Mailcode_Parser_Safeguard_Formatting
32
+     */
33 33
     protected $formatting;
34 34
     
35
-   /**
36
-    * @var Mailcode_StringContainer
37
-    */
35
+    /**
36
+     * @var Mailcode_StringContainer
37
+     */
38 38
     protected $subject;
39 39
     
40
-   /**
41
-    * @var string[]
42
-    */
40
+    /**
41
+     * @var string[]
42
+     */
43 43
     protected $log = array();
44 44
     
45 45
     public function __construct(Mailcode_Parser_Safeguard_Formatting $formatting)
@@ -98,12 +98,12 @@  discard block
 block discarded – undo
98 98
         );
99 99
     }
100 100
     
101
-   /**
102
-    * Retrieves all formatter-specific placeholder locations 
103
-    * in the subject string.
104
-    * 
105
-    * @return Mailcode_Parser_Safeguard_Formatter_Location[]
106
-    */
101
+    /**
102
+     * Retrieves all formatter-specific placeholder locations 
103
+     * in the subject string.
104
+     * 
105
+     * @return Mailcode_Parser_Safeguard_Formatter_Location[]
106
+     */
107 107
     protected function resolveLocations() : array
108 108
     {
109 109
         $placeholders = $this->formatting->getSafeguard()->getPlaceholdersCollection()->getAll();
@@ -118,12 +118,12 @@  discard block
 block discarded – undo
118 118
         return $result;
119 119
     }
120 120
     
121
-   /**
122
-    * Resolves the newline character used in the string.
123
-    * 
124
-    * @param string $subject
125
-    * @return string
126
-    */
121
+    /**
122
+     * Resolves the newline character used in the string.
123
+     * 
124
+     * @param string $subject
125
+     * @return string
126
+     */
127 127
     protected function resolveNewlineChar(string $subject) : string
128 128
     {
129 129
         $eol = ConvertHelper::detectEOLCharacter($subject);
@@ -155,9 +155,9 @@  discard block
 block discarded – undo
155 155
         );
156 156
     }
157 157
  
158
-   /**
159
-    * @return string[]
160
-    */
158
+    /**
159
+     * @return string[]
160
+     */
161 161
     public function getLog() : array
162 162
     {
163 163
         return $this->log;
Please login to merge, or discard this patch.
src/Mailcode/Parser/Safeguard/Formatter/Location.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -89,23 +89,23 @@  discard block
 block discarded – undo
89 89
         
90 90
         $placeholderID = $this->placeholder->getID();
91 91
         
92
-        foreach($placeholders as $placeholder)
92
+        foreach ($placeholders as $placeholder)
93 93
         {
94
-            if($placeholder->getID() === $placeholderID)
94
+            if ($placeholder->getID() === $placeholderID)
95 95
             {
96 96
                 continue;
97 97
             }
98 98
             
99 99
             $start = $this->subject->getSubstrPosition($placeholder->getReplacementText());
100 100
             
101
-            if($start === false)
101
+            if ($start === false)
102 102
             {
103 103
                 continue;
104 104
             }
105 105
             
106 106
             $end = $start + $placeholder->getReplacementLength();
107 107
             
108
-            if($position >= $start && $position <= $end)
108
+            if ($position >= $start && $position <= $end)
109 109
             {
110 110
                 return true;
111 111
             }
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
     {
122 122
         $start = $this->getStartPosition();
123 123
         
124
-        if($start !== false)
124
+        if ($start !== false)
125 125
         {
126 126
             return $start + $this->placeholder->getReplacementLength();
127 127
         }
@@ -151,14 +151,14 @@  discard block
 block discarded – undo
151 151
     {
152 152
         $needle = $this->placeholder->getReplacementText();
153 153
         
154
-        if($this->subject->replaceSubstrings($needle, $replacementText))
154
+        if ($this->subject->replaceSubstrings($needle, $replacementText))
155 155
         {
156 156
             return;
157 157
         }
158 158
         
159 159
         // Complain about missing placeholders only if we
160 160
         // are not in partial mode.
161
-        if(!$this->formatter->getFormatting()->isPartial())
161
+        if (!$this->formatter->getFormatting()->isPartial())
162 162
         {
163 163
             throw new Mailcode_Exception(
164 164
                 'Could not find the placeholder to replace',
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
     
174 174
     public function format() : void
175 175
     {
176
-        if($this->requiresAdjustment() && (!empty($this->prepend) || !empty($this->append)))
176
+        if ($this->requiresAdjustment() && (!empty($this->prepend) || !empty($this->append)))
177 177
         {
178 178
             $this->replaceWith(sprintf(
179 179
                 '%s%s%s',
Please login to merge, or discard this patch.
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -24,34 +24,34 @@  discard block
 block discarded – undo
24 24
 {
25 25
     public const ERROR_PLACEHOLDER_NOT_FOUND = 66001;
26 26
     
27
-   /**
28
-    * @var Mailcode_Parser_Safeguard_Formatter
29
-    */
27
+    /**
28
+     * @var Mailcode_Parser_Safeguard_Formatter
29
+     */
30 30
     protected $formatter;
31 31
     
32
-   /**
33
-    * @var string
34
-    */
32
+    /**
33
+     * @var string
34
+     */
35 35
     protected $append = '';
36 36
 
37
-   /**
38
-    * @var string
39
-    */
37
+    /**
38
+     * @var string
39
+     */
40 40
     protected $prepend = '';
41 41
     
42
-   /**
43
-    * @var Mailcode_Parser_Safeguard_Placeholder
44
-    */
42
+    /**
43
+     * @var Mailcode_Parser_Safeguard_Placeholder
44
+     */
45 45
     protected $placeholder;
46 46
     
47
-   /**
48
-    * @var Mailcode_StringContainer
49
-    */
47
+    /**
48
+     * @var Mailcode_StringContainer
49
+     */
50 50
     protected $subject;
51 51
     
52
-   /**
53
-    * @var string[]
54
-    */
52
+    /**
53
+     * @var string[]
54
+     */
55 55
     protected $log = array();
56 56
     
57 57
     public function __construct(Mailcode_Parser_Safeguard_Formatter $formatter, Mailcode_Parser_Safeguard_Placeholder $placeholder)
@@ -67,22 +67,22 @@  discard block
 block discarded – undo
67 67
     
68 68
     abstract public function requiresAdjustment() : bool;
69 69
     
70
-   /**
71
-    * @return int|boolean
72
-    */
70
+    /**
71
+     * @return int|boolean
72
+     */
73 73
     public function getStartPosition()
74 74
     {
75 75
         return $this->subject->getSubstrPosition($this->placeholder->getReplacementText());
76 76
     }
77 77
     
78
-   /**
79
-    * Checks whether the specified position within the string
80
-    * is within another command's placeholder (excluding this
81
-    * location's placeholder).
82
-    * 
83
-    * @param int $position
84
-    * @return bool
85
-    */
78
+    /**
79
+     * Checks whether the specified position within the string
80
+     * is within another command's placeholder (excluding this
81
+     * location's placeholder).
82
+     * 
83
+     * @param int $position
84
+     * @return bool
85
+     */
86 86
     public function isWithinCommand(int $position) : bool
87 87
     {
88 88
         $placeholders = $this->formatter->getSafeguard()->getPlaceholdersCollection()->getAll();
@@ -114,9 +114,9 @@  discard block
 block discarded – undo
114 114
         return false;
115 115
     }
116 116
     
117
-   /**
118
-    * @return int|boolean
119
-    */
117
+    /**
118
+     * @return int|boolean
119
+     */
120 120
     public function getEndPosition()
121 121
     {
122 122
         $start = $this->getStartPosition();
@@ -139,14 +139,14 @@  discard block
 block discarded – undo
139 139
         return $this->placeholder;
140 140
     }
141 141
     
142
-   /**
143
-    * Replaces the placeholder with the specified replacement text.
144
-    * 
145
-    * @param string $replacementText
146
-    * @throws Mailcode_Exception
147
-    * 
148
-    * @see Mailcode_Parser_Safeguard_Formatter_Location::ERROR_PLACEHOLDER_NOT_FOUND
149
-    */
142
+    /**
143
+     * Replaces the placeholder with the specified replacement text.
144
+     * 
145
+     * @param string $replacementText
146
+     * @throws Mailcode_Exception
147
+     * 
148
+     * @see Mailcode_Parser_Safeguard_Formatter_Location::ERROR_PLACEHOLDER_NOT_FOUND
149
+     */
150 150
     public function replaceWith(string $replacementText) : void
151 151
     {
152 152
         $needle = $this->placeholder->getReplacementText();
@@ -196,10 +196,10 @@  discard block
 block discarded – undo
196 196
         );
197 197
     }
198 198
     
199
-   /**
200
-    * Retrieves the location's log messages, if any.
201
-    * @return string[]
202
-    */
199
+    /**
200
+     * Retrieves the location's log messages, if any.
201
+     * @return string[]
202
+     */
203 203
     public function getLog() : array
204 204
     {
205 205
         return $this->log;
Please login to merge, or discard this patch.
src/Mailcode/Parser.php 3 patches
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -146,8 +146,7 @@  discard block
 block discarded – undo
146 146
         if($cmd instanceof Mailcode_Commands_Command_Type_Opening)
147 147
         {
148 148
             $this->stack[] = $cmd;
149
-        }
150
-        else if($cmd instanceof Mailcode_Commands_Command_Type_Closing)
149
+        } else if($cmd instanceof Mailcode_Commands_Command_Type_Closing)
151 150
         {
152 151
             array_pop($this->stack);
153 152
         }
@@ -177,13 +176,11 @@  discard block
 block discarded – undo
177 176
         if(!empty($matches[1][$index]))
178 177
         {
179 178
             $name = $matches[1][$index];
180
-        }
181
-        else if(!empty($matches[2][$index]))
179
+        } else if(!empty($matches[2][$index]))
182 180
         {
183 181
             $name = $matches[2][$index];
184 182
             $params = $matches[3][$index];
185
-        }
186
-        else if(!empty($matches[4][$index]))
183
+        } else if(!empty($matches[4][$index]))
187 184
         {
188 185
             $name = $matches[4][$index];
189 186
             $type = $matches[5][$index];
Please login to merge, or discard this patch.
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -42,11 +42,11 @@  discard block
 block discarded – undo
42 42
         $this->commands = $this->mailcode->getCommands();
43 43
     }
44 44
     
45
-   /**
46
-    * Gets the regex format string used to detect commands.
47
-    * 
48
-    * @return string
49
-    */
45
+    /**
46
+     * Gets the regex format string used to detect commands.
47
+     * 
48
+     * @return string
49
+     */
50 50
     protected static function getRegex() : string
51 51
     {
52 52
         return '/'.implode('|', self::COMMAND_REGEX_PARTS).'/sixU';
@@ -183,14 +183,14 @@  discard block
 block discarded – undo
183 183
         throw new Mailcode_Exception('Not a command', '', self::ERROR_NOT_A_COMMAND);
184 184
     }
185 185
     
186
-   /**
187
-    * Parses a single regex match: determines which named group
188
-    * matches, and retrieves the according information.
189
-    * 
190
-    * @param array<int,array<int,string>>$matches The regex results array.
191
-    * @param int $index The matched index.
192
-    * @return Mailcode_Parser_Match
193
-    */
186
+    /**
187
+     * Parses a single regex match: determines which named group
188
+     * matches, and retrieves the according information.
189
+     * 
190
+     * @param array<int,array<int,string>>$matches The regex results array.
191
+     * @param int $index The matched index.
192
+     * @return Mailcode_Parser_Match
193
+     */
194 194
     protected function parseMatch(array $matches, int $index) : Mailcode_Parser_Match
195 195
     {
196 196
         $name = ''; // the command name, e.g. "showvar"
@@ -228,14 +228,14 @@  discard block
 block discarded – undo
228 228
         );
229 229
     }
230 230
     
231
-   /**
232
-    * Creates an instance of the safeguard tool, which
233
-    * is used to safeguard commands in a string with placeholders.
234
-    * 
235
-    * @param string $subject The string to use to safeguard commands in.
236
-    * @return Mailcode_Parser_Safeguard
237
-    * @see Mailcode_Parser_Safeguard
238
-    */
231
+    /**
232
+     * Creates an instance of the safeguard tool, which
233
+     * is used to safeguard commands in a string with placeholders.
234
+     * 
235
+     * @param string $subject The string to use to safeguard commands in.
236
+     * @return Mailcode_Parser_Safeguard
237
+     * @see Mailcode_Parser_Safeguard
238
+     */
239 239
     public function createSafeguard(string $subject) : Mailcode_Parser_Safeguard
240 240
     {
241 241
         return new Mailcode_Parser_Safeguard($this, $subject);
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 
73 73
         $result = new ParseResult($collection, $preParser);
74 74
 
75
-        if(!$collection->isValid())
75
+        if (!$collection->isValid())
76 76
         {
77 77
             return $result;
78 78
         }
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
         
85 85
         $total = count($matches[0]);
86 86
 
87
-        for($i=0; $i < $total; $i++)
87
+        for ($i = 0; $i < $total; $i++)
88 88
         {
89 89
             $match = $this->parseMatch($matches, $i);
90 90
             
@@ -154,17 +154,17 @@  discard block
 block discarded – undo
154 154
     private function handleNesting(Mailcode_Commands_Command $cmd) : void
155 155
     {
156 156
         // Set the command's parent from the stack, if any is present.
157
-        if(!empty($this->stack))
157
+        if (!empty($this->stack))
158 158
         {
159 159
             $cmd->setParent($this->getStackLast());
160 160
         }
161 161
 
162 162
         // Handle opening and closing commands, adding and removing from the stack.
163
-        if($cmd instanceof Mailcode_Commands_Command_Type_Opening)
163
+        if ($cmd instanceof Mailcode_Commands_Command_Type_Opening)
164 164
         {
165 165
             $this->stack[] = $cmd;
166 166
         }
167
-        else if($cmd instanceof Mailcode_Commands_Command_Type_Closing)
167
+        else if ($cmd instanceof Mailcode_Commands_Command_Type_Closing)
168 168
         {
169 169
             array_pop($this->stack);
170 170
         }
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
     {
179 179
         $cmd = $this->stack[array_key_last($this->stack)];
180 180
 
181
-        if($cmd instanceof Mailcode_Commands_Command)
181
+        if ($cmd instanceof Mailcode_Commands_Command)
182 182
         {
183 183
             return $cmd;
184 184
         }
@@ -207,16 +207,16 @@  discard block
 block discarded – undo
207 207
         // 5 = parameter type command, type
208 208
         // 6 = parameter type command, params
209 209
         
210
-        if(!empty($matches[1][$index]))
210
+        if (!empty($matches[1][$index]))
211 211
         {
212 212
             $name = $matches[1][$index];
213 213
         }
214
-        else if(!empty($matches[2][$index]))
214
+        else if (!empty($matches[2][$index]))
215 215
         {
216 216
             $name = $matches[2][$index];
217 217
             $params = $matches[3][$index];
218 218
         }
219
-        else if(!empty($matches[4][$index]))
219
+        else if (!empty($matches[4][$index]))
220 220
         {
221 221
             $name = $matches[4][$index];
222 222
             $type = $matches[5][$index];
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
      * @param Mailcode_Commands_Command|null $sourceCommand
254 254
      * @return Mailcode_Parser_Statement
255 255
      */
256
-    public function createStatement(string $statement, bool $freeform=false, ?Mailcode_Commands_Command $sourceCommand=null) : Mailcode_Parser_Statement
256
+    public function createStatement(string $statement, bool $freeform = false, ?Mailcode_Commands_Command $sourceCommand = null) : Mailcode_Parser_Statement
257 257
     {
258 258
         return new Mailcode_Parser_Statement($statement, $freeform, $sourceCommand);
259 259
     }
Please login to merge, or discard this patch.
src/Mailcode/Parser/Safeguard/Formatter/Type/MarkVariables.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
     
61 61
     public function setTemplate(string $template) : Mailcode_Parser_Safeguard_Formatter_Type_MarkVariables
62 62
     {
63
-        if(substr_count($template, '%s') !== 1)
63
+        if (substr_count($template, '%s') !== 1)
64 64
         {
65 65
             throw new Mailcode_Exception(
66 66
                 'Invalid tag template',
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
         $parts = explode('%s', $this->getTemplate());
102 102
         $tag = array_shift($parts);
103 103
 
104
-        if($this->templateMode === self::TEMPLATE_MODE_INLINE)
104
+        if ($this->templateMode === self::TEMPLATE_MODE_INLINE)
105 105
         {
106 106
             $tag = str_replace('__STYLES__', $this->getInlineStyles(), $tag);
107 107
         }
@@ -129,12 +129,12 @@  discard block
 block discarded – undo
129 129
         $styles = '';
130 130
         $regex = '/\.'.self::DEFAULT_CLASS_NAME.'{([^}]+)}/';
131 131
 
132
-        if(preg_match($regex, $this->getCSS(), $matches))
132
+        if (preg_match($regex, $this->getCSS(), $matches))
133 133
         {
134 134
             $styles = $matches[1];
135 135
         }
136 136
 
137
-        if(empty($styles))
137
+        if (empty($styles))
138 138
         {
139 139
             throw new Mailcode_Exception(
140 140
                 'Cannot extract styles.',
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
         $file = MAILCODE_INSTALL_FOLDER.'/css/marked-variables.css';
192 192
         $path = realpath($file);
193 193
 
194
-        if($path !== false)
194
+        if ($path !== false)
195 195
         {
196 196
             return $path;
197 197
         }
Please login to merge, or discard this patch.
src/Mailcode/Number/Info.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
     {
43 43
         $format = trim($format);
44 44
 
45
-        if(empty($format))
45
+        if (empty($format))
46 46
         {
47 47
             $format = self::DEFAULT_FORMAT;
48 48
         }
@@ -108,15 +108,15 @@  discard block
 block discarded – undo
108 108
     {
109 109
         $format = $this->format;
110 110
 
111
-        foreach($this->validations as $validation)
111
+        foreach ($this->validations as $validation)
112 112
         {
113 113
             $method = 'parse_'.$validation;
114 114
 
115
-            if(method_exists($this, $method))
115
+            if (method_exists($this, $method))
116 116
             {
117 117
                 $format = $this->$method($format);
118 118
 
119
-                if(!$this->isValid())
119
+                if (!$this->isValid())
120 120
                 {
121 121
                     return;
122 122
                 }
@@ -138,13 +138,13 @@  discard block
 block discarded – undo
138 138
 
139 139
     private function parse_padding(string $format) : string
140 140
     {
141
-        if(strstr($format, ':') === false) {
141
+        if (strstr($format, ':') === false) {
142 142
             return $format;
143 143
         }
144 144
 
145 145
         $parts = ConvertHelper::explodeTrim(':', $this->format);
146 146
 
147
-        if(count($parts) !== 2)
147
+        if (count($parts) !== 2)
148 148
         {
149 149
             $this->makeError(
150 150
                 t(
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 
160 160
         $padding = $parts[1];
161 161
 
162
-        if(!preg_match('/\A[#]+\z/x', $padding))
162
+        if (!preg_match('/\A[#]+\z/x', $padding))
163 163
         {
164 164
             $this->makeError(
165 165
                 t('The padding may only contain hashes (%1$s given).', '<code>'.$padding.'</code>'),
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
 
177 177
     private function parse_number(string $format) : string
178 178
     {
179
-        if($format[0] !== '1')
179
+        if ($format[0] !== '1')
180 180
         {
181 181
             $this->makeError(
182 182
                 t('The first character of the format must be a %1$s.', '<code>1</code>'),
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
         $base = str_replace(array('.', ',', ' '), '', $format);
191 191
         $number = intval(substr($base, 0, 4));
192 192
 
193
-        if($number === 1000) {
193
+        if ($number === 1000) {
194 194
             return $format;
195 195
         }
196 196
 
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
         $separator = $format[1];
211 211
 
212 212
         // No thousands separator
213
-        if($separator === '0')
213
+        if ($separator === '0')
214 214
         {
215 215
             return $format;
216 216
         }
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
         // Valid thousands separator
219 219
         $validSeparators = array(' ', ',', '.');
220 220
 
221
-        if(in_array($separator, $validSeparators))
221
+        if (in_array($separator, $validSeparators))
222 222
         {
223 223
             $this->thousandsSeparator = $separator;
224 224
             $format = str_replace('1'.$separator, '1', $format);
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
 
255 255
     private function parse_separators(string $format) : string
256 256
     {
257
-        if(!empty($this->thousandsSeparator) && !empty($this->decimalsSeparator) && $this->thousandsSeparator === $this->decimalsSeparator)
257
+        if (!empty($this->thousandsSeparator) && !empty($this->decimalsSeparator) && $this->thousandsSeparator === $this->decimalsSeparator)
258 258
         {
259 259
             $this->makeError(
260 260
                 t(
@@ -270,14 +270,14 @@  discard block
 block discarded – undo
270 270
 
271 271
     private function parse_decimals(string $format) : string
272 272
     {
273
-        if(empty($this->decimalsSeparator))
273
+        if (empty($this->decimalsSeparator))
274 274
         {
275 275
             return $format;
276 276
         }
277 277
 
278 278
         $parts = ConvertHelper::explodeTrim($this->decimalsSeparator, $format);
279 279
 
280
-        if(!isset($parts[1]))
280
+        if (!isset($parts[1]))
281 281
         {
282 282
             $this->makeError(
283 283
                 t('Cannot determine the amount of decimals.').' '.
@@ -293,7 +293,7 @@  discard block
 block discarded – undo
293 293
             return $format;
294 294
         }
295 295
 
296
-        if($this->validateDecimals($parts[1]))
296
+        if ($this->validateDecimals($parts[1]))
297 297
         {
298 298
             $this->decimals = strlen($parts[1]);
299 299
         }
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
 
304 304
     private function validateDecimals(string $decimals) : bool
305 305
     {
306
-        if(preg_match('/\A[0]+\z/x', $decimals)) {
306
+        if (preg_match('/\A[0]+\z/x', $decimals)) {
307 307
             return true;
308 308
         }
309 309
 
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
     {
323 323
         $validSeparators = array('.', ',');
324 324
 
325
-        if(in_array($separator, $validSeparators)) {
325
+        if (in_array($separator, $validSeparators)) {
326 326
             return true;
327 327
         }
328 328
 
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
      */
345 345
     private function parse_regex(string $format) : string
346 346
     {
347
-        if(preg_match('/1[ ,.]?000|1[ ,.]?000[.,][0]+/x', $format))
347
+        if (preg_match('/1[ ,.]?000|1[ ,.]?000[.,][0]+/x', $format))
348 348
         {
349 349
             return $format;
350 350
         }
Please login to merge, or discard this patch.
src/Mailcode/Traits/Commands/IfNumber.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@
 block discarded – undo
50 50
     {
51 51
         $value = $this->getRawNumber();
52 52
 
53
-        if(!is_numeric($value))
53
+        if (!is_numeric($value))
54 54
         {
55 55
             $this->validationResult->makeError(
56 56
                 t(
Please login to merge, or discard this patch.