Failed Conditions
Branch master (7eab5b)
by Tomas
02:46
created
src/AbstractArgumentBuilder.php 1 patch
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -14,15 +14,15 @@  discard block
 block discarded – undo
14 14
  */
15 15
 abstract class AbstractArgumentBuilder implements ArgumentBuilderInterface
16 16
 {
17
-    public const ARGUMENT_TYPE_MIXED = 0;
18
-    public const ARGUMENT_TYPE_ARGUMENT_BUILDER = 1;
19
-    public const ARGUMENT_TYPE_NUMERIC = 2;
20
-    public const ARGUMENT_TYPE_ENUM = 3;
21
-    public const ARGUMENT_TYPE_BOOLEAN = 4;
17
+    public const ARGUMENT_TYPE_MIXED=0;
18
+    public const ARGUMENT_TYPE_ARGUMENT_BUILDER=1;
19
+    public const ARGUMENT_TYPE_NUMERIC=2;
20
+    public const ARGUMENT_TYPE_ENUM=3;
21
+    public const ARGUMENT_TYPE_BOOLEAN=4;
22 22
 
23
-    protected $args = array();
23
+    protected $args=array();
24 24
 
25
-    protected $fields = array(
25
+    protected $fields=array(
26 26
         //'arg1' => self::ARGUMENT_TYPE_MIXED,
27 27
         //'arg2' => SomeArgumentBuilder::class,
28 28
     );
@@ -46,9 +46,9 @@  discard block
 block discarded – undo
46 46
      */
47 47
     private function camelCaseToSnakeCase($str)
48 48
     {
49
-        $str[0] = strtolower($str[0]);
49
+        $str[0]=strtolower($str[0]);
50 50
 
51
-        return preg_replace_callback('/([A-Z])/', function ($c) {
51
+        return preg_replace_callback('/([A-Z])/', function($c) {
52 52
             return '_'.strtolower($c[1]);
53 53
         }, $str);
54 54
     }
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
         foreach ($this->fields as $name => $field) {
76 76
             // Consider string value as a class name
77 77
             if (is_string($field)) {
78
-                $this->fields[$name] = array(
78
+                $this->fields[$name]=array(
79 79
                     'type' => self::ARGUMENT_TYPE_ARGUMENT_BUILDER,
80 80
                     'class' => $field,
81 81
                     'validator' => new ArgumentBuilderTypeValidator($name, $field),
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 
84 84
             // consider numeric values as type name
85 85
             } elseif (is_int($field)) {
86
-                $this->fields[$name] = array(
86
+                $this->fields[$name]=array(
87 87
                     'type' => $field,
88 88
                     'validator' => null,
89 89
                 );
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
             return true;
137 137
         }
138 138
 
139
-        $validator = $this->fields[$field]['validator'];
139
+        $validator=$this->fields[$field]['validator'];
140 140
 
141 141
         if ($validator instanceof TypeValidatorInterface) {
142 142
             return $validator->validate($value);
@@ -189,8 +189,8 @@  discard block
 block discarded – undo
189 189
             throw new Exception\UnmatchedCallTypeException();
190 190
         }
191 191
 
192
-        $field = lcfirst($matches[1]);
193
-        $field = $this->camelCaseToSnakeCase($field);
192
+        $field=lcfirst($matches[1]);
193
+        $field=$this->camelCaseToSnakeCase($field);
194 194
 
195 195
         if (!array_key_exists($field, $this->fields)) {
196 196
             throw new Exception\UndefinedMethodException($name);
@@ -233,11 +233,11 @@  discard block
 block discarded – undo
233 233
             throw new Exception\UnmatchedCallTypeException();
234 234
         }
235 235
 
236
-        $field = $matches[1];
236
+        $field=$matches[1];
237 237
         if ('-' !== $field[0]) {
238
-            $field = lcfirst($matches[1]);
238
+            $field=lcfirst($matches[1]);
239 239
         }
240
-        $field = $this->camelCaseToSnakeCase($field);
240
+        $field=$this->camelCaseToSnakeCase($field);
241 241
 
242 242
         if (!array_key_exists($field, $this->fields)) {
243 243
             throw new Exception\UndefinedMethodException($name);
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
             throw new Exception\InvalidArgumentException('Method '.__CLASS__.'::'.$name.'() must take exactly 1 argument');
248 248
         }
249 249
 
250
-        $value = $arguments[0];
250
+        $value=$arguments[0];
251 251
 
252 252
         if (self::ARGUMENT_TYPE_ARGUMENT_BUILDER === $this->fields[$field]['type'] && count($arguments) > 1) {
253 253
             if (!is_string($arguments[0])) {
@@ -256,15 +256,15 @@  discard block
 block discarded – undo
256 256
                 );
257 257
             }
258 258
 
259
-            $class = $this->fields[$field]['class'];
260
-            $value = isset($this->args[$field]) ? $this->args[$field] : new $class();
259
+            $class=$this->fields[$field]['class'];
260
+            $value=isset($this->args[$field]) ? $this->args[$field] : new $class();
261 261
 
262 262
             call_user_func_array(array($value, 'set'.$this->snakeCaseToCamelCase($arguments[0])), array_slice($arguments, 1));
263 263
         } elseif (!$this->validateFieldValue($field, $value)) {
264 264
             throw new Exception\InvalidArgumentException(sprintf('Invalid value "%s" for field "%s"', $value, $field));
265 265
         }
266 266
 
267
-        $this->args[$field] = $value;
267
+        $this->args[$field]=$value;
268 268
 
269 269
         return $this;
270 270
     }
@@ -286,11 +286,11 @@  discard block
 block discarded – undo
286 286
             throw new Exception\UnmatchedCallTypeException();
287 287
         }
288 288
 
289
-        $field = $matches[1];
289
+        $field=$matches[1];
290 290
         if ('-' !== $field[0]) {
291
-            $field = lcfirst($matches[1]);
291
+            $field=lcfirst($matches[1]);
292 292
         }
293
-        $field = $this->camelCaseToSnakeCase($field);
293
+        $field=$this->camelCaseToSnakeCase($field);
294 294
 
295 295
         // Check if field is defined for this ArgumentBuilder
296 296
         if (!array_key_exists($field, $this->fields)) {
@@ -347,13 +347,13 @@  discard block
 block discarded – undo
347 347
      */
348 348
     public function build()
349 349
     {
350
-        $result = array();
350
+        $result=array();
351 351
 
352 352
         foreach ($this->args as $key => $arg) {
353 353
             if ($arg instanceof ArgumentBuilderInterface) {
354
-                $result[$key] = $arg->build(); //@todo: missing Circular Reference check
354
+                $result[$key]=$arg->build(); //@todo: missing Circular Reference check
355 355
             } else {
356
-                $result[$key] = $this->transformValue($key, $arg);
356
+                $result[$key]=$this->transformValue($key, $arg);
357 357
             }
358 358
         }
359 359
 
Please login to merge, or discard this patch.
tests/Fixtures/CustomMockArgumentBuilder.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@
 block discarded – undo
8 8
 {
9 9
     public function __construct(array $fields)
10 10
     {
11
-        $this->fields = $fields;
11
+        $this->fields=$fields;
12 12
         parent::__construct();
13 13
     }
14 14
 }
Please login to merge, or discard this patch.
tests/Fixtures/SubMockArgumentBuilder.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@
 block discarded – undo
6 6
 
7 7
 class SubMockArgumentBuilder extends AbstractArgumentBuilder
8 8
 {
9
-    protected $fields = array(
9
+    protected $fields=array(
10 10
         'subarg1' => self::ARGUMENT_TYPE_MIXED,
11 11
         'subarg2' => self::ARGUMENT_TYPE_MIXED,
12 12
         'boolarg' => self::ARGUMENT_TYPE_BOOLEAN,
Please login to merge, or discard this patch.
tests/Fixtures/MockArgumentBuilder.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 {
9 9
     protected function load()
10 10
     {
11
-        $this->fields = array(
11
+        $this->fields=array(
12 12
             'arg1' => self::ARGUMENT_TYPE_MIXED,
13 13
             'arg2' => self::ARGUMENT_TYPE_MIXED,
14 14
             'sub1' => SubMockArgumentBuilder::class,
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
             ),
19 19
             'enum' => array(
20 20
                 'type' => self::ARGUMENT_TYPE_ENUM,
21
-                'validator' => function ($value) {
21
+                'validator' => function($value) {
22 22
                     return in_array($value, array('val1', 'val2'));
23 23
                 },
24 24
             ),
Please login to merge, or discard this patch.
tests/Unit/AbstractArgumentBuilderTest.php 1 patch
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 
19 19
     protected function setUp()
20 20
     {
21
-        $this->sampleData = array(
21
+        $this->sampleData=array(
22 22
             'arg1' => 'xxx',
23 23
             'arg2' => 'yyy',
24 24
             'sub1' => array(
@@ -34,12 +34,12 @@  discard block
 block discarded – undo
34 34
             'enum' => 'val1',
35 35
         );
36 36
 
37
-        $this->sampleDataEncoded = http_build_query($this->sampleData);
37
+        $this->sampleDataEncoded=http_build_query($this->sampleData);
38 38
     }
39 39
 
40 40
     private function getBuilderMock()
41 41
     {
42
-        $builder = new MockArgumentBuilder();
42
+        $builder=new MockArgumentBuilder();
43 43
         $builder->setArg1('xxx');
44 44
         $builder->setArg2('yyy');
45 45
         $builder->setSub1('subarg1', 'zzz');
@@ -55,21 +55,21 @@  discard block
 block discarded – undo
55 55
 
56 56
     public function testBuild()
57 57
     {
58
-        $builder = $this->getBuilderMock();
58
+        $builder=$this->getBuilderMock();
59 59
 
60 60
         $this->assertEquals($this->sampleData, $builder->build());
61 61
     }
62 62
 
63 63
     public function testToString()
64 64
     {
65
-        $builder = $this->getBuilderMock();
65
+        $builder=$this->getBuilderMock();
66 66
 
67 67
         $this->assertEquals($this->sampleDataEncoded, (string) $builder);
68 68
     }
69 69
 
70 70
     public function testGetFields()
71 71
     {
72
-        $builder = $this->getBuilderMock();
72
+        $builder=$this->getBuilderMock();
73 73
 
74 74
         $this->assertEquals('xxx', $builder->getArg1());
75 75
         $this->assertInstanceOf(SubMockArgumentBuilder::class, $builder->getSub1());
@@ -80,12 +80,12 @@  discard block
 block discarded – undo
80 80
 
81 81
     public function testSetNullFields()
82 82
     {
83
-        $data = $this->sampleData;
84
-        $data['arg1'] = null;
85
-        $data['sub1'] = null;
86
-        $data['sub2']['subarg1'] = null;
83
+        $data=$this->sampleData;
84
+        $data['arg1']=null;
85
+        $data['sub1']=null;
86
+        $data['sub2']['subarg1']=null;
87 87
 
88
-        $builder = $this->getBuilderMock();
88
+        $builder=$this->getBuilderMock();
89 89
         $builder->setArg1(null);
90 90
         $builder->setSub1(null);
91 91
         $builder->setSub2('subarg1', null);
@@ -95,16 +95,16 @@  discard block
 block discarded – undo
95 95
 
96 96
     public function testSetSubAsObject()
97 97
     {
98
-        $builder = $this->getBuilderMock();
98
+        $builder=$this->getBuilderMock();
99 99
         $builder->setSub1(new SubMockArgumentBuilder());
100 100
     }
101 101
 
102 102
     public function testUnsetFields()
103 103
     {
104
-        $data = $this->sampleData;
104
+        $data=$this->sampleData;
105 105
         unset($data['arg1'], $data['sub1'], $data['sub2']['subarg1']);
106 106
 
107
-        $builder = $this->getBuilderMock();
107
+        $builder=$this->getBuilderMock();
108 108
         $builder->unsetArg1();
109 109
         $builder->unsetSub1();
110 110
         $builder->unsetSub2('subarg1');
@@ -114,13 +114,13 @@  discard block
 block discarded – undo
114 114
 
115 115
     public function testSetFields()
116 116
     {
117
-        $data = $this->sampleData;
118
-        $data['arg1'] = 'aaa';
119
-        $data['sub1']['subarg1'] = 'new';
120
-        $data['sub1']['boolarg'] = 'true';
121
-        $data['sub2'] = array('subarg1' => 'good');
117
+        $data=$this->sampleData;
118
+        $data['arg1']='aaa';
119
+        $data['sub1']['subarg1']='new';
120
+        $data['sub1']['boolarg']='true';
121
+        $data['sub2']=array('subarg1' => 'good');
122 122
 
123
-        $builder = $this->getBuilderMock();
123
+        $builder=$this->getBuilderMock();
124 124
         $builder->setArg1('aaa');
125 125
         $builder->setSub1('subarg1', 'new');
126 126
         $builder->setSub2((new SubMockArgumentBuilder())->setSubarg1('good'));
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
         $this->expectException(InvalidDefinitionException::class);
135 135
         $this->expectExceptionMessage('Field description must be either string (shortcut for class name), or int (shortcut for field type) or array (full form)');
136 136
 
137
-        $builder = new CustomMockArgumentBuilder(array(
137
+        $builder=new CustomMockArgumentBuilder(array(
138 138
             'arg1' => new \stdClass(),
139 139
         ));
140 140
         $builder->setArg1('aaa');
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
         $this->expectException(InvalidDefinitionException::class);
146 146
         $this->expectExceptionMessage('Field type is not defined');
147 147
 
148
-        $builder = new CustomMockArgumentBuilder(array(
148
+        $builder=new CustomMockArgumentBuilder(array(
149 149
             'arg1' => array(
150 150
             ),
151 151
         ));
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
         $this->expectException(InvalidDefinitionException::class);
158 158
         $this->expectExceptionMessage('Field of type ARGUMENT_TYPE_ARGUMENT_BUILDER must have class defined');
159 159
 
160
-        $builder = new CustomMockArgumentBuilder(array(
160
+        $builder=new CustomMockArgumentBuilder(array(
161 161
             'arg1' => array(
162 162
                 'type' => AbstractArgumentBuilder::ARGUMENT_TYPE_ARGUMENT_BUILDER,
163 163
             ),
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
         $this->expectException(UndefinedMethodException::class);
171 171
         $this->expectExceptionMessageRegExp('/^Call to undefined method/');
172 172
 
173
-        $builder = $this->getBuilderMock();
173
+        $builder=$this->getBuilderMock();
174 174
         $builder->dummyCall('foo');
175 175
     }
176 176
 
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
         $this->expectException(UndefinedMethodException::class);
180 180
         $this->expectExceptionMessageRegExp('/^Call to undefined method/');
181 181
 
182
-        $builder = $this->getBuilderMock();
182
+        $builder=$this->getBuilderMock();
183 183
         $builder->setNonexistant('blah');
184 184
     }
185 185
 
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
         $this->expectException(UndefinedMethodException::class);
189 189
         $this->expectExceptionMessageRegExp('/^Call to undefined method/');
190 190
 
191
-        $builder = $this->getBuilderMock();
191
+        $builder=$this->getBuilderMock();
192 192
         $builder->unsetNonexistant();
193 193
     }
194 194
 
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
         $this->expectException(InvalidArgumentException::class);
201 201
         $this->expectExceptionMessageRegExp('/^Method .+ expects the first parameter to be string if you want to get sub-value$/');
202 202
 
203
-        $builder = $this->getBuilderMock();
203
+        $builder=$this->getBuilderMock();
204 204
         $builder->getSub1($value);
205 205
     }
206 206
 
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
         $this->expectException(InvalidArgumentException::class);
210 210
         $this->expectExceptionMessageRegExp('/Method .+ must take exactly 0 arguments/');
211 211
 
212
-        $builder = $this->getBuilderMock();
212
+        $builder=$this->getBuilderMock();
213 213
         $builder->getArg1('yyy');
214 214
     }
215 215
 
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
         $this->expectException(UndefinedMethodException::class);
219 219
         $this->expectExceptionMessageRegExp('/^Call to undefined method/');
220 220
 
221
-        $builder = $this->getBuilderMock();
221
+        $builder=$this->getBuilderMock();
222 222
         $builder->getDummy();
223 223
     }
224 224
 
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
         $this->expectException(InvalidArgumentException::class);
228 228
         $this->expectExceptionMessageRegExp('/^Value of the field ".+" must an instance of ArgumentBuilderInterface$/');
229 229
 
230
-        $builder = $this->getBuilderMock();
230
+        $builder=$this->getBuilderMock();
231 231
         $builder->setSub1(new \stdClass());
232 232
     }
233 233
 
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
         $this->expectException(InvalidArgumentException::class);
237 237
         $this->expectExceptionMessageRegExp('/^Invalid value type. Expected instance of ".+", got ".+".$/');
238 238
 
239
-        $builder = $this->getBuilderMock();
239
+        $builder=$this->getBuilderMock();
240 240
         $builder->setSub1(array('xxx'));
241 241
     }
242 242
 
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
         $this->expectException(InvalidArgumentException::class);
246 246
         $this->expectExceptionMessageRegExp('/^Method .+ must take exactly 1 argument$/');
247 247
 
248
-        $builder = $this->getBuilderMock();
248
+        $builder=$this->getBuilderMock();
249 249
         $builder->setArg1('aaa', 'bbb');
250 250
     }
251 251
 
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
         $this->expectException(InvalidArgumentException::class);
258 258
         $this->expectExceptionMessageRegExp('/^Method .+ expects the first parameter to be string$/');
259 259
 
260
-        $builder = $this->getBuilderMock();
260
+        $builder=$this->getBuilderMock();
261 261
         $builder->setSub1($value, 'bbb');
262 262
     }
263 263
 
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
         $this->expectException(InvalidArgumentException::class);
267 267
         $this->expectExceptionMessageRegExp('/^Method .+ must take exactly 0 arguments$/');
268 268
 
269
-        $builder = $this->getBuilderMock();
269
+        $builder=$this->getBuilderMock();
270 270
         $builder->unsetArg1('bbb');
271 271
     }
272 272
 
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
         $this->expectException(InvalidArgumentException::class);
279 279
         $this->expectExceptionMessageRegExp('/^Method .+ expects the first parameter to be string if you want to unset sub-value$/');
280 280
 
281
-        $builder = $this->getBuilderMock();
281
+        $builder=$this->getBuilderMock();
282 282
         $builder->unsetSub1($value);
283 283
     }
284 284
 
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
         $this->expectException(InvalidDefinitionException::class);
288 288
         $this->expectExceptionMessageRegExp('/^Class ".+" not found \(field\: ".+"\)$/');
289 289
 
290
-        $builder = new CustomMockArgumentBuilder(array(
290
+        $builder=new CustomMockArgumentBuilder(array(
291 291
             'arg1' => 'DummyNonExistantClass',
292 292
         ));
293 293
         $builder->setArg1('something');
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
         $this->expectException(InvalidDefinitionException::class);
302 302
         $this->expectExceptionMessageRegExp('/^Validator for the field ".+" is defined but is not callable$/');
303 303
 
304
-        $builder = new CustomMockArgumentBuilder(array(
304
+        $builder=new CustomMockArgumentBuilder(array(
305 305
             'arg1' => array(
306 306
                 'type' => AbstractArgumentBuilder::ARGUMENT_TYPE_MIXED,
307 307
                 'validator' => $validator,
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
      */
316 316
     public function testArgumentBuilderEmptyValidator($validator)
317 317
     {
318
-        $builder = new CustomMockArgumentBuilder(array(
318
+        $builder=new CustomMockArgumentBuilder(array(
319 319
             'arg1' => array(
320 320
                 'type' => AbstractArgumentBuilder::ARGUMENT_TYPE_MIXED,
321 321
                 'validator' => $validator,
@@ -329,10 +329,10 @@  discard block
 block discarded – undo
329 329
         $this->expectException(InvalidArgumentException::class);
330 330
         $this->expectExceptionMessageRegExp('/^Invalid value ".+" for field ".+"$/');
331 331
 
332
-        $builder = new CustomMockArgumentBuilder(array(
332
+        $builder=new CustomMockArgumentBuilder(array(
333 333
             'arg1' => array(
334 334
                 'type' => AbstractArgumentBuilder::ARGUMENT_TYPE_MIXED,
335
-                'validator' => function () {
335
+                'validator' => function() {
336 336
                     return false;
337 337
                 },
338 338
             ),
Please login to merge, or discard this patch.