Passed
Push — master ( 8c805d...5e8702 )
by Sebastian
02:45
created
src/Mailcode/Parser/Safeguard/URLAnalyzer.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -56,23 +56,23 @@
 block discarded – undo
56 56
 
57 57
     private function analyzeURL(string $url) : void
58 58
     {
59
-        if(stristr($url, 'tel:'))
59
+        if (stristr($url, 'tel:'))
60 60
         {
61 61
             return;
62 62
         }
63 63
 
64 64
         $placeholders = $this->safeguard->getPlaceholders();
65 65
 
66
-        foreach($placeholders as $placeholder)
66
+        foreach ($placeholders as $placeholder)
67 67
         {
68 68
             $command = $placeholder->getCommand();
69 69
 
70
-            if(!$command->supportsURLEncoding())
70
+            if (!$command->supportsURLEncoding())
71 71
             {
72 72
                 continue;
73 73
             }
74 74
 
75
-            if(strstr($url, $placeholder->getReplacementText()) && !$command->isURLDecoded())
75
+            if (strstr($url, $placeholder->getReplacementText()) && !$command->isURLDecoded())
76 76
             {
77 77
                 $command->setURLEncoding(true);
78 78
             }
Please login to merge, or discard this patch.
src/Mailcode/Parser/Safeguard/DelimiterValidator.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 
46 46
     private function validate() : OperationResult
47 47
     {
48
-        if(empty($this->delimiter))
48
+        if (empty($this->delimiter))
49 49
         {
50 50
             return $this->makeError(
51 51
                 'Delimiters may not be empty.',
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
             );
54 54
         }
55 55
 
56
-        if(strlen($this->delimiter) < 2)
56
+        if (strlen($this->delimiter) < 2)
57 57
         {
58 58
             return $this->makeError(
59 59
                 'The delimiter must have at least 2 characters in length.',
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
             );
62 62
         }
63 63
 
64
-        if(!preg_match('/\A[^0-9*].*[^0-9*]\z/x', $this->delimiter))
64
+        if (!preg_match('/\A[^0-9*].*[^0-9*]\z/x', $this->delimiter))
65 65
         {
66 66
             return $this->makeError(
67 67
                 'The delimiter may not begin or end with a number.',
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
             );
70 70
         }
71 71
 
72
-        if(strstr($this->delimiter, '*') !== false)
72
+        if (strstr($this->delimiter, '*') !== false)
73 73
         {
74 74
             return $this->makeError(
75 75
                 'The delimiter may not contain the * character.',
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 
83 83
     public function throwExceptionIfInvalid() : void
84 84
     {
85
-        if($this->isValid()) {
85
+        if ($this->isValid()) {
86 86
             return;
87 87
         }
88 88
 
Please login to merge, or discard this patch.
src/Mailcode/Parser/Safeguard.php 2 patches
Indentation   +145 added lines, -145 removed lines patch added patch discarded remove patch
@@ -54,45 +54,45 @@  discard block
 block discarded – undo
54 54
     const ERROR_INVALID_COMMANDS = 47801;
55 55
     const ERROR_PLACEHOLDER_NOT_FOUND = 47804;
56 56
 
57
-   /**
58
-    * @var Mailcode_Parser
59
-    */
57
+    /**
58
+     * @var Mailcode_Parser
59
+     */
60 60
     protected $parser;
61 61
     
62
-   /**
63
-    * @var Mailcode_Collection
64
-    */
62
+    /**
63
+     * @var Mailcode_Collection
64
+     */
65 65
     protected $commands;
66 66
     
67
-   /**
68
-    * @var string
69
-    */
67
+    /**
68
+     * @var string
69
+     */
70 70
     protected $originalString;
71 71
     
72
-   /**
73
-    * @var Mailcode_Collection
74
-    */
72
+    /**
73
+     * @var Mailcode_Collection
74
+     */
75 75
     protected $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 $counter = 0;
82 82
     
83
-   /**
84
-    * @var Mailcode_Parser_Safeguard_Placeholder[]
85
-    */
83
+    /**
84
+     * @var Mailcode_Parser_Safeguard_Placeholder[]
85
+     */
86 86
     protected $placeholders;
87 87
     
88
-   /**
89
-    * @var string
90
-    */
88
+    /**
89
+     * @var string
90
+     */
91 91
     protected $delimiter = '__';
92 92
     
93
-   /**
94
-    * @var string[]|NULL
95
-    */
93
+    /**
94
+     * @var string[]|NULL
95
+     */
96 96
     protected $placeholderStrings;
97 97
 
98 98
     public function __construct(Mailcode_Parser $parser, string $subject)
@@ -111,29 +111,29 @@  discard block
 block discarded – undo
111 111
         self::$counter = 0;
112 112
     }
113 113
     
114
-   /**
115
-    * Retrieves the string the safeguard was created for.
116
-    * 
117
-    * @return string
118
-    */
114
+    /**
115
+     * Retrieves the string the safeguard was created for.
116
+     * 
117
+     * @return string
118
+     */
119 119
     public function getOriginalString() : string
120 120
     {
121 121
         return $this->originalString;
122 122
     }
123 123
     
124
-   /**
125
-    * Sets the delimiter character sequence used to prepend
126
-    * and append to the placeholders.
127
-    * 
128
-    * The delimiter's default is "__" (two underscores).
129
-    *
130
-    * Minimum characters: 2
131
-    * Invalid characters: *
132
-    * Rules: May not end or begin with a number
133
-    * 
134
-    * @param string $delimiter
135
-    * @return Mailcode_Parser_Safeguard
136
-    */
124
+    /**
125
+     * Sets the delimiter character sequence used to prepend
126
+     * and append to the placeholders.
127
+     * 
128
+     * The delimiter's default is "__" (two underscores).
129
+     *
130
+     * Minimum characters: 2
131
+     * Invalid characters: *
132
+     * Rules: May not end or begin with a number
133
+     * 
134
+     * @param string $delimiter
135
+     * @return Mailcode_Parser_Safeguard
136
+     */
137 137
     public function setDelimiter(string $delimiter) : Mailcode_Parser_Safeguard
138 138
     {
139 139
         $validator = new Mailcode_Parser_Safeguard_DelimiterValidator($delimiter);
@@ -149,15 +149,15 @@  discard block
 block discarded – undo
149 149
         return $this->delimiter;
150 150
     }
151 151
     
152
-   /**
153
-    * Retrieves the safe string in which all commands have been replaced
154
-    * by placeholder strings.
155
-    *
156
-    * @return string
157
-    * @throws Mailcode_Exception 
158
-    *
159
-    * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS
160
-    */
152
+    /**
153
+     * Retrieves the safe string in which all commands have been replaced
154
+     * by placeholder strings.
155
+     *
156
+     * @return string
157
+     * @throws Mailcode_Exception 
158
+     *
159
+     * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS
160
+     */
161 161
     public function makeSafe() : string
162 162
     {
163 163
         $this->requireValidCollection();
@@ -165,16 +165,16 @@  discard block
 block discarded – undo
165 165
         return $this->makeSafePartial();
166 166
     }
167 167
     
168
-   /**
169
-    * Like makeSafe(), but allows partial (invalid) commands: use this
170
-    * if the subject string may contain only part of the whole set of
171
-    * commands. 
172
-    * 
173
-    * Example: parsing a text with an opening if statement, without the 
174
-    * matching end statement.
175
-    * 
176
-    * @return string
177
-    */
168
+    /**
169
+     * Like makeSafe(), but allows partial (invalid) commands: use this
170
+     * if the subject string may contain only part of the whole set of
171
+     * commands. 
172
+     * 
173
+     * Example: parsing a text with an opening if statement, without the 
174
+     * matching end statement.
175
+     * 
176
+     * @return string
177
+     */
178 178
     public function makeSafePartial() : string
179 179
     {
180 180
         $placeholders = $this->getPlaceholders();
@@ -258,13 +258,13 @@  discard block
 block discarded – undo
258 258
         $analyzer->analyze();
259 259
     }
260 260
     
261
-   /**
262
-    * Creates a formatting handler, which can be used to specify
263
-    * which formattings to use for the commands in the subject string.
264
-    * 
265
-    * @param Mailcode_StringContainer|string $subject
266
-    * @return Mailcode_Parser_Safeguard_Formatting
267
-    */
261
+    /**
262
+     * Creates a formatting handler, which can be used to specify
263
+     * which formattings to use for the commands in the subject string.
264
+     * 
265
+     * @param Mailcode_StringContainer|string $subject
266
+     * @return Mailcode_Parser_Safeguard_Formatting
267
+     */
268 268
     public function createFormatting($subject) : Mailcode_Parser_Safeguard_Formatting
269 269
     {
270 270
         if(is_string($subject))
@@ -275,12 +275,12 @@  discard block
 block discarded – undo
275 275
         return new Mailcode_Parser_Safeguard_Formatting($this, $subject);
276 276
     }
277 277
     
278
-   /**
279
-    * Retrieves all placeholders that have to be added to
280
-    * the subject text.
281
-    * 
282
-    * @return \Mailcode\Mailcode_Parser_Safeguard_Placeholder[]
283
-    */
278
+    /**
279
+     * Retrieves all placeholders that have to be added to
280
+     * the subject text.
281
+     * 
282
+     * @return \Mailcode\Mailcode_Parser_Safeguard_Placeholder[]
283
+     */
284 284
     public function getPlaceholders()
285 285
     {
286 286
         if(isset($this->placeholders))
@@ -356,16 +356,16 @@  discard block
 block discarded – undo
356 356
         return $string;
357 357
     }
358 358
     
359
-   /**
360
-    * Makes the string whole again after transforming or filtering it,
361
-    * by replacing the command placeholders with the original commands.
362
-    *
363
-    * @param string $string
364
-    * @return string
365
-    * @throws Mailcode_Exception
366
-    *
367
-    * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS
368
-    */
359
+    /**
360
+     * Makes the string whole again after transforming or filtering it,
361
+     * by replacing the command placeholders with the original commands.
362
+     *
363
+     * @param string $string
364
+     * @return string
365
+     * @throws Mailcode_Exception
366
+     *
367
+     * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS
368
+     */
369 369
     public function makeWhole(string $string) : string
370 370
     {
371 371
         return $this->restore(
@@ -375,15 +375,15 @@  discard block
 block discarded – undo
375 375
         );
376 376
     }
377 377
     
378
-   /**
379
-    * Like `makeWhole()`, but ignores missing command placeholders.
380
-    *
381
-    * @param string $string
382
-    * @return string
383
-    * @throws Mailcode_Exception
384
-    *
385
-    * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS
386
-    */
378
+    /**
379
+     * Like `makeWhole()`, but ignores missing command placeholders.
380
+     *
381
+     * @param string $string
382
+     * @return string
383
+     * @throws Mailcode_Exception
384
+     *
385
+     * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS
386
+     */
387 387
     public function makeWholePartial(string $string) : string
388 388
     {
389 389
         return $this->restore(
@@ -393,19 +393,19 @@  discard block
 block discarded – undo
393 393
         );
394 394
     }
395 395
 
396
-   /**
397
-    * Like `makeWhole()`, but replaces the commands with a syntax
398
-    * highlighted version, meant for human readable texts only.
399
-    * 
400
-    * Note: the commands lose their functionality (They cannot be 
401
-    * parsed from that string again).
402
-    *
403
-    * @param string $string
404
-    * @return string
405
-    * @throws Mailcode_Exception
406
-    *
407
-    * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS
408
-    */
396
+    /**
397
+     * Like `makeWhole()`, but replaces the commands with a syntax
398
+     * highlighted version, meant for human readable texts only.
399
+     * 
400
+     * Note: the commands lose their functionality (They cannot be 
401
+     * parsed from that string again).
402
+     *
403
+     * @param string $string
404
+     * @return string
405
+     * @throws Mailcode_Exception
406
+     *
407
+     * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS
408
+     */
409 409
     public function makeHighlighted(string $string) : string
410 410
     {
411 411
         return $this->restore(
@@ -415,15 +415,15 @@  discard block
 block discarded – undo
415 415
         );
416 416
     }
417 417
     
418
-   /**
419
-    * Like `makeHighlighted()`, but ignores missing command placeholders.
420
-    * 
421
-    * @param string $string
422
-    * @return string
423
-    * @throws Mailcode_Exception
424
-    *
425
-    * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS
426
-    */
418
+    /**
419
+     * Like `makeHighlighted()`, but ignores missing command placeholders.
420
+     * 
421
+     * @param string $string
422
+     * @return string
423
+     * @throws Mailcode_Exception
424
+     *
425
+     * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS
426
+     */
427 427
     public function makeHighlightedPartial(string $string) : string
428 428
     {
429 429
         return $this->restore(
@@ -433,11 +433,11 @@  discard block
 block discarded – undo
433 433
         );
434 434
     }
435 435
     
436
-   /**
437
-    * Retrieves the commands collection contained in the string.
438
-    * 
439
-    * @return Mailcode_Collection
440
-    */
436
+    /**
437
+     * Retrieves the commands collection contained in the string.
438
+     * 
439
+     * @return Mailcode_Collection
440
+     */
441 441
     public function getCollection() : Mailcode_Collection
442 442
     {
443 443
         if(isset($this->collection))
@@ -455,11 +455,11 @@  discard block
 block discarded – undo
455 455
         return $this->getCollection()->isValid();
456 456
     }
457 457
     
458
-   /**
459
-    * @throws Mailcode_Exception
460
-    * 
461
-    * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS
462
-    */
458
+    /**
459
+     * @throws Mailcode_Exception
460
+     * 
461
+     * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS
462
+     */
463 463
     protected function requireValidCollection() : void
464 464
     {
465 465
         if($this->getCollection()->isValid())
@@ -478,11 +478,11 @@  discard block
 block discarded – undo
478 478
         );
479 479
     }
480 480
     
481
-   /**
482
-    * Retrieves a list of all placeholder IDs used in the text.
483
-    * 
484
-    * @return string[]
485
-    */
481
+    /**
482
+     * Retrieves a list of all placeholder IDs used in the text.
483
+     * 
484
+     * @return string[]
485
+     */
486 486
     public function getPlaceholderStrings() : array
487 487
     {
488 488
         if(is_array($this->placeholderStrings))
@@ -509,13 +509,13 @@  discard block
 block discarded – undo
509 509
         return in_array($subject, $ids);
510 510
     }
511 511
     
512
-   /**
513
-    * Retrieves a placeholder instance by its ID.
514
-    * 
515
-    * @param int $id
516
-    * @throws Mailcode_Exception If the placeholder was not found.
517
-    * @return Mailcode_Parser_Safeguard_Placeholder
518
-    */
512
+    /**
513
+     * Retrieves a placeholder instance by its ID.
514
+     * 
515
+     * @param int $id
516
+     * @throws Mailcode_Exception If the placeholder was not found.
517
+     * @return Mailcode_Parser_Safeguard_Placeholder
518
+     */
519 519
     public function getPlaceholderByID(int $id) : Mailcode_Parser_Safeguard_Placeholder
520 520
     {
521 521
         $placeholders = $this->getPlaceholders();
@@ -538,13 +538,13 @@  discard block
 block discarded – undo
538 538
         );
539 539
     }
540 540
     
541
-   /**
542
-    * Retrieves a placeholder instance by its replacement text.
543
-    * 
544
-    * @param string $string
545
-    * @throws Mailcode_Exception
546
-    * @return Mailcode_Parser_Safeguard_Placeholder
547
-    */
541
+    /**
542
+     * Retrieves a placeholder instance by its replacement text.
543
+     * 
544
+     * @param string $string
545
+     * @throws Mailcode_Exception
546
+     * @return Mailcode_Parser_Safeguard_Placeholder
547
+     */
548 548
     public function getPlaceholderByString(string $string) : Mailcode_Parser_Safeguard_Placeholder
549 549
     {
550 550
         $placeholders = $this->getPlaceholders();
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
         $placeholders = $this->getPlaceholders();
181 181
         $string = $this->originalString;
182 182
         
183
-        foreach($placeholders as $placeholder)
183
+        foreach ($placeholders as $placeholder)
184 184
         {
185 185
             $string = $this->makePlaceholderSafe($string, $placeholder);
186 186
         }
@@ -210,14 +210,14 @@  discard block
 block discarded – undo
210 210
         $placeholders = $this->getPlaceholders();
211 211
         $total = count($placeholders);
212 212
 
213
-        for($i=0; $i < $total; $i++)
213
+        for ($i = 0; $i < $total; $i++)
214 214
         {
215 215
             $placeholder = $placeholders[$i];
216 216
             $command = $placeholder->getCommand();
217 217
 
218
-            if($command instanceof Mailcode_Interfaces_Commands_ProtectedContent)
218
+            if ($command instanceof Mailcode_Interfaces_Commands_ProtectedContent)
219 219
             {
220
-                $string = $command->protectContent($string, $placeholder, $placeholders[$i+1]);
220
+                $string = $command->protectContent($string, $placeholder, $placeholders[$i + 1]);
221 221
             }
222 222
         }
223 223
 
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
     {
229 229
         $pos = mb_strpos($string, $placeholder->getOriginalText());
230 230
 
231
-        if($pos === false)
231
+        if ($pos === false)
232 232
         {
233 233
             throw new Mailcode_Exception(
234 234
                 'Placeholder original text not found',
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
     */
268 268
     public function createFormatting($subject) : Mailcode_Parser_Safeguard_Formatting
269 269
     {
270
-        if(is_string($subject))
270
+        if (is_string($subject))
271 271
         {
272 272
             $subject = Mailcode::create()->createString($subject);
273 273
         }
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
     */
284 284
     public function getPlaceholders()
285 285
     {
286
-        if(isset($this->placeholders))
286
+        if (isset($this->placeholders))
287 287
         {
288 288
             return $this->placeholders;
289 289
         }
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
         
293 293
         $cmds = $this->getCollection()->getCommands();
294 294
         
295
-        foreach($cmds as $command)
295
+        foreach ($cmds as $command)
296 296
         {
297 297
             self::$counter++;
298 298
             
@@ -313,21 +313,21 @@  discard block
 block discarded – undo
313 313
      * @return string
314 314
      * @throws Mailcode_Exception
315 315
      */
316
-    protected function restore(string $string, bool $partial=false, bool $highlighted=false) : string
316
+    protected function restore(string $string, bool $partial = false, bool $highlighted = false) : string
317 317
     {
318
-        if(!$partial)
318
+        if (!$partial)
319 319
         {
320 320
             $this->requireValidCollection();
321 321
         }
322 322
         
323 323
         $formatting = $this->createFormatting($string);
324 324
 
325
-        if($partial)
325
+        if ($partial)
326 326
         {
327 327
             $formatting->makePartial();
328 328
         }
329 329
         
330
-        if($highlighted)
330
+        if ($highlighted)
331 331
         {
332 332
             $formatting->replaceWithHTMLHighlighting();
333 333
         }
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
         {
348 348
             $command = $placeholder->getCommand();
349 349
 
350
-            if($command instanceof Mailcode_Interfaces_Commands_ProtectedContent)
350
+            if ($command instanceof Mailcode_Interfaces_Commands_ProtectedContent)
351 351
             {
352 352
                 $string = $command->restoreContent($string);
353 353
             }
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
     */
441 441
     public function getCollection() : Mailcode_Collection
442 442
     {
443
-        if(isset($this->collection))
443
+        if (isset($this->collection))
444 444
         {
445 445
             return $this->collection;
446 446
         }
@@ -462,7 +462,7 @@  discard block
 block discarded – undo
462 462
     */
463 463
     protected function requireValidCollection() : void
464 464
     {
465
-        if($this->getCollection()->isValid())
465
+        if ($this->getCollection()->isValid())
466 466
         {
467 467
             return;
468 468
         }
@@ -485,7 +485,7 @@  discard block
 block discarded – undo
485 485
     */
486 486
     public function getPlaceholderStrings() : array
487 487
     {
488
-        if(is_array($this->placeholderStrings))
488
+        if (is_array($this->placeholderStrings))
489 489
         {
490 490
             return $this->placeholderStrings;
491 491
         }
@@ -494,7 +494,7 @@  discard block
 block discarded – undo
494 494
         
495 495
         $this->placeholderStrings = array();
496 496
         
497
-        foreach($placeholders as $placeholder)
497
+        foreach ($placeholders as $placeholder)
498 498
         {
499 499
             $this->placeholderStrings[] = $placeholder->getReplacementText();
500 500
         }
@@ -520,9 +520,9 @@  discard block
 block discarded – undo
520 520
     {
521 521
         $placeholders = $this->getPlaceholders();
522 522
         
523
-        foreach($placeholders as $placeholder)
523
+        foreach ($placeholders as $placeholder)
524 524
         {
525
-            if($placeholder->getID() === $id)
525
+            if ($placeholder->getID() === $id)
526 526
             {
527 527
                 return $placeholder;
528 528
             }
@@ -549,9 +549,9 @@  discard block
 block discarded – undo
549 549
     {
550 550
         $placeholders = $this->getPlaceholders();
551 551
         
552
-        foreach($placeholders as $placeholder)
552
+        foreach ($placeholders as $placeholder)
553 553
         {
554
-            if($placeholder->getReplacementText() === $string)
554
+            if ($placeholder->getReplacementText() === $string)
555 555
             {
556 556
                 return $placeholder;
557 557
             }
Please login to merge, or discard this patch.