Passed
Push — master ( f87868...1b5df6 )
by Sebastian
02:44
created
src/Mailcode.php 2 patches
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -26,51 +26,51 @@  discard block
 block discarded – undo
26 26
  */
27 27
 class Mailcode
28 28
 {
29
-   /**
30
-    * @var Mailcode_Parser|NULL
31
-    */
29
+    /**
30
+     * @var Mailcode_Parser|NULL
31
+     */
32 32
     protected $parser = null;
33 33
     
34
-   /**
35
-    * @var Mailcode_Commands|NULL
36
-    */
34
+    /**
35
+     * @var Mailcode_Commands|NULL
36
+     */
37 37
     protected $commands = null;
38 38
     
39
-   /**
40
-    * @var Mailcode_Variables|NULL
41
-    */
39
+    /**
40
+     * @var Mailcode_Variables|NULL
41
+     */
42 42
     protected $variables = null;
43 43
     
44
-   /**
45
-    * @var Mailcode_Translator|NULL
46
-    */
44
+    /**
45
+     * @var Mailcode_Translator|NULL
46
+     */
47 47
     protected $translator = null;
48 48
     
49
-   /**
50
-    * Creates a new mailcode instance.
51
-    * @return Mailcode
52
-    */
49
+    /**
50
+     * Creates a new mailcode instance.
51
+     * @return Mailcode
52
+     */
53 53
     public static function create() : Mailcode
54 54
     {
55 55
         return new Mailcode();
56 56
     }
57 57
     
58
-   /**
59
-    * Parses the string to detect all commands contained within.
60
-    * 
61
-    * @param string $string
62
-    * @return Mailcode_Collection
63
-    */
58
+    /**
59
+     * Parses the string to detect all commands contained within.
60
+     * 
61
+     * @param string $string
62
+     * @return Mailcode_Collection
63
+     */
64 64
     public function parseString(string $string) : Mailcode_Collection
65 65
     {
66 66
         return $this->getParser()->parseString($string);
67 67
     }
68 68
     
69
-   /**
70
-    * Retrieves the string parser instance used to detect commands.
71
-    * 
72
-    * @return Mailcode_Parser
73
-    */
69
+    /**
70
+     * Retrieves the string parser instance used to detect commands.
71
+     * 
72
+     * @return Mailcode_Parser
73
+     */
74 74
     public function getParser() : Mailcode_Parser
75 75
     {
76 76
         if(!isset($this->parser)) 
@@ -81,12 +81,12 @@  discard block
 block discarded – undo
81 81
         return $this->parser;
82 82
     }
83 83
     
84
-   /**
85
-    * Retrieves the commands collection, which is used to
86
-    * access information on the available commands.
87
-    * 
88
-    * @return Mailcode_Commands
89
-    */
84
+    /**
85
+     * Retrieves the commands collection, which is used to
86
+     * access information on the available commands.
87
+     * 
88
+     * @return Mailcode_Commands
89
+     */
90 90
     public function getCommands() : Mailcode_Commands
91 91
     {
92 92
         if(!isset($this->commands)) 
@@ -102,12 +102,12 @@  discard block
 block discarded – undo
102 102
         return $this->getParser()->createSafeguard($subject);
103 103
     }
104 104
     
105
-   /**
106
-    * Attempts to find all variables in the target string.
107
-    * 
108
-    * @param string $subject
109
-    * @return Mailcode_Variables_Collection_Regular
110
-    */
105
+    /**
106
+     * Attempts to find all variables in the target string.
107
+     * 
108
+     * @param string $subject
109
+     * @return Mailcode_Variables_Collection_Regular
110
+     */
111 111
     public function findVariables(string $subject) : Mailcode_Variables_Collection_Regular
112 112
     {
113 113
         return $this->createVariables()->parseString($subject);
@@ -123,12 +123,12 @@  discard block
 block discarded – undo
123 123
         return $this->variables;
124 124
     }
125 125
     
126
-   /**
127
-    * Creates the translator, which can be used to convert commands
128
-    * to another supported syntax.
129
-    * 
130
-    * @return Mailcode_Translator
131
-    */
126
+    /**
127
+     * Creates the translator, which can be used to convert commands
128
+     * to another supported syntax.
129
+     * 
130
+     * @return Mailcode_Translator
131
+     */
132 132
     public function createTranslator() : Mailcode_Translator
133 133
     {
134 134
         if(!isset($this->translator))
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
     */
74 74
     public function getParser() : Mailcode_Parser
75 75
     {
76
-        if(!isset($this->parser)) 
76
+        if (!isset($this->parser)) 
77 77
         {
78 78
             $this->parser = new Mailcode_Parser($this);
79 79
         }
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
     */
90 90
     public function getCommands() : Mailcode_Commands
91 91
     {
92
-        if(!isset($this->commands)) 
92
+        if (!isset($this->commands)) 
93 93
         {
94 94
             $this->commands = new Mailcode_Commands();
95 95
         }
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
     
116 116
     public function createVariables() : Mailcode_Variables
117 117
     {
118
-        if(!isset($this->variables))
118
+        if (!isset($this->variables))
119 119
         {
120 120
             $this->variables = new Mailcode_Variables();
121 121
         }
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
     */
132 132
     public function createTranslator() : Mailcode_Translator
133 133
     {
134
-        if(!isset($this->translator))
134
+        if (!isset($this->translator))
135 135
         {
136 136
             $this->translator = new Mailcode_Translator(); 
137 137
         }
Please login to merge, or discard this patch.
src/Mailcode/Parser/Statement.php 2 patches
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -29,24 +29,24 @@  discard block
 block discarded – undo
29 29
     
30 30
     const VALIDATION_UNQUOTED_STRING_LITERALS = 48802;
31 31
     
32
-   /**
33
-    * @var string
34
-    */
32
+    /**
33
+     * @var string
34
+     */
35 35
     protected $statement;
36 36
     
37
-   /**
38
-    * @var OperationResult
39
-    */
37
+    /**
38
+     * @var OperationResult
39
+     */
40 40
     protected $result;
41 41
     
42
-   /**
43
-    * @var Mailcode_Parser_Statement_Tokenizer|NULL
44
-    */
42
+    /**
43
+     * @var Mailcode_Parser_Statement_Tokenizer|NULL
44
+     */
45 45
     protected $tokenizer;
46 46
     
47
-   /**
48
-    * @var Mailcode_Parser_Statement_Info|NULL
49
-    */
47
+    /**
48
+     * @var Mailcode_Parser_Statement_Info|NULL
49
+     */
50 50
     protected $info;
51 51
     
52 52
     public function __construct(string $statement)
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
         if($unknown)
103 103
         {
104 104
             $this->result->makeError(
105
-               t('Unquoted string literal found:').' ('.htmlspecialchars($unknown->getMatchedText()).')',
105
+                t('Unquoted string literal found:').' ('.htmlspecialchars($unknown->getMatchedText()).')',
106 106
                 self::VALIDATION_UNQUOTED_STRING_LITERALS
107 107
             );
108 108
         }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
     
76 76
     public function getInfo() : Mailcode_Parser_Statement_Info
77 77
     {
78
-        if(isset($this->info))
78
+        if (isset($this->info))
79 79
         {
80 80
             return $this->info; 
81 81
         }
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
     
88 88
     protected function validate() : void
89 89
     {
90
-        if(!$this->tokenizer->hasTokens())
90
+        if (!$this->tokenizer->hasTokens())
91 91
         {
92 92
             $this->result->makeError(
93 93
                 t('Empty statement'),
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
         
100 100
         $unknown = $this->tokenizer->getFirstUnknown();
101 101
         
102
-        if($unknown)
102
+        if ($unknown)
103 103
         {
104 104
             $this->result->makeError(
105 105
                t('Unquoted string literal found:').' ('.htmlspecialchars($unknown->getMatchedText()).')',
Please login to merge, or discard this patch.
src/Mailcode/Commands/Command/Comment.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@
 block discarded – undo
25 25
         $this->paramsString = trim($this->paramsString);
26 26
         
27 27
         // automatically quote the parameters, since comments don't require any.
28
-        if(substr($this->paramsString, 0, 1) != '"')
28
+        if (substr($this->paramsString, 0, 1) != '"')
29 29
         {
30 30
             $this->paramsString = '"'.$this->paramsString.'"';
31 31
         }
Please login to merge, or discard this patch.
src/Mailcode/Commands/Command/ShowSnippet.php 2 patches
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -24,9 +24,9 @@  discard block
 block discarded – undo
24 24
     
25 25
     const VALIDATION_VARIABLE_COUNT_MISMATCH = 52001;
26 26
     
27
-   /**
28
-    * @var Mailcode_Variables_Variable|NULL
29
-    */
27
+    /**
28
+     * @var Mailcode_Variables_Variable|NULL
29
+     */
30 30
     protected $variable;
31 31
     
32 32
     public function getName() : string
@@ -49,15 +49,15 @@  discard block
 block discarded – undo
49 49
         return true;
50 50
     }
51 51
     
52
-   /**
53
-    * Retrieves the variable to show.
54
-    * 
55
-    * NOTE: Only available once the command has been
56
-    * validated. Always use isValid() first.
57
-    * 
58
-    * @throws Mailcode_Exception
59
-    * @return Mailcode_Variables_Variable
60
-    */
52
+    /**
53
+     * Retrieves the variable to show.
54
+     * 
55
+     * NOTE: Only available once the command has been
56
+     * validated. Always use isValid() first.
57
+     * 
58
+     * @throws Mailcode_Exception
59
+     * @return Mailcode_Variables_Variable
60
+     */
61 61
     public function getVariable() : Mailcode_Variables_Variable
62 62
     {
63 63
         $this->validate();
@@ -74,15 +74,15 @@  discard block
 block discarded – undo
74 74
         );
75 75
     }
76 76
     
77
-   /**
78
-    * Retrieves the full name of the variable to show.
79
-    * 
80
-    * NOTE: Only available once the command has been
81
-    * validated. Always use isValid() first.
82
-    * 
83
-    * @throws Mailcode_Exception
84
-    * @return string
85
-    */
77
+    /**
78
+     * Retrieves the full name of the variable to show.
79
+     * 
80
+     * NOTE: Only available once the command has been
81
+     * validated. Always use isValid() first.
82
+     * 
83
+     * @throws Mailcode_Exception
84
+     * @return string
85
+     */
86 86
     public function getVariableName() : string
87 87
     {
88 88
         return $this->getVariable()->getFullName();
@@ -90,19 +90,19 @@  discard block
 block discarded – undo
90 90
 
91 91
     protected function validateSyntax_require_variable() : void
92 92
     {
93
-         $vars = $this->getVariables()->getGroupedByName();
94
-         $amount = count($vars);
93
+            $vars = $this->getVariables()->getGroupedByName();
94
+            $amount = count($vars);
95 95
          
96
-         if($amount === 1)
97
-         {
98
-             $this->variable = array_pop($vars);
99
-             return;
100
-         }
96
+            if($amount === 1)
97
+            {
98
+                $this->variable = array_pop($vars);
99
+                return;
100
+            }
101 101
          
102
-         $this->validationResult->makeError(
102
+            $this->validationResult->makeError(
103 103
             t('Command has %1$s variables, %2$s expected.', $amount, 1),
104 104
             self::VALIDATION_VARIABLE_COUNT_MISMATCH
105
-         );
105
+            );
106 106
     }
107 107
     
108 108
     protected function getValidations() : array
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
     {
63 63
         $this->validate();
64 64
         
65
-        if(isset($this->variable))
65
+        if (isset($this->variable))
66 66
         {
67 67
             return $this->variable;
68 68
         }
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
          $vars = $this->getVariables()->getGroupedByName();
94 94
          $amount = count($vars);
95 95
          
96
-         if($amount === 1)
96
+         if ($amount === 1)
97 97
          {
98 98
              $this->variable = array_pop($vars);
99 99
              return;
Please login to merge, or discard this patch.
src/Mailcode/Collection.php 2 patches
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -24,9 +24,9 @@  discard block
 block discarded – undo
24 24
 {
25 25
     const ERROR_CANNOT_RETRIEVE_FIRST_ERROR = 52301;
26 26
     
27
-   /**
28
-    * @var Mailcode_Commands_Command[]
29
-    */
27
+    /**
28
+     * @var Mailcode_Commands_Command[]
29
+     */
30 30
     protected $commands = array();
31 31
     
32 32
     /**
@@ -34,17 +34,17 @@  discard block
 block discarded – undo
34 34
      */
35 35
     protected $errors = array();
36 36
     
37
-   /**
38
-    * @var OperationResult|NULL
39
-    */
37
+    /**
38
+     * @var OperationResult|NULL
39
+     */
40 40
     protected $validationResult;
41 41
     
42
-   /**
43
-    * Adds a command to the collection.
44
-    * 
45
-    * @param Mailcode_Commands_Command $command
46
-    * @return Mailcode_Collection
47
-    */
42
+    /**
43
+     * Adds a command to the collection.
44
+     * 
45
+     * @param Mailcode_Commands_Command $command
46
+     * @return Mailcode_Collection
47
+     */
48 48
     public function addCommand(Mailcode_Commands_Command $command) : Mailcode_Collection
49 49
     {
50 50
         $this->commands[] = $command;
@@ -56,21 +56,21 @@  discard block
 block discarded – undo
56 56
         return $this;
57 57
     }
58 58
     
59
-   /**
60
-    * Whether there are any commands in the collection.
61
-    * 
62
-    * @return bool
63
-    */
59
+    /**
60
+     * Whether there are any commands in the collection.
61
+     * 
62
+     * @return bool
63
+     */
64 64
     public function hasCommands() : bool
65 65
     {
66 66
         return !empty($this->commands);
67 67
     }
68 68
     
69
-   /**
70
-    * Counts the amount of commands in the collection.
71
-    * 
72
-    * @return int
73
-    */
69
+    /**
70
+     * Counts the amount of commands in the collection.
71
+     * 
72
+     * @return int
73
+     */
74 74
     public function countCommands() : int
75 75
     {
76 76
         return count($this->commands);
@@ -90,9 +90,9 @@  discard block
 block discarded – undo
90 90
         $this->errors[] = new Mailcode_Collection_Error_Command($command);
91 91
     }
92 92
     
93
-   /**
94
-    * @return Mailcode_Collection_Error[]
95
-    */
93
+    /**
94
+     * @return Mailcode_Collection_Error[]
95
+     */
96 96
     public function getErrors()
97 97
     {
98 98
         $result = $this->getValidationResult();
@@ -134,25 +134,25 @@  discard block
 block discarded – undo
134 134
         return empty($errors);
135 135
     }
136 136
     
137
-   /**
138
-    * Retrieves all commands that were detected, in the exact order
139
-    * they were found.
140
-    * 
141
-    * @return \Mailcode\Mailcode_Commands_Command[]
142
-    */
137
+    /**
138
+     * Retrieves all commands that were detected, in the exact order
139
+     * they were found.
140
+     * 
141
+     * @return \Mailcode\Mailcode_Commands_Command[]
142
+     */
143 143
     public function getCommands()
144 144
     {
145
-       return $this->commands;
145
+        return $this->commands;
146 146
     }
147 147
     
148
-   /**
149
-    * Retrieves all unique commands by their matched
150
-    * string hash: this ensures only commands that were
151
-    * written the exact same way (including spacing)
152
-    * are returned.
153
-    * 
154
-    * @return \Mailcode\Mailcode_Commands_Command[]
155
-    */
148
+    /**
149
+     * Retrieves all unique commands by their matched
150
+     * string hash: this ensures only commands that were
151
+     * written the exact same way (including spacing)
152
+     * are returned.
153
+     * 
154
+     * @return \Mailcode\Mailcode_Commands_Command[]
155
+     */
156 156
     public function getGroupedByHash()
157 157
     {
158 158
         $hashes = array();
@@ -170,12 +170,12 @@  discard block
 block discarded – undo
170 170
         return array_values($hashes);
171 171
     }
172 172
 
173
-   /**
174
-    * Adds several commands at once.
175
-    * 
176
-    * @param Mailcode_Commands_Command[] $commands
177
-    * @return Mailcode_Collection
178
-    */
173
+    /**
174
+     * Adds several commands at once.
175
+     * 
176
+     * @param Mailcode_Commands_Command[] $commands
177
+     * @return Mailcode_Collection
178
+     */
179 179
     public function addCommands(array $commands) : Mailcode_Collection
180 180
     {
181 181
         foreach($commands as $command)
@@ -234,11 +234,11 @@  discard block
 block discarded – undo
234 234
         return false;
235 235
     }
236 236
     
237
-   /**
238
-    * Retrieves only show variable commands in the collection, if any.
239
-    * 
240
-    * @return \Mailcode\Mailcode_Commands_Command_ShowVariable[]
241
-    */
237
+    /**
238
+     * Retrieves only show variable commands in the collection, if any.
239
+     * 
240
+     * @return \Mailcode\Mailcode_Commands_Command_ShowVariable[]
241
+     */
242 242
     public function getShowVariableCommands()
243 243
     {
244 244
         $result = array();
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
         
100 100
         $errors = $this->errors;
101 101
         
102
-        if(!$result->isValid())
102
+        if (!$result->isValid())
103 103
         {
104 104
             $errors[] = new Mailcode_Collection_Error_Message(
105 105
                 '',
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
     {
116 116
         $errors = $this->getErrors();
117 117
         
118
-        if(!empty($errors))
118
+        if (!empty($errors))
119 119
         {
120 120
             return array_shift($errors);
121 121
         }
@@ -157,11 +157,11 @@  discard block
 block discarded – undo
157 157
     {
158 158
         $hashes = array();
159 159
         
160
-        foreach($this->commands as $command)
160
+        foreach ($this->commands as $command)
161 161
         {
162 162
             $hash = $command->getHash();
163 163
             
164
-            if(!isset($hashes[$hash]))
164
+            if (!isset($hashes[$hash]))
165 165
             {
166 166
                 $hashes[$hash] = $command;
167 167
             }
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
     */
179 179
     public function addCommands(array $commands) : Mailcode_Collection
180 180
     {
181
-        foreach($commands as $command)
181
+        foreach ($commands as $command)
182 182
         {
183 183
             $this->addCommand($command);
184 184
         }
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
     {
198 198
         $collection = new Mailcode_Variables_Collection_Regular();
199 199
         
200
-        foreach($this->commands as $command)
200
+        foreach ($this->commands as $command)
201 201
         {
202 202
             $collection->mergeWith($command->getVariables());
203 203
         }
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
     
208 208
     public function getValidationResult() : OperationResult
209 209
     {
210
-        if(isset($this->validationResult))
210
+        if (isset($this->validationResult))
211 211
         {
212 212
             return $this->validationResult;
213 213
         }
@@ -223,9 +223,9 @@  discard block
 block discarded – undo
223 223
     {
224 224
         $errors = $this->getErrors();
225 225
         
226
-        foreach($errors as $error)
226
+        foreach ($errors as $error)
227 227
         {
228
-            if($error->getCode() === $code)
228
+            if ($error->getCode() === $code)
229 229
             {
230 230
                 return true;
231 231
             }
@@ -243,9 +243,9 @@  discard block
 block discarded – undo
243 243
     {
244 244
         $result = array();
245 245
         
246
-        foreach($this->commands as $command)
246
+        foreach ($this->commands as $command)
247 247
         {
248
-            if($command instanceof Mailcode_Commands_Command_ShowVariable)
248
+            if ($command instanceof Mailcode_Commands_Command_ShowVariable)
249 249
             {
250 250
                 $result[] = $command;
251 251
             }
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
     {
259 259
         $commands = $this->getCommands();
260 260
         
261
-        if(!empty($commands))
261
+        if (!empty($commands))
262 262
         {
263 263
             return array_shift($commands);
264 264
         }
Please login to merge, or discard this patch.