Passed
Push — master ( cd2614...13a961 )
by Sebastian
03:27
created
src/Mailcode/Traits/Formatting/HTMLHighlighting.php 2 patches
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -23,21 +23,21 @@  discard block
 block discarded – undo
23 23
  */
24 24
 trait Mailcode_Traits_Formatting_HTMLHighlighting
25 25
 {
26
-   /**
27
-    * @var string[]
28
-    */
26
+    /**
27
+     * @var string[]
28
+     */
29 29
     private $excludeTags = array(
30 30
         'style', // NOTE: style tags are excluded natively on the parser level.
31 31
         'script'
32 32
     );
33 33
     
34
-   /**
35
-    * Adds an HTML tag name to the list of tags within which
36
-    * commands may not be highlighted.
37
-    *
38
-    * @param string $tagName Case insensitive.
39
-    * @return $this
40
-    */
34
+    /**
35
+     * Adds an HTML tag name to the list of tags within which
36
+     * commands may not be highlighted.
37
+     *
38
+     * @param string $tagName Case insensitive.
39
+     * @return $this
40
+     */
41 41
     public function excludeTag(string $tagName)
42 42
     {
43 43
         $tagName = strtolower($tagName);
@@ -50,12 +50,12 @@  discard block
 block discarded – undo
50 50
         return $this;
51 51
     }
52 52
     
53
-   /**
54
-    * Adds several exluded tag names at once.
55
-    *
56
-    * @param string[] $tagNames
57
-    * @return $this
58
-    */
53
+    /**
54
+     * Adds several exluded tag names at once.
55
+     *
56
+     * @param string[] $tagNames
57
+     * @return $this
58
+     */
59 59
     public function excludeTags(array $tagNames)
60 60
     {
61 61
         foreach($tagNames as $tagName)
@@ -66,12 +66,12 @@  discard block
 block discarded – undo
66 66
         return $this;
67 67
     }
68 68
     
69
-   /**
70
-    * Whether the specified tag name is in the exlusion list.
71
-    *
72
-    * @param string $tagName
73
-    * @return bool
74
-    */
69
+    /**
70
+     * Whether the specified tag name is in the exlusion list.
71
+     *
72
+     * @param string $tagName
73
+     * @return bool
74
+     */
75 75
     public function isTagExcluded(string $tagName) : bool
76 76
     {
77 77
         $tagName = strtolower($tagName);
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
     {
43 43
         $tagName = strtolower($tagName);
44 44
         
45
-        if(!in_array($tagName, $this->excludeTags))
45
+        if (!in_array($tagName, $this->excludeTags))
46 46
         {
47 47
             $this->excludeTags[] = $tagName;
48 48
         }
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
     */
59 59
     public function excludeTags(array $tagNames)
60 60
     {
61
-        foreach($tagNames as $tagName)
61
+        foreach ($tagNames as $tagName)
62 62
         {
63 63
             $this->excludeTag((string)$tagName);
64 64
         }
Please login to merge, or discard this patch.
src/Mailcode/Parser/Safeguard/Formatter/Type/HTMLHighlighting/Location.php 2 patches
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -24,14 +24,14 @@  discard block
 block discarded – undo
24 24
 {
25 25
     const COMMAND_MARKER = '__MAILCODE_COMMAND__';
26 26
     
27
-   /**
28
-    * @var boolean
29
-    */
27
+    /**
28
+     * @var boolean
29
+     */
30 30
     private $ancestryChecked = false;
31 31
     
32
-   /**
33
-    * @var array<int,array<int,string>>
34
-    */
32
+    /**
33
+     * @var array<int,array<int,string>>
34
+     */
35 35
     private $tagAncestry = array();
36 36
     
37 37
     protected function init() : void
@@ -43,12 +43,12 @@  discard block
 block discarded – undo
43 43
         return !$this->isInTagAttributes() && !$this->isInExcludedTag();
44 44
     }
45 45
     
46
-   /**
47
-    * Retrieves the part of the subject string that comes
48
-    * before the command.
49
-    * 
50
-    * @return string
51
-    */
46
+    /**
47
+     * Retrieves the part of the subject string that comes
48
+     * before the command.
49
+     * 
50
+     * @return string
51
+     */
52 52
     private function getHaystackBefore() : string
53 53
     {
54 54
         $pos = $this->getStartPosition();
@@ -65,12 +65,12 @@  discard block
 block discarded – undo
65 65
         return $this->subject->getSubstr(0, $pos).self::COMMAND_MARKER.'>';
66 66
     }
67 67
     
68
-   /**
69
-    * Whether the command is nested in one of the tags
70
-    * that have been added to the list of excluded tags.
71
-    * 
72
-    * @return bool
73
-    */
68
+    /**
69
+     * Whether the command is nested in one of the tags
70
+     * that have been added to the list of excluded tags.
71
+     * 
72
+     * @return bool
73
+     */
74 74
     protected function isInExcludedTag() : bool
75 75
     {
76 76
         $tagNames = $this->getParentTags();
@@ -86,12 +86,12 @@  discard block
 block discarded – undo
86 86
         return false;
87 87
     }
88 88
     
89
-   /**
90
-    * Retrieves a list of the command's parent HTML tags, from
91
-    * highest to lowest.
92
-    * 
93
-    * @return string[]
94
-    */
89
+    /**
90
+     * Retrieves a list of the command's parent HTML tags, from
91
+     * highest to lowest.
92
+     * 
93
+     * @return string[]
94
+     */
95 95
     private function getParentTags() : array
96 96
     {
97 97
         $tags = $this->getTagAncestry();
@@ -116,12 +116,12 @@  discard block
 block discarded – undo
116 116
         return $stack;
117 117
     }
118 118
     
119
-   /**
120
-    * Checks whether the command is located within the attributes
121
-    * of an HTML tag.
122
-    * 
123
-    * @return bool
124
-    */
119
+    /**
120
+     * Checks whether the command is located within the attributes
121
+     * of an HTML tag.
122
+     * 
123
+     * @return bool
124
+     */
125 125
     protected function isInTagAttributes() : bool
126 126
     {
127 127
         $tags = $this->getTagAncestry();
@@ -139,12 +139,12 @@  discard block
 block discarded – undo
139 139
         return false;
140 140
     }
141 141
     
142
-   /**
143
-    * Retrieves a list of tag names that come as parents 
144
-    * above the command.
145
-    * 
146
-    * @return array<int,array<int,string>>
147
-    */
142
+    /**
143
+     * Retrieves a list of tag names that come as parents 
144
+     * above the command.
145
+     * 
146
+     * @return array<int,array<int,string>>
147
+     */
148 148
     private function getTagAncestry() : array
149 149
     {
150 150
         if($this->ancestryChecked)
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
     {
54 54
         $pos = $this->getStartPosition();
55 55
         
56
-        if(is_bool($pos))
56
+        if (is_bool($pos))
57 57
         {
58 58
             return '';
59 59
         }
@@ -75,9 +75,9 @@  discard block
 block discarded – undo
75 75
     {
76 76
         $tagNames = $this->getParentTags();
77 77
         
78
-        foreach($tagNames as $tagName)
78
+        foreach ($tagNames as $tagName)
79 79
         {
80
-            if($this->formatter->isTagExcluded($tagName))
80
+            if ($this->formatter->isTagExcluded($tagName))
81 81
             {
82 82
                 return true;
83 83
             }
@@ -99,11 +99,11 @@  discard block
 block discarded – undo
99 99
         // Create a stack of all direct parent tags of the command.
100 100
         // Handles closing tags as well.
101 101
         $stack = array();
102
-        foreach($tags[2] as $idx => $tagName)
102
+        foreach ($tags[2] as $idx => $tagName)
103 103
         {
104 104
             $closing = $tags[1][$idx] === '/';
105 105
             
106
-            if($closing)
106
+            if ($closing)
107 107
             {
108 108
                 array_pop($stack);
109 109
             }
@@ -128,9 +128,9 @@  discard block
 block discarded – undo
128 128
         
129 129
         // This check is easy: if the command is in the attribute
130 130
         // of any of the tags, we will find the command marker in there.
131
-        foreach($tags[3] as $attributes)
131
+        foreach ($tags[3] as $attributes)
132 132
         {
133
-            if(strstr($attributes, self::COMMAND_MARKER))
133
+            if (strstr($attributes, self::COMMAND_MARKER))
134 134
             {
135 135
                 return true;
136 136
             }
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
     */
148 148
     private function getTagAncestry() : array
149 149
     {
150
-        if($this->ancestryChecked)
150
+        if ($this->ancestryChecked)
151 151
         {
152 152
             return $this->tagAncestry;
153 153
         }
Please login to merge, or discard this patch.
src/Mailcode/Parser/Safeguard/Formatter/Location.php 1 patch
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.
src/Mailcode/Parser/Safeguard/Formatting.php 1 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
     const ERROR_TOO_MANY_REPLACERS = 65902;
33 33
     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);
@@ -273,26 +273,26 @@  discard block
 block discarded – undo
273 273
         return $this->subject->getString();
274 274
     }
275 275
 
276
-   /**
277
-    * Whether the formatting is done partially: missing placeholders
278
-    * will simply be ignored.
279
-    * 
280
-    * @return bool
281
-    */
276
+    /**
277
+     * Whether the formatting is done partially: missing placeholders
278
+     * will simply be ignored.
279
+     * 
280
+     * @return bool
281
+     */
282 282
     public function isPartial() : bool
283 283
     {
284 284
         return $this->partial;
285 285
     }
286 286
     
287
-   /**
288
-    * The formatting will ignore missing placeholders. Use this if the
289
-    * formatting will be done on a text that may not contain all of the
290
-    * initial placeholders anymore.
291
-    * 
292
-    * This is like the safeguard's makeWholePartial() method.
293
-    * 
294
-    * @return Mailcode_Parser_Safeguard_Formatting
295
-    */
287
+    /**
288
+     * The formatting will ignore missing placeholders. Use this if the
289
+     * formatting will be done on a text that may not contain all of the
290
+     * initial placeholders anymore.
291
+     * 
292
+     * This is like the safeguard's makeWholePartial() method.
293
+     * 
294
+     * @return Mailcode_Parser_Safeguard_Formatting
295
+     */
296 296
     public function makePartial() : Mailcode_Parser_Safeguard_Formatting
297 297
     {
298 298
         $this->partial = true;
Please login to merge, or discard this patch.
src/Mailcode/Parser/Safeguard.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
     */
127 127
     public function setDelimiter(string $delimiter) : Mailcode_Parser_Safeguard
128 128
     {
129
-        if(empty($delimiter))
129
+        if (empty($delimiter))
130 130
         {
131 131
             throw new Mailcode_Exception(
132 132
                 'Empty delimiter',
@@ -176,11 +176,11 @@  discard block
 block discarded – undo
176 176
         $placeholders = $this->getPlaceholders();
177 177
         $string = $this->originalString;
178 178
         
179
-        foreach($placeholders as $placeholder)
179
+        foreach ($placeholders as $placeholder)
180 180
         {
181 181
             $pos = mb_strpos($string, $placeholder->getOriginalText());
182 182
             
183
-            if($pos === false)
183
+            if ($pos === false)
184 184
             {
185 185
                 throw new Mailcode_Exception(
186 186
                     'Placeholder original text not found',
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
     */
210 210
     public function createFormatting($subject) : Mailcode_Parser_Safeguard_Formatting
211 211
     {
212
-        if(is_string($subject))
212
+        if (is_string($subject))
213 213
         {
214 214
             $subject = Mailcode::create()->createString($subject);
215 215
         }
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
     */
226 226
     public function getPlaceholders()
227 227
     {
228
-        if(isset($this->placeholders))
228
+        if (isset($this->placeholders))
229 229
         {
230 230
             return $this->placeholders;
231 231
         }
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
         
235 235
         $cmds = $this->getCollection()->getCommands();
236 236
         
237
-        foreach($cmds as $command)
237
+        foreach ($cmds as $command)
238 238
         {
239 239
             self::$counter++;
240 240
             
@@ -248,21 +248,21 @@  discard block
 block discarded – undo
248 248
         return $this->placeholders;
249 249
     }
250 250
     
251
-    protected function restore(string $string, bool $partial=false, bool $highlighted=false) : string
251
+    protected function restore(string $string, bool $partial = false, bool $highlighted = false) : string
252 252
     {
253
-        if(!$partial)
253
+        if (!$partial)
254 254
         {
255 255
             $this->requireValidCollection();
256 256
         }
257 257
         
258 258
         $formatting = $this->createFormatting($string);
259 259
 
260
-        if($partial)
260
+        if ($partial)
261 261
         {
262 262
             $formatting->makePartial();
263 263
         }
264 264
         
265
-        if($highlighted)
265
+        if ($highlighted)
266 266
         {
267 267
             $formatting->replaceWithHTMLHighlighting();
268 268
         }
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
     */
359 359
     public function getCollection() : Mailcode_Collection
360 360
     {
361
-        if(isset($this->collection))
361
+        if (isset($this->collection))
362 362
         {
363 363
             return $this->collection;
364 364
         }
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
     */
381 381
     protected function requireValidCollection() : void
382 382
     {
383
-        if($this->getCollection()->isValid())
383
+        if ($this->getCollection()->isValid())
384 384
         {
385 385
             return;
386 386
         }
@@ -403,7 +403,7 @@  discard block
 block discarded – undo
403 403
     */
404 404
     public function getPlaceholderStrings() : array
405 405
     {
406
-        if(is_array($this->placeholderStrings))
406
+        if (is_array($this->placeholderStrings))
407 407
         {
408 408
             return $this->placeholderStrings;
409 409
         }
@@ -412,7 +412,7 @@  discard block
 block discarded – undo
412 412
         
413 413
         $this->placeholderStrings = array();
414 414
         
415
-        foreach($placeholders as $placeholder)
415
+        foreach ($placeholders as $placeholder)
416 416
         {
417 417
             $this->placeholderStrings[] = $placeholder->getReplacementText();
418 418
         }
@@ -438,9 +438,9 @@  discard block
 block discarded – undo
438 438
     {
439 439
         $placeholders = $this->getPlaceholders();
440 440
         
441
-        foreach($placeholders as $placeholder)
441
+        foreach ($placeholders as $placeholder)
442 442
         {
443
-            if($placeholder->getID() === $id)
443
+            if ($placeholder->getID() === $id)
444 444
             {
445 445
                 return $placeholder;
446 446
             }
@@ -467,9 +467,9 @@  discard block
 block discarded – undo
467 467
     {
468 468
         $placeholders = $this->getPlaceholders();
469 469
         
470
-        foreach($placeholders as $placeholder)
470
+        foreach ($placeholders as $placeholder)
471 471
         {
472
-            if($placeholder->getReplacementText() === $string)
472
+            if ($placeholder->getReplacementText() === $string)
473 473
             {
474 474
                 return $placeholder;
475 475
             }
Please login to merge, or discard this patch.