Passed
Push — master ( caf38d...9bab94 )
by Sebastian
02:11
created
src/Mailcode/Parser/Safeguard.php 3 patches
Indentation   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -55,40 +55,40 @@  discard block
 block discarded – undo
55 55
     
56 56
     const ERROR_EMPTY_DELIMITER = 47803;
57 57
     
58
-   /**
59
-    * @var Mailcode_Parser
60
-    */
58
+    /**
59
+     * @var Mailcode_Parser
60
+     */
61 61
     protected $parser;
62 62
     
63
-   /**
64
-    * @var Mailcode_Collection
65
-    */
63
+    /**
64
+     * @var Mailcode_Collection
65
+     */
66 66
     protected $commands;
67 67
     
68
-   /**
69
-    * @var string
70
-    */
68
+    /**
69
+     * @var string
70
+     */
71 71
     protected $originalString;
72 72
     
73
-   /**
74
-    * @var Mailcode_Collection
75
-    */
73
+    /**
74
+     * @var Mailcode_Collection
75
+     */
76 76
     protected $collection;
77 77
     
78
-   /**
79
-    * Counter for the placeholders, global for all placeholders.
80
-    * @var integer
81
-    */
78
+    /**
79
+     * Counter for the placeholders, global for all placeholders.
80
+     * @var integer
81
+     */
82 82
     private static $counter = 0;
83 83
     
84
-   /**
85
-    * @var Mailcode_Parser_Safeguard_Placeholder[]
86
-    */
84
+    /**
85
+     * @var Mailcode_Parser_Safeguard_Placeholder[]
86
+     */
87 87
     protected $placeholders;
88 88
     
89
-   /**
90
-    * @var string
91
-    */
89
+    /**
90
+     * @var string
91
+     */
92 92
     protected $delimiter = '__';
93 93
     
94 94
     public function __construct(Mailcode_Parser $parser, string $subject)
@@ -97,15 +97,15 @@  discard block
 block discarded – undo
97 97
         $this->originalString = $subject;
98 98
     }
99 99
     
100
-   /**
101
-    * Sets the delimiter character sequence used to prepend
102
-    * and append to the placeholders.
103
-    * 
104
-    * The delimiter's default is "__" (two underscores).
105
-    * 
106
-    * @param string $delimiter
107
-    * @return Mailcode_Parser_Safeguard
108
-    */
100
+    /**
101
+     * Sets the delimiter character sequence used to prepend
102
+     * and append to the placeholders.
103
+     * 
104
+     * The delimiter's default is "__" (two underscores).
105
+     * 
106
+     * @param string $delimiter
107
+     * @return Mailcode_Parser_Safeguard
108
+     */
109 109
     public function setDelimiter(string $delimiter) : Mailcode_Parser_Safeguard
110 110
     {
111 111
         if(empty($delimiter))
@@ -127,15 +127,15 @@  discard block
 block discarded – undo
127 127
         return $this->delimiter;
128 128
     }
129 129
     
130
-   /**
131
-    * Retrieves the safe string in which all commands have been replaced
132
-    * by placeholder strings.
133
-    * 
134
-    * @return string
135
-    * @throws Mailcode_Exception 
136
-    *
137
-    * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS
138
-    */
130
+    /**
131
+     * Retrieves the safe string in which all commands have been replaced
132
+     * by placeholder strings.
133
+     * 
134
+     * @return string
135
+     * @throws Mailcode_Exception 
136
+     *
137
+     * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS
138
+     */
139 139
     public function makeSafe() : string
140 140
     {
141 141
         $this->requireValidCollection();
@@ -171,12 +171,12 @@  discard block
 block discarded – undo
171 171
     }
172 172
     
173 173
     
174
-   /**
175
-    * Retrieves all placeholders that have to be added to
176
-    * the subject text.
177
-    * 
178
-    * @return \Mailcode\Mailcode_Parser_Safeguard_Placeholder[]
179
-    */
174
+    /**
175
+     * Retrieves all placeholders that have to be added to
176
+     * the subject text.
177
+     * 
178
+     * @return \Mailcode\Mailcode_Parser_Safeguard_Placeholder[]
179
+     */
180 180
     public function getPlaceholders()
181 181
     {
182 182
         if(isset($this->placeholders))
@@ -228,46 +228,46 @@  discard block
 block discarded – undo
228 228
         return str_replace($placeholderStrings, array_values($replaces), $string);
229 229
     }
230 230
     
231
-   /**
232
-    * Makes the string whole again after transforming or filtering it,
233
-    * by replacing the command placeholders with the original commands.
234
-    *
235
-    * @param string $string
236
-    * @return string
237
-    * @throws Mailcode_Exception
238
-    *
239
-    * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS
240
-    * @see Mailcode_Parser_Safeguard::ERROR_COMMAND_PLACEHOLDER_MISSING
241
-    */
231
+    /**
232
+     * Makes the string whole again after transforming or filtering it,
233
+     * by replacing the command placeholders with the original commands.
234
+     *
235
+     * @param string $string
236
+     * @return string
237
+     * @throws Mailcode_Exception
238
+     *
239
+     * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS
240
+     * @see Mailcode_Parser_Safeguard::ERROR_COMMAND_PLACEHOLDER_MISSING
241
+     */
242 242
     public function makeWhole(string $string) : string
243 243
     {
244 244
         return $this->restore($string, false);
245 245
     }
246 246
 
247
-   /**
248
-    * Like makeWhole(), but replaces the commands with a syntax
249
-    * highlighted version, meant for human readable texts only.
250
-    * 
251
-    * Note: the commands lose their functionality (They cannot be 
252
-    * parsed from that string again).
253
-    *
254
-    * @param string $string
255
-    * @return string
256
-    * @throws Mailcode_Exception
257
-    *
258
-    * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS
259
-    * @see Mailcode_Parser_Safeguard::ERROR_COMMAND_PLACEHOLDER_MISSING
260
-    */
247
+    /**
248
+     * Like makeWhole(), but replaces the commands with a syntax
249
+     * highlighted version, meant for human readable texts only.
250
+     * 
251
+     * Note: the commands lose their functionality (They cannot be 
252
+     * parsed from that string again).
253
+     *
254
+     * @param string $string
255
+     * @return string
256
+     * @throws Mailcode_Exception
257
+     *
258
+     * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS
259
+     * @see Mailcode_Parser_Safeguard::ERROR_COMMAND_PLACEHOLDER_MISSING
260
+     */
261 261
     public function makeHighlighted(string $string) : string
262 262
     {
263 263
         return $this->restore($string, true);
264 264
     }
265 265
     
266
-   /**
267
-    * Retrieves the commands collection contained in the string.
268
-    * 
269
-    * @return Mailcode_Collection
270
-    */
266
+    /**
267
+     * Retrieves the commands collection contained in the string.
268
+     * 
269
+     * @return Mailcode_Collection
270
+     */
271 271
     public function getCollection() : Mailcode_Collection
272 272
     {
273 273
         if(isset($this->collection))
@@ -285,11 +285,11 @@  discard block
 block discarded – undo
285 285
         return $this->getCollection()->isValid();
286 286
     }
287 287
     
288
-   /**
289
-    * @throws Mailcode_Exception
290
-    * 
291
-    * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS
292
-    */
288
+    /**
289
+     * @throws Mailcode_Exception
290
+     * 
291
+     * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS
292
+     */
293 293
     protected function requireValidCollection() : void
294 294
     {
295 295
         if($this->getCollection()->isValid())
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
     */
109 109
     public function setDelimiter(string $delimiter) : Mailcode_Parser_Safeguard
110 110
     {
111
-        if(empty($delimiter))
111
+        if (empty($delimiter))
112 112
         {
113 113
             throw new Mailcode_Exception(
114 114
                 'Empty delimiter',
@@ -145,17 +145,17 @@  discard block
 block discarded – undo
145 145
         return str_replace(array_values($replaces), array_keys($replaces), $this->originalString);
146 146
     }
147 147
     
148
-    protected function getReplaces(bool $highlighted=false) : array
148
+    protected function getReplaces(bool $highlighted = false) : array
149 149
     {
150 150
         $placeholders = $this->getPlaceholders();
151 151
         
152 152
         $replaces = array();
153 153
         
154
-        foreach($placeholders as $placeholder)
154
+        foreach ($placeholders as $placeholder)
155 155
         {
156 156
             $replace = '';
157 157
             
158
-            if($highlighted)
158
+            if ($highlighted)
159 159
             {
160 160
                 $replace = $placeholder->getHighlightedText();
161 161
             }
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
     */
180 180
     public function getPlaceholders()
181 181
     {
182
-        if(isset($this->placeholders))
182
+        if (isset($this->placeholders))
183 183
         {
184 184
             return $this->placeholders;
185 185
         }
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
         
189 189
         $cmds = $this->getCollection()->getCommands();
190 190
         
191
-        foreach($cmds as $command)
191
+        foreach ($cmds as $command)
192 192
         {
193 193
             self::$counter++;
194 194
             
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
         return $this->placeholders;
203 203
     }
204 204
     
205
-    protected function restore(string $string, bool $highlighted=false) : string
205
+    protected function restore(string $string, bool $highlighted = false) : string
206 206
     {
207 207
         $this->requireValidCollection();
208 208
         
@@ -210,9 +210,9 @@  discard block
 block discarded – undo
210 210
         
211 211
         $placeholderStrings = array_keys($replaces);
212 212
         
213
-        foreach($placeholderStrings as $search)
213
+        foreach ($placeholderStrings as $search)
214 214
         {
215
-            if(!strstr($string, $search))
215
+            if (!strstr($string, $search))
216 216
             {
217 217
                 throw new Mailcode_Exception(
218 218
                     'Command placeholder not found',
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
     */
271 271
     public function getCollection() : Mailcode_Collection
272 272
     {
273
-        if(isset($this->collection))
273
+        if (isset($this->collection))
274 274
         {
275 275
             return $this->collection;
276 276
         }
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
     */
293 293
     protected function requireValidCollection() : void
294 294
     {
295
-        if($this->getCollection()->isValid())
295
+        if ($this->getCollection()->isValid())
296 296
         {
297 297
             return;
298 298
         }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -158,8 +158,7 @@
 block discarded – undo
158 158
             if($highlighted)
159 159
             {
160 160
                 $replace = $placeholder->getHighlightedText();
161
-            }
162
-            else 
161
+            } else 
163 162
             {
164 163
                 $replace = $placeholder->getOriginalText();
165 164
             }
Please login to merge, or discard this patch.