Completed
Pull Request — master (#26)
by Greg
01:13
created
src/GherkinParam.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -93,7 +93,7 @@
 block discarded – undo
93 93
    *
94 94
    * @param string $param
95 95
    *
96
-   * @return \mixed|null Returns parameter's value if exists, else parameter's name
96
+   * @return null|string Returns parameter's value if exists, else parameter's name
97 97
    */
98 98
   final protected function getValueFromParam(string $param)
99 99
   {
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
           elseif (preg_match(self::$regEx['array'], $variable)) {
113 113
             try {
114 114
               $values[] = $this->getValueFromArray($variable);
115
-            } catch(RuntimeException $e) {
115
+            } catch (RuntimeException $e) {
116 116
               if ($this->throwException) throw new GherkinParamException();
117 117
               if ($this->nullable) $values[] = null;
118 118
             }
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
           else {
122 122
             try {
123 123
               $values[] = Fixtures::get($variable);
124
-            } catch(RuntimeException $e) {
124
+            } catch (RuntimeException $e) {
125 125
               if ($this->throwException) throw new GherkinParamException();
126 126
               if ($this->nullable) $values[] = null;
127 127
             }
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
         // due to the default behavior when `search` and `replace` arrays size mismatch
137 137
         $param = $this->mapParametersToValues($matches, $values, $param);
138 138
 
139
-      } catch(GherkinParamException $e) {
139
+      } catch (GherkinParamException $e) {
140 140
         // only active if throwException setting is true
141 141
         throw new ExtensionException($this, "Incorrect parameter name ${param}, or not initialized");
142 142
       }
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
   final private function mapParametersToValues(array $matches, array $values, string $param)
160 160
   {
161 161
     //TODO: move count() into separate variable [performance]
162
-    for ($i=0; $i<count($matches); $i++) {
162
+    for ($i = 0; $i < count($matches); $i++) {
163 163
       $search = $matches[$i];
164 164
       if (\is_string($search)) { // if null then skip
165 165
         if (isset($values[$i])) {
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
         $prop = new ReflectionProperty(get_class($arg), 'table');
273 273
         $prop->setAccessible(true);
274 274
         $table = $prop->getValue($arg);
275
-        foreach($table as $i => $row) {
275
+        foreach ($table as $i => $row) {
276 276
           foreach ($row as $j => $cell) {
277 277
             $val = $this->getValueFromParam($cell);
278 278
             $table[$i][$j] = $val ? $val : null; // issue TableNode does not support `null` values in table
Please login to merge, or discard this patch.
Braces   +30 added lines, -10 removed lines patch added patch discarded remove patch
@@ -113,8 +113,12 @@  discard block
 block discarded – undo
113 113
             try {
114 114
               $values[] = $this->getValueFromArray($variable);
115 115
             } catch(RuntimeException $e) {
116
-              if ($this->throwException) throw new GherkinParamException();
117
-              if ($this->nullable) $values[] = null;
116
+              if ($this->throwException) {
117
+                throw new GherkinParamException();
118
+              }
119
+              if ($this->nullable) {
120
+                $values[] = null;
121
+              }
118 122
             }
119 123
           } 
120 124
           // normal case
@@ -122,13 +126,19 @@  discard block
 block discarded – undo
122 126
             try {
123 127
               $values[] = Fixtures::get($variable);
124 128
             } catch(RuntimeException $e) {
125
-              if ($this->throwException) throw new GherkinParamException();
126
-              if ($this->nullable) $values[] = null;
129
+              if ($this->throwException) {
130
+                throw new GherkinParamException();
131
+              }
132
+              if ($this->nullable) {
133
+                $values[] = null;
134
+              }
127 135
             }
128 136
           }
129 137
           // if machting value return is not found (null)
130 138
           if (is_null(end($values))) {
131
-            if ($this->throwException) throw new GherkinParamException();
139
+            if ($this->throwException) {
140
+              throw new GherkinParamException();
141
+            }
132 142
           }
133 143
         }
134 144
 
@@ -166,18 +176,28 @@  discard block
 block discarded – undo
166 176
           $replacement = $values[$i];
167 177
           if (\is_array($replacement)) { 
168 178
             // case of replacement is an array (case of config param), ie param does not exists
169
-            if ($this->throwException) throw new GherkinParamException();
170
-            if ($this->nullable) $param = null;
179
+            if ($this->throwException) {
180
+              throw new GherkinParamException();
181
+            }
182
+            if ($this->nullable) {
183
+              $param = null;
184
+            }
171 185
             break;
172 186
           }
173 187
           //TODO: replace str_replace by strtr (performance)
174 188
           $param = \str_replace($search, $replacement, $param);
175 189
         } else {
176
-          if ($this->throwException) throw new GherkinParamException();
177
-          if ($this->nullable) $param = null;
190
+          if ($this->throwException) {
191
+            throw new GherkinParamException();
192
+          }
193
+          if ($this->nullable) {
194
+            $param = null;
195
+          }
178 196
         }
179 197
       } else {
180
-        if ($this->nullable) $param = null;
198
+        if ($this->nullable) {
199
+          $param = null;
200
+        }
181 201
         break;
182 202
       }
183 203
     }
Please login to merge, or discard this patch.