Completed
Pull Request — master (#51)
by
unknown
20s
created
tests/Parser/Php/PreprocessorTest.php 1 patch
Indentation   +274 added lines, -274 removed lines patch added patch discarded remove patch
@@ -3,42 +3,42 @@  discard block
 block discarded – undo
3 3
 class PreprocessorTest extends SwaggerGen_TestCase
4 4
 {
5 5
 
6
-    /**
7
-     * @covers \SwaggerGen\Parser\Php\Preprocessor::__construct
8
-     */
9
-    public function testConstructor_Empty()
10
-    {
11
-        $object = new \SwaggerGen\Parser\Php\Preprocessor();
12
-        $this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object);
13
-    }
14
-
15
-    /**
16
-     * @covers \SwaggerGen\Parser\Php\Preprocessor::__construct
17
-     * @covers \SwaggerGen\Parser\Php\Preprocessor::getPrefix
18
-     * @covers \SwaggerGen\Parser\Php\Preprocessor::setPrefix
19
-     */
20
-    public function testConstructor_Prefix()
21
-    {
22
-        $object = new \SwaggerGen\Parser\Php\Preprocessor();
23
-        $this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object);
24
-        $this->assertEquals('rest', $object->getPrefix());
25
-
26
-        $object = new \SwaggerGen\Parser\Php\Preprocessor('foo');
27
-        $this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object);
28
-        $this->assertEquals('foo', $object->getPrefix());
29
-
30
-        $object->setPrefix('bar');
31
-        $this->assertEquals('bar', $object->getPrefix());
32
-    }
33
-
34
-    /**
35
-     * @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess
36
-     */
37
-    public function testPreprocess_Ifdef_NotDefined()
38
-    {
39
-        $object = new \SwaggerGen\Parser\Php\Preprocessor();
40
-        $this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object);
41
-        $out = $object->preprocess('<?php
6
+	/**
7
+	 * @covers \SwaggerGen\Parser\Php\Preprocessor::__construct
8
+	 */
9
+	public function testConstructor_Empty()
10
+	{
11
+		$object = new \SwaggerGen\Parser\Php\Preprocessor();
12
+		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object);
13
+	}
14
+
15
+	/**
16
+	 * @covers \SwaggerGen\Parser\Php\Preprocessor::__construct
17
+	 * @covers \SwaggerGen\Parser\Php\Preprocessor::getPrefix
18
+	 * @covers \SwaggerGen\Parser\Php\Preprocessor::setPrefix
19
+	 */
20
+	public function testConstructor_Prefix()
21
+	{
22
+		$object = new \SwaggerGen\Parser\Php\Preprocessor();
23
+		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object);
24
+		$this->assertEquals('rest', $object->getPrefix());
25
+
26
+		$object = new \SwaggerGen\Parser\Php\Preprocessor('foo');
27
+		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object);
28
+		$this->assertEquals('foo', $object->getPrefix());
29
+
30
+		$object->setPrefix('bar');
31
+		$this->assertEquals('bar', $object->getPrefix());
32
+	}
33
+
34
+	/**
35
+	 * @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess
36
+	 */
37
+	public function testPreprocess_Ifdef_NotDefined()
38
+	{
39
+		$object = new \SwaggerGen\Parser\Php\Preprocessor();
40
+		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object);
41
+		$out = $object->preprocess('<?php
42 42
 			/**
43 43
 			 * @rest\ifdef test
44 44
 			 * @rest\whatever
@@ -46,25 +46,25 @@  discard block
 block discarded – undo
46 46
 			 */
47 47
 		');
48 48
 
49
-        $this->assertEquals('<?php
49
+		$this->assertEquals('<?php
50 50
 			/**
51 51
 			 * @!rest\ifdef test
52 52
 			 * @!rest\whatever
53 53
 			 * @!rest\endif
54 54
 			 */
55 55
 		', $out);
56
-    }
57
-
58
-    /**
59
-     * @covers \SwaggerGen\Parser\Php\Preprocessor::define
60
-     * @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess
61
-     */
62
-    public function testPreprocess_Ifdef_Defined()
63
-    {
64
-        $object = new \SwaggerGen\Parser\Php\Preprocessor();
65
-        $this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object);
66
-        $object->define('test');
67
-        $out = $object->preprocess('<?php
56
+	}
57
+
58
+	/**
59
+	 * @covers \SwaggerGen\Parser\Php\Preprocessor::define
60
+	 * @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess
61
+	 */
62
+	public function testPreprocess_Ifdef_Defined()
63
+	{
64
+		$object = new \SwaggerGen\Parser\Php\Preprocessor();
65
+		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object);
66
+		$object->define('test');
67
+		$out = $object->preprocess('<?php
68 68
 			/**
69 69
 			 * @rest\ifdef test
70 70
 			 * @rest\whatever
@@ -72,23 +72,23 @@  discard block
 block discarded – undo
72 72
 			 */
73 73
 		');
74 74
 
75
-        $this->assertEquals('<?php
75
+		$this->assertEquals('<?php
76 76
 			/**
77 77
 			 * @!rest\ifdef test
78 78
 			 * @rest\whatever
79 79
 			 * @!rest\endif
80 80
 			 */
81 81
 		', $out);
82
-    }
82
+	}
83 83
 
84
-    /**
85
-     * @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess
86
-     */
87
-    public function testPreprocess_Ifndef_NotDefined()
88
-    {
89
-        $object = new \SwaggerGen\Parser\Php\Preprocessor();
90
-        $this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object);
91
-        $out = $object->preprocess('<?php
84
+	/**
85
+	 * @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess
86
+	 */
87
+	public function testPreprocess_Ifndef_NotDefined()
88
+	{
89
+		$object = new \SwaggerGen\Parser\Php\Preprocessor();
90
+		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object);
91
+		$out = $object->preprocess('<?php
92 92
 			/**
93 93
 			 * @rest\ifndef test
94 94
 			 * @rest\whatever
@@ -96,25 +96,25 @@  discard block
 block discarded – undo
96 96
 			 */
97 97
 		');
98 98
 
99
-        $this->assertEquals('<?php
99
+		$this->assertEquals('<?php
100 100
 			/**
101 101
 			 * @!rest\ifndef test
102 102
 			 * @rest\whatever
103 103
 			 * @!rest\endif
104 104
 			 */
105 105
 		', $out);
106
-    }
107
-
108
-    /**
109
-     * @covers \SwaggerGen\Parser\Php\Preprocessor::define
110
-     * @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess
111
-     */
112
-    public function testPreprocess_Ifndef_Defined()
113
-    {
114
-        $object = new \SwaggerGen\Parser\Php\Preprocessor();
115
-        $this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object);
116
-        $object->define('test');
117
-        $out = $object->preprocess('<?php
106
+	}
107
+
108
+	/**
109
+	 * @covers \SwaggerGen\Parser\Php\Preprocessor::define
110
+	 * @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess
111
+	 */
112
+	public function testPreprocess_Ifndef_Defined()
113
+	{
114
+		$object = new \SwaggerGen\Parser\Php\Preprocessor();
115
+		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object);
116
+		$object->define('test');
117
+		$out = $object->preprocess('<?php
118 118
 			/**
119 119
 			 * @rest\ifndef test
120 120
 			 * @rest\whatever
@@ -122,23 +122,23 @@  discard block
 block discarded – undo
122 122
 			 */
123 123
 		');
124 124
 
125
-        $this->assertEquals('<?php
125
+		$this->assertEquals('<?php
126 126
 			/**
127 127
 			 * @!rest\ifndef test
128 128
 			 * @!rest\whatever
129 129
 			 * @!rest\endif
130 130
 			 */
131 131
 		', $out);
132
-    }
132
+	}
133 133
 
134
-    /**
135
-     * @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess
136
-     */
137
-    public function testPreprocess_Define()
138
-    {
139
-        $object = new \SwaggerGen\Parser\Php\Preprocessor();
140
-        $this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object);
141
-        $out = $object->preprocess('<?php
134
+	/**
135
+	 * @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess
136
+	 */
137
+	public function testPreprocess_Define()
138
+	{
139
+		$object = new \SwaggerGen\Parser\Php\Preprocessor();
140
+		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object);
141
+		$out = $object->preprocess('<?php
142 142
 			/**
143 143
 			 * @rest\define test
144 144
 			 * @rest\ifndef test
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
 			 */
148 148
 		');
149 149
 
150
-        $this->assertEquals('<?php
150
+		$this->assertEquals('<?php
151 151
 			/**
152 152
 			 * @!rest\define test
153 153
 			 * @!rest\ifndef test
@@ -155,16 +155,16 @@  discard block
 block discarded – undo
155 155
 			 * @!rest\endif
156 156
 			 */
157 157
 		', $out);
158
-    }
158
+	}
159 159
 
160
-    /**
161
-     * @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess
162
-     */
163
-    public function testPreprocess_Undef()
164
-    {
165
-        $object = new \SwaggerGen\Parser\Php\Preprocessor();
166
-        $this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object);
167
-        $out = $object->preprocess('<?php
160
+	/**
161
+	 * @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess
162
+	 */
163
+	public function testPreprocess_Undef()
164
+	{
165
+		$object = new \SwaggerGen\Parser\Php\Preprocessor();
166
+		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object);
167
+		$out = $object->preprocess('<?php
168 168
 			/**
169 169
 			 * @rest\define test
170 170
 			 * @rest\undef test
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
 			 */
175 175
 		');
176 176
 
177
-        $this->assertEquals('<?php
177
+		$this->assertEquals('<?php
178 178
 			/**
179 179
 			 * @!rest\define test
180 180
 			 * @!rest\undef test
@@ -183,16 +183,16 @@  discard block
 block discarded – undo
183 183
 			 * @!rest\endif
184 184
 			 */
185 185
 		', $out);
186
-    }
186
+	}
187 187
 
188
-    /**
189
-     * @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess
190
-     */
191
-    public function testPreprocess_If_NotDefined()
192
-    {
193
-        $object = new \SwaggerGen\Parser\Php\Preprocessor();
194
-        $this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object);
195
-        $out = $object->preprocess('<?php
188
+	/**
189
+	 * @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess
190
+	 */
191
+	public function testPreprocess_If_NotDefined()
192
+	{
193
+		$object = new \SwaggerGen\Parser\Php\Preprocessor();
194
+		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object);
195
+		$out = $object->preprocess('<?php
196 196
 			/**
197 197
 			 * @rest\if test red
198 198
 			 * @rest\whatever
@@ -200,25 +200,25 @@  discard block
 block discarded – undo
200 200
 			 */
201 201
 		');
202 202
 
203
-        $this->assertEquals('<?php
203
+		$this->assertEquals('<?php
204 204
 			/**
205 205
 			 * @!rest\if test red
206 206
 			 * @!rest\whatever
207 207
 			 * @!rest\endif
208 208
 			 */
209 209
 		', $out);
210
-    }
211
-
212
-    /**
213
-     * @covers \SwaggerGen\Parser\Php\Preprocessor::define
214
-     * @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess
215
-     */
216
-    public function testPreprocess_If_AnyValue()
217
-    {
218
-        $object = new \SwaggerGen\Parser\Php\Preprocessor();
219
-        $this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object);
220
-        $object->define('test', 'green');
221
-        $out = $object->preprocess('<?php
210
+	}
211
+
212
+	/**
213
+	 * @covers \SwaggerGen\Parser\Php\Preprocessor::define
214
+	 * @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess
215
+	 */
216
+	public function testPreprocess_If_AnyValue()
217
+	{
218
+		$object = new \SwaggerGen\Parser\Php\Preprocessor();
219
+		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object);
220
+		$object->define('test', 'green');
221
+		$out = $object->preprocess('<?php
222 222
 			/**
223 223
 			 * @rest\if test
224 224
 			 * @rest\whatever
@@ -226,25 +226,25 @@  discard block
 block discarded – undo
226 226
 			 */
227 227
 		');
228 228
 
229
-        $this->assertEquals('<?php
229
+		$this->assertEquals('<?php
230 230
 			/**
231 231
 			 * @!rest\if test
232 232
 			 * @rest\whatever
233 233
 			 * @!rest\endif
234 234
 			 */
235 235
 		', $out);
236
-    }
237
-
238
-    /**
239
-     * @covers \SwaggerGen\Parser\Php\Preprocessor::define
240
-     * @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess
241
-     */
242
-    public function testPreprocess_If_NoValue()
243
-    {
244
-        $object = new \SwaggerGen\Parser\Php\Preprocessor();
245
-        $this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object);
246
-        $object->define('test');
247
-        $out = $object->preprocess('<?php
236
+	}
237
+
238
+	/**
239
+	 * @covers \SwaggerGen\Parser\Php\Preprocessor::define
240
+	 * @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess
241
+	 */
242
+	public function testPreprocess_If_NoValue()
243
+	{
244
+		$object = new \SwaggerGen\Parser\Php\Preprocessor();
245
+		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object);
246
+		$object->define('test');
247
+		$out = $object->preprocess('<?php
248 248
 			/**
249 249
 			 * @rest\if test red
250 250
 			 * @rest\whatever
@@ -252,25 +252,25 @@  discard block
 block discarded – undo
252 252
 			 */
253 253
 		');
254 254
 
255
-        $this->assertEquals('<?php
255
+		$this->assertEquals('<?php
256 256
 			/**
257 257
 			 * @!rest\if test red
258 258
 			 * @!rest\whatever
259 259
 			 * @!rest\endif
260 260
 			 */
261 261
 		', $out);
262
-    }
263
-
264
-    /**
265
-     * @covers \SwaggerGen\Parser\Php\Preprocessor::define
266
-     * @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess
267
-     */
268
-    public function testPreprocess_If_Mismatch()
269
-    {
270
-        $object = new \SwaggerGen\Parser\Php\Preprocessor();
271
-        $this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object);
272
-        $object->define('test', 'green');
273
-        $out = $object->preprocess('<?php
262
+	}
263
+
264
+	/**
265
+	 * @covers \SwaggerGen\Parser\Php\Preprocessor::define
266
+	 * @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess
267
+	 */
268
+	public function testPreprocess_If_Mismatch()
269
+	{
270
+		$object = new \SwaggerGen\Parser\Php\Preprocessor();
271
+		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object);
272
+		$object->define('test', 'green');
273
+		$out = $object->preprocess('<?php
274 274
 			/**
275 275
 			 * @rest\if test red
276 276
 			 * @rest\whatever
@@ -278,25 +278,25 @@  discard block
 block discarded – undo
278 278
 			 */
279 279
 		');
280 280
 
281
-        $this->assertEquals('<?php
281
+		$this->assertEquals('<?php
282 282
 			/**
283 283
 			 * @!rest\if test red
284 284
 			 * @!rest\whatever
285 285
 			 * @!rest\endif
286 286
 			 */
287 287
 		', $out);
288
-    }
289
-
290
-    /**
291
-     * @covers \SwaggerGen\Parser\Php\Preprocessor::define
292
-     * @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess
293
-     */
294
-    public function testPreprocess_If_Match()
295
-    {
296
-        $object = new \SwaggerGen\Parser\Php\Preprocessor();
297
-        $this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object);
298
-        $object->define('test', 'red');
299
-        $out = $object->preprocess('<?php
288
+	}
289
+
290
+	/**
291
+	 * @covers \SwaggerGen\Parser\Php\Preprocessor::define
292
+	 * @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess
293
+	 */
294
+	public function testPreprocess_If_Match()
295
+	{
296
+		$object = new \SwaggerGen\Parser\Php\Preprocessor();
297
+		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object);
298
+		$object->define('test', 'red');
299
+		$out = $object->preprocess('<?php
300 300
 			/**
301 301
 			 * @rest\if test red
302 302
 			 * @rest\whatever
@@ -304,25 +304,25 @@  discard block
 block discarded – undo
304 304
 			 */
305 305
 		');
306 306
 
307
-        $this->assertEquals('<?php
307
+		$this->assertEquals('<?php
308 308
 			/**
309 309
 			 * @!rest\if test red
310 310
 			 * @rest\whatever
311 311
 			 * @!rest\endif
312 312
 			 */
313 313
 		', $out);
314
-    }
315
-
316
-    /**
317
-     * @covers \SwaggerGen\Parser\Php\Preprocessor::define
318
-     * @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess
319
-     */
320
-    public function testPreprocess_Else_Match()
321
-    {
322
-        $object = new \SwaggerGen\Parser\Php\Preprocessor();
323
-        $this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object);
324
-        $object->define('test', 'blue');
325
-        $out = $object->preprocess('<?php
314
+	}
315
+
316
+	/**
317
+	 * @covers \SwaggerGen\Parser\Php\Preprocessor::define
318
+	 * @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess
319
+	 */
320
+	public function testPreprocess_Else_Match()
321
+	{
322
+		$object = new \SwaggerGen\Parser\Php\Preprocessor();
323
+		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object);
324
+		$object->define('test', 'blue');
325
+		$out = $object->preprocess('<?php
326 326
 			/**
327 327
 			 * @rest\if test red
328 328
 			 * @rest\whatever
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
 			 */
333 333
 		');
334 334
 
335
-        $this->assertEquals('<?php
335
+		$this->assertEquals('<?php
336 336
 			/**
337 337
 			 * @!rest\if test red
338 338
 			 * @!rest\whatever
@@ -341,18 +341,18 @@  discard block
 block discarded – undo
341 341
 			 * @!rest\endif
342 342
 			 */
343 343
 		', $out);
344
-    }
345
-
346
-    /**
347
-     * @covers \SwaggerGen\Parser\Php\Preprocessor::define
348
-     * @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess
349
-     */
350
-    public function testPreprocess_Elif_Match()
351
-    {
352
-        $object = new \SwaggerGen\Parser\Php\Preprocessor();
353
-        $this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object);
354
-        $object->define('test', 'blue');
355
-        $out = $object->preprocess('<?php
344
+	}
345
+
346
+	/**
347
+	 * @covers \SwaggerGen\Parser\Php\Preprocessor::define
348
+	 * @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess
349
+	 */
350
+	public function testPreprocess_Elif_Match()
351
+	{
352
+		$object = new \SwaggerGen\Parser\Php\Preprocessor();
353
+		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object);
354
+		$object->define('test', 'blue');
355
+		$out = $object->preprocess('<?php
356 356
 			/**
357 357
 			 * @rest\if test red
358 358
 			 * @rest\whatever
@@ -364,7 +364,7 @@  discard block
 block discarded – undo
364 364
 			 */
365 365
 		');
366 366
 
367
-        $this->assertEquals('<?php
367
+		$this->assertEquals('<?php
368 368
 			/**
369 369
 			 * @!rest\if test red
370 370
 			 * @!rest\whatever
@@ -375,18 +375,18 @@  discard block
 block discarded – undo
375 375
 			 * @!rest\endif
376 376
 			 */
377 377
 		', $out);
378
-    }
379
-
380
-    /**
381
-     * @covers \SwaggerGen\Parser\Php\Preprocessor::define
382
-     * @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess
383
-     */
384
-    public function testPreprocess_Elif_NoValue()
385
-    {
386
-        $object = new \SwaggerGen\Parser\Php\Preprocessor();
387
-        $this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object);
388
-        $object->define('test', 'blue');
389
-        $out = $object->preprocess('<?php
378
+	}
379
+
380
+	/**
381
+	 * @covers \SwaggerGen\Parser\Php\Preprocessor::define
382
+	 * @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess
383
+	 */
384
+	public function testPreprocess_Elif_NoValue()
385
+	{
386
+		$object = new \SwaggerGen\Parser\Php\Preprocessor();
387
+		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object);
388
+		$object->define('test', 'blue');
389
+		$out = $object->preprocess('<?php
390 390
 			/**
391 391
 			 * @rest\if test red
392 392
 			 * @rest\whatever
@@ -398,7 +398,7 @@  discard block
 block discarded – undo
398 398
 			 */
399 399
 		');
400 400
 
401
-        $this->assertEquals('<?php
401
+		$this->assertEquals('<?php
402 402
 			/**
403 403
 			 * @!rest\if test red
404 404
 			 * @!rest\whatever
@@ -409,16 +409,16 @@  discard block
 block discarded – undo
409 409
 			 * @!rest\endif
410 410
 			 */
411 411
 		', $out);
412
-    }
412
+	}
413 413
 
414
-    /**
415
-     * @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess
416
-     */
417
-    public function testPreprocess_Ifdef_AffectPrefixedOnly()
418
-    {
419
-        $object = new \SwaggerGen\Parser\Php\Preprocessor();
420
-        $this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object);
421
-        $out = $object->preprocess('<?php
414
+	/**
415
+	 * @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess
416
+	 */
417
+	public function testPreprocess_Ifdef_AffectPrefixedOnly()
418
+	{
419
+		$object = new \SwaggerGen\Parser\Php\Preprocessor();
420
+		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object);
421
+		$out = $object->preprocess('<?php
422 422
 			/**
423 423
 			 * @rest\ifdef test
424 424
 			 * @rest\whatever
@@ -429,7 +429,7 @@  discard block
 block discarded – undo
429 429
 			 */
430 430
 		');
431 431
 
432
-        $this->assertEquals('<?php
432
+		$this->assertEquals('<?php
433 433
 			/**
434 434
 			 * @!rest\ifdef test
435 435
 			 * @!rest\whatever
@@ -439,20 +439,20 @@  discard block
 block discarded – undo
439 439
 			 * @!rest\endif
440 440
 			 */
441 441
 		', $out);
442
-    }
443
-
444
-    /**
445
-     * @covers \SwaggerGen\Parser\Php\Preprocessor::define
446
-     * @covers \SwaggerGen\Parser\Php\Preprocessor::undefine
447
-     * @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess
448
-     */
449
-    public function testPreprocess_Undefine()
450
-    {
451
-        $object = new \SwaggerGen\Parser\Php\Preprocessor();
452
-        $this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object);
453
-        $object->define('test');
454
-        $object->undefine('test');
455
-        $out = $object->preprocess('<?php
442
+	}
443
+
444
+	/**
445
+	 * @covers \SwaggerGen\Parser\Php\Preprocessor::define
446
+	 * @covers \SwaggerGen\Parser\Php\Preprocessor::undefine
447
+	 * @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess
448
+	 */
449
+	public function testPreprocess_Undefine()
450
+	{
451
+		$object = new \SwaggerGen\Parser\Php\Preprocessor();
452
+		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object);
453
+		$object->define('test');
454
+		$object->undefine('test');
455
+		$out = $object->preprocess('<?php
456 456
 			/**
457 457
 			 * @rest\ifdef test
458 458
 			 * @rest\whatever
@@ -460,27 +460,27 @@  discard block
 block discarded – undo
460 460
 			 */
461 461
 		');
462 462
 
463
-        $this->assertEquals('<?php
463
+		$this->assertEquals('<?php
464 464
 			/**
465 465
 			 * @!rest\ifdef test
466 466
 			 * @!rest\whatever
467 467
 			 * @!rest\endif
468 468
 			 */
469 469
 		', $out);
470
-    }
471
-
472
-    /**
473
-     * @covers \SwaggerGen\Parser\Php\Preprocessor::define
474
-     * @covers \SwaggerGen\Parser\Php\Preprocessor::resetDefines
475
-     * @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess
476
-     */
477
-    public function testPreprocess_ResetDefines()
478
-    {
479
-        $object = new \SwaggerGen\Parser\Php\Preprocessor();
480
-        $this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object);
481
-        $object->define('test');
482
-        $object->resetDefines();
483
-        $out = $object->preprocess('<?php
470
+	}
471
+
472
+	/**
473
+	 * @covers \SwaggerGen\Parser\Php\Preprocessor::define
474
+	 * @covers \SwaggerGen\Parser\Php\Preprocessor::resetDefines
475
+	 * @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess
476
+	 */
477
+	public function testPreprocess_ResetDefines()
478
+	{
479
+		$object = new \SwaggerGen\Parser\Php\Preprocessor();
480
+		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object);
481
+		$object->define('test');
482
+		$object->resetDefines();
483
+		$out = $object->preprocess('<?php
484 484
 			/**
485 485
 			 * @rest\ifdef test
486 486
 			 * @rest\whatever
@@ -488,25 +488,25 @@  discard block
 block discarded – undo
488 488
 			 */
489 489
 		');
490 490
 
491
-        $this->assertEquals('<?php
491
+		$this->assertEquals('<?php
492 492
 			/**
493 493
 			 * @!rest\ifdef test
494 494
 			 * @!rest\whatever
495 495
 			 * @!rest\endif
496 496
 			 */
497 497
 		', $out);
498
-    }
499
-
500
-    /**
501
-     * @covers \SwaggerGen\Parser\Php\Preprocessor::addDefines
502
-     * @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess
503
-     */
504
-    public function testPreprocess_AddDefines()
505
-    {
506
-        $object = new \SwaggerGen\Parser\Php\Preprocessor();
507
-        $this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object);
508
-        $object->addDefines(array('test' => true));
509
-        $out = $object->preprocess('<?php
498
+	}
499
+
500
+	/**
501
+	 * @covers \SwaggerGen\Parser\Php\Preprocessor::addDefines
502
+	 * @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess
503
+	 */
504
+	public function testPreprocess_AddDefines()
505
+	{
506
+		$object = new \SwaggerGen\Parser\Php\Preprocessor();
507
+		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object);
508
+		$object->addDefines(array('test' => true));
509
+		$out = $object->preprocess('<?php
510 510
 			/**
511 511
 			 * @rest\ifdef test
512 512
 			 * @rest\whatever
@@ -514,23 +514,23 @@  discard block
 block discarded – undo
514 514
 			 */
515 515
 		');
516 516
 
517
-        $this->assertEquals('<?php
517
+		$this->assertEquals('<?php
518 518
 			/**
519 519
 			 * @!rest\ifdef test
520 520
 			 * @rest\whatever
521 521
 			 * @!rest\endif
522 522
 			 */
523 523
 		', $out);
524
-    }
524
+	}
525 525
 
526
-    /**
527
-     * @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess
528
-     */
529
-    public function testPreprocess_AlternativePrefix()
530
-    {
531
-        $object = new \SwaggerGen\Parser\Php\Preprocessor('foo');
532
-        $this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object);
533
-        $out = $object->preprocess('<?php
526
+	/**
527
+	 * @covers \SwaggerGen\Parser\Php\Preprocessor::preprocess
528
+	 */
529
+	public function testPreprocess_AlternativePrefix()
530
+	{
531
+		$object = new \SwaggerGen\Parser\Php\Preprocessor('foo');
532
+		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object);
533
+		$out = $object->preprocess('<?php
534 534
 			/**
535 535
 			 * @foo\ifdef test
536 536
 			 * @foo\whatever
@@ -539,7 +539,7 @@  discard block
 block discarded – undo
539 539
 			 */
540 540
 		');
541 541
 
542
-        $this->assertEquals('<?php
542
+		$this->assertEquals('<?php
543 543
 			/**
544 544
 			 * @!foo\ifdef test
545 545
 			 * @!foo\whatever
@@ -547,31 +547,31 @@  discard block
 block discarded – undo
547 547
 			 * @!foo\endif
548 548
 			 */
549 549
 		', $out);
550
-    }
550
+	}
551 551
 
552
-    /**
553
-     * @covers \SwaggerGen\Parser\Php\Preprocessor::define
554
-     * @covers \SwaggerGen\Parser\Php\Preprocessor::preprocessFile
555
-     */
556
-    public function testPreprocessFile()
557
-    {
558
-        $object = new \SwaggerGen\Parser\Php\Preprocessor();
559
-        $this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object);
560
-        $object->define('test');
552
+	/**
553
+	 * @covers \SwaggerGen\Parser\Php\Preprocessor::define
554
+	 * @covers \SwaggerGen\Parser\Php\Preprocessor::preprocessFile
555
+	 */
556
+	public function testPreprocessFile()
557
+	{
558
+		$object = new \SwaggerGen\Parser\Php\Preprocessor();
559
+		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Preprocessor', $object);
560
+		$object->define('test');
561 561
 
562
-        $out = $object->preprocessFile(__DIR__ . '/PreprocessorTest/testPreprocessFile.php');
562
+		$out = $object->preprocessFile(__DIR__ . '/PreprocessorTest/testPreprocessFile.php');
563 563
 
564
-        $this->assertEquals('<?php
564
+		$this->assertEquals('<?php
565 565
 
566 566
 /**
567 567
  * @!rest\ifdef test
568 568
  * @rest\whatever
569 569
  * @!rest\endif
570 570
  */', $out);
571
-    }
571
+	}
572 572
 
573
-    //@todo  preprocess($content) -> mingle with other PHP code
574
-    //@todo  preprocess($content) -> Condition within comment
575
-    //@todo  preprocess($content) -> Condition over comments
576
-    //@todo  preprocess($content) -> Condition over code
573
+	//@todo  preprocess($content) -> mingle with other PHP code
574
+	//@todo  preprocess($content) -> Condition within comment
575
+	//@todo  preprocess($content) -> Condition over comments
576
+	//@todo  preprocess($content) -> Condition over code
577 577
 }
Please login to merge, or discard this patch.
tests/Parser/Text/ParserTest.php 1 patch
Indentation   +186 added lines, -186 removed lines patch added patch discarded remove patch
@@ -5,191 +5,191 @@
 block discarded – undo
5 5
 class ParserTest extends \SwaggerGen_TestCase
6 6
 {
7 7
 
8
-    /**
9
-     * @covers \SwaggerGen\Parser\Text\Parser::__construct
10
-     */
11
-    public function testConstructor_Empty()
12
-    {
13
-        $object = new \SwaggerGen\Parser\Text\Parser();
14
-        $this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object);
15
-    }
16
-
17
-    /**
18
-     * @covers \SwaggerGen\Parser\Text\Parser::__construct
19
-     */
20
-    public function testConstructor_Dirs()
21
-    {
22
-        $this->markTestIncomplete('Not yet implemented.');
23
-    }
24
-
25
-    /**
26
-     * @covers \SwaggerGen\Parser\Text\Parser::addDirs
27
-     */
28
-    public function testAddDirs()
29
-    {
30
-        $this->markTestIncomplete('Not yet implemented.');
31
-    }
32
-
33
-    /**
34
-     * @covers \SwaggerGen\Parser\Text\Parser::parseText
35
-     */
36
-    public function testParseText()
37
-    {
38
-        $object = new \SwaggerGen\Parser\Text\Parser();
39
-        $this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object);
40
-
41
-        $statements = $object->parseText('title Some words');
42
-
43
-        $this->assertCount(1, $statements);
44
-        $this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]);
45
-        $this->assertSame('title', $statements[0]->getCommand());
46
-        $this->assertSame('Some words', $statements[0]->getData());
47
-    }
48
-
49
-    /**
50
-     * @covers \SwaggerGen\Parser\Text\Parser::parseText
51
-     */
52
-    public function testParseText_Whitespace()
53
-    {
54
-        $object = new \SwaggerGen\Parser\Text\Parser();
55
-        $this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object);
56
-
57
-        $statements = $object->parseText(" \t title   \t\t Some words \t ");
58
-
59
-        $this->assertCount(1, $statements);
60
-        $this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]);
61
-        $this->assertSame('title', $statements[0]->getCommand());
62
-        $this->assertSame('Some words', $statements[0]->getData());
63
-    }
64
-
65
-    /**
66
-     * @covers \SwaggerGen\Parser\Text\Parser::parseText
67
-     */
68
-    public function testParseText_Multiple_LF()
69
-    {
70
-        $object = new \SwaggerGen\Parser\Text\Parser();
71
-        $this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object);
72
-
73
-        $statements = $object->parseText("title Some words\nSome Random words");
74
-
75
-        $this->assertCount(2, $statements);
76
-
77
-        $this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]);
78
-        $this->assertSame('title', $statements[0]->getCommand());
79
-        $this->assertSame('Some words', $statements[0]->getData());
80
-
81
-        $this->assertInstanceOf('\SwaggerGen\Statement', $statements[1]);
82
-        $this->assertSame('Some', $statements[1]->getCommand());
83
-        $this->assertSame('Random words', $statements[1]->getData());
84
-    }
85
-
86
-    /**
87
-     * @covers \SwaggerGen\Parser\Text\Parser::parseText
88
-     */
89
-    public function testParseText_Multiple_CR()
90
-    {
91
-        $object = new \SwaggerGen\Parser\Text\Parser();
92
-        $this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object);
93
-
94
-        $statements = $object->parseText("title Some words\rSome Random words");
95
-
96
-        $this->assertCount(2, $statements);
97
-
98
-        $this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]);
99
-        $this->assertSame('title', $statements[0]->getCommand());
100
-        $this->assertSame('Some words', $statements[0]->getData());
101
-
102
-        $this->assertInstanceOf('\SwaggerGen\Statement', $statements[1]);
103
-        $this->assertSame('Some', $statements[1]->getCommand());
104
-        $this->assertSame('Random words', $statements[1]->getData());
105
-    }
106
-
107
-    /**
108
-     * @covers \SwaggerGen\Parser\Text\Parser::parseText
109
-     */
110
-    public function testParseText_Multiple_CRLF()
111
-    {
112
-        $object = new \SwaggerGen\Parser\Text\Parser();
113
-        $this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object);
114
-
115
-        $statements = $object->parseText("title Some words\r\nSome Random words");
116
-
117
-        $this->assertCount(2, $statements);
118
-
119
-        $this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]);
120
-        $this->assertSame('title', $statements[0]->getCommand());
121
-        $this->assertSame('Some words', $statements[0]->getData());
122
-
123
-        $this->assertInstanceOf('\SwaggerGen\Statement', $statements[1]);
124
-        $this->assertSame('Some', $statements[1]->getCommand());
125
-        $this->assertSame('Random words', $statements[1]->getData());
126
-    }
127
-
128
-    /**
129
-     * @covers \SwaggerGen\Parser\Text\Parser::parseText
130
-     */
131
-    public function testParseText_Multiple_BlankLines()
132
-    {
133
-        $object = new \SwaggerGen\Parser\Text\Parser();
134
-        $this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object);
135
-
136
-        $statements = $object->parseText("title Some words\r\n\n\n\rSome Random words");
137
-
138
-        $this->assertCount(2, $statements);
139
-
140
-        $this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]);
141
-        $this->assertSame('title', $statements[0]->getCommand());
142
-        $this->assertSame('Some words', $statements[0]->getData());
143
-
144
-        $this->assertInstanceOf('\SwaggerGen\Statement', $statements[1]);
145
-        $this->assertSame('Some', $statements[1]->getCommand());
146
-        $this->assertSame('Random words', $statements[1]->getData());
147
-    }
148
-
149
-    /**
150
-     * @covers \SwaggerGen\Parser\Text\Parser::parseText
151
-     */
152
-    public function testParseText_Dirs()
153
-    {
154
-        $object = new \SwaggerGen\Parser\Text\Parser();
155
-        $this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object);
156
-
157
-        $statements = $object->parseText("title Some words\r\n\n\n\rSome Random words", array(
158
-            __DIR__ . '/ParserTest/not used by text parser',
159
-        ));
160
-
161
-        $this->assertCount(2, $statements);
162
-
163
-        $this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]);
164
-        $this->assertSame('title', $statements[0]->getCommand());
165
-        $this->assertSame('Some words', $statements[0]->getData());
166
-
167
-        $this->assertInstanceOf('\SwaggerGen\Statement', $statements[1]);
168
-        $this->assertSame('Some', $statements[1]->getCommand());
169
-        $this->assertSame('Random words', $statements[1]->getData());
170
-    }
171
-
172
-    /**
173
-     * @covers \SwaggerGen\Parser\Text\Parser::parse
174
-     */
175
-    public function testParse()
176
-    {
177
-        $object = new \SwaggerGen\Parser\Text\Parser();
178
-        $this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object);
179
-
180
-        $statements = $object->parse(__DIR__ . '/ParserTest/testParse.txt', array(
181
-            __DIR__ . '/ParserTest/not used by text parser',
182
-        ));
183
-
184
-        $this->assertCount(2, $statements);
185
-
186
-        $this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]);
187
-        $this->assertSame('title', $statements[0]->getCommand());
188
-        $this->assertSame('Some words', $statements[0]->getData());
189
-
190
-        $this->assertInstanceOf('\SwaggerGen\Statement', $statements[1]);
191
-        $this->assertSame('Some', $statements[1]->getCommand());
192
-        $this->assertSame('Random words', $statements[1]->getData());
193
-    }
8
+	/**
9
+	 * @covers \SwaggerGen\Parser\Text\Parser::__construct
10
+	 */
11
+	public function testConstructor_Empty()
12
+	{
13
+		$object = new \SwaggerGen\Parser\Text\Parser();
14
+		$this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object);
15
+	}
16
+
17
+	/**
18
+	 * @covers \SwaggerGen\Parser\Text\Parser::__construct
19
+	 */
20
+	public function testConstructor_Dirs()
21
+	{
22
+		$this->markTestIncomplete('Not yet implemented.');
23
+	}
24
+
25
+	/**
26
+	 * @covers \SwaggerGen\Parser\Text\Parser::addDirs
27
+	 */
28
+	public function testAddDirs()
29
+	{
30
+		$this->markTestIncomplete('Not yet implemented.');
31
+	}
32
+
33
+	/**
34
+	 * @covers \SwaggerGen\Parser\Text\Parser::parseText
35
+	 */
36
+	public function testParseText()
37
+	{
38
+		$object = new \SwaggerGen\Parser\Text\Parser();
39
+		$this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object);
40
+
41
+		$statements = $object->parseText('title Some words');
42
+
43
+		$this->assertCount(1, $statements);
44
+		$this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]);
45
+		$this->assertSame('title', $statements[0]->getCommand());
46
+		$this->assertSame('Some words', $statements[0]->getData());
47
+	}
48
+
49
+	/**
50
+	 * @covers \SwaggerGen\Parser\Text\Parser::parseText
51
+	 */
52
+	public function testParseText_Whitespace()
53
+	{
54
+		$object = new \SwaggerGen\Parser\Text\Parser();
55
+		$this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object);
56
+
57
+		$statements = $object->parseText(" \t title   \t\t Some words \t ");
58
+
59
+		$this->assertCount(1, $statements);
60
+		$this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]);
61
+		$this->assertSame('title', $statements[0]->getCommand());
62
+		$this->assertSame('Some words', $statements[0]->getData());
63
+	}
64
+
65
+	/**
66
+	 * @covers \SwaggerGen\Parser\Text\Parser::parseText
67
+	 */
68
+	public function testParseText_Multiple_LF()
69
+	{
70
+		$object = new \SwaggerGen\Parser\Text\Parser();
71
+		$this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object);
72
+
73
+		$statements = $object->parseText("title Some words\nSome Random words");
74
+
75
+		$this->assertCount(2, $statements);
76
+
77
+		$this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]);
78
+		$this->assertSame('title', $statements[0]->getCommand());
79
+		$this->assertSame('Some words', $statements[0]->getData());
80
+
81
+		$this->assertInstanceOf('\SwaggerGen\Statement', $statements[1]);
82
+		$this->assertSame('Some', $statements[1]->getCommand());
83
+		$this->assertSame('Random words', $statements[1]->getData());
84
+	}
85
+
86
+	/**
87
+	 * @covers \SwaggerGen\Parser\Text\Parser::parseText
88
+	 */
89
+	public function testParseText_Multiple_CR()
90
+	{
91
+		$object = new \SwaggerGen\Parser\Text\Parser();
92
+		$this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object);
93
+
94
+		$statements = $object->parseText("title Some words\rSome Random words");
95
+
96
+		$this->assertCount(2, $statements);
97
+
98
+		$this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]);
99
+		$this->assertSame('title', $statements[0]->getCommand());
100
+		$this->assertSame('Some words', $statements[0]->getData());
101
+
102
+		$this->assertInstanceOf('\SwaggerGen\Statement', $statements[1]);
103
+		$this->assertSame('Some', $statements[1]->getCommand());
104
+		$this->assertSame('Random words', $statements[1]->getData());
105
+	}
106
+
107
+	/**
108
+	 * @covers \SwaggerGen\Parser\Text\Parser::parseText
109
+	 */
110
+	public function testParseText_Multiple_CRLF()
111
+	{
112
+		$object = new \SwaggerGen\Parser\Text\Parser();
113
+		$this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object);
114
+
115
+		$statements = $object->parseText("title Some words\r\nSome Random words");
116
+
117
+		$this->assertCount(2, $statements);
118
+
119
+		$this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]);
120
+		$this->assertSame('title', $statements[0]->getCommand());
121
+		$this->assertSame('Some words', $statements[0]->getData());
122
+
123
+		$this->assertInstanceOf('\SwaggerGen\Statement', $statements[1]);
124
+		$this->assertSame('Some', $statements[1]->getCommand());
125
+		$this->assertSame('Random words', $statements[1]->getData());
126
+	}
127
+
128
+	/**
129
+	 * @covers \SwaggerGen\Parser\Text\Parser::parseText
130
+	 */
131
+	public function testParseText_Multiple_BlankLines()
132
+	{
133
+		$object = new \SwaggerGen\Parser\Text\Parser();
134
+		$this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object);
135
+
136
+		$statements = $object->parseText("title Some words\r\n\n\n\rSome Random words");
137
+
138
+		$this->assertCount(2, $statements);
139
+
140
+		$this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]);
141
+		$this->assertSame('title', $statements[0]->getCommand());
142
+		$this->assertSame('Some words', $statements[0]->getData());
143
+
144
+		$this->assertInstanceOf('\SwaggerGen\Statement', $statements[1]);
145
+		$this->assertSame('Some', $statements[1]->getCommand());
146
+		$this->assertSame('Random words', $statements[1]->getData());
147
+	}
148
+
149
+	/**
150
+	 * @covers \SwaggerGen\Parser\Text\Parser::parseText
151
+	 */
152
+	public function testParseText_Dirs()
153
+	{
154
+		$object = new \SwaggerGen\Parser\Text\Parser();
155
+		$this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object);
156
+
157
+		$statements = $object->parseText("title Some words\r\n\n\n\rSome Random words", array(
158
+			__DIR__ . '/ParserTest/not used by text parser',
159
+		));
160
+
161
+		$this->assertCount(2, $statements);
162
+
163
+		$this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]);
164
+		$this->assertSame('title', $statements[0]->getCommand());
165
+		$this->assertSame('Some words', $statements[0]->getData());
166
+
167
+		$this->assertInstanceOf('\SwaggerGen\Statement', $statements[1]);
168
+		$this->assertSame('Some', $statements[1]->getCommand());
169
+		$this->assertSame('Random words', $statements[1]->getData());
170
+	}
171
+
172
+	/**
173
+	 * @covers \SwaggerGen\Parser\Text\Parser::parse
174
+	 */
175
+	public function testParse()
176
+	{
177
+		$object = new \SwaggerGen\Parser\Text\Parser();
178
+		$this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object);
179
+
180
+		$statements = $object->parse(__DIR__ . '/ParserTest/testParse.txt', array(
181
+			__DIR__ . '/ParserTest/not used by text parser',
182
+		));
183
+
184
+		$this->assertCount(2, $statements);
185
+
186
+		$this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]);
187
+		$this->assertSame('title', $statements[0]->getCommand());
188
+		$this->assertSame('Some words', $statements[0]->getData());
189
+
190
+		$this->assertInstanceOf('\SwaggerGen\Statement', $statements[1]);
191
+		$this->assertSame('Some', $statements[1]->getCommand());
192
+		$this->assertSame('Random words', $statements[1]->getData());
193
+	}
194 194
 
195 195
 }
Please login to merge, or discard this patch.
tests/ExceptionTest.php 1 patch
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -3,34 +3,34 @@
 block discarded – undo
3 3
 class ExceptionTest extends SwaggerGen_TestCase
4 4
 {
5 5
 
6
-    /**
7
-     * @covers \SwaggerGen\Exception::__construct
8
-     */
9
-    public function testConstructor0()
10
-    {
11
-        $this->expectException('\SwaggerGen\Exception');
12
-
13
-        throw new \SwaggerGen\Exception('', 0);
14
-    }
15
-
16
-    /**
17
-     * @covers \SwaggerGen\Exception::__construct
18
-     */
19
-    public function testConstructor1()
20
-    {
21
-        $this->expectException('\SwaggerGen\Exception', 'This is a message');
22
-
23
-        throw new \SwaggerGen\Exception('This is a message', 0);
24
-    }
25
-
26
-    /**
27
-     * @covers \SwaggerGen\Exception::__construct
28
-     */
29
-    public function testConstructor2()
30
-    {
31
-        $this->expectException('\SwaggerGen\Exception', 'This is a message', 1234);
32
-
33
-        throw new \SwaggerGen\Exception('This is a message', 1234);
34
-    }
6
+	/**
7
+	 * @covers \SwaggerGen\Exception::__construct
8
+	 */
9
+	public function testConstructor0()
10
+	{
11
+		$this->expectException('\SwaggerGen\Exception');
12
+
13
+		throw new \SwaggerGen\Exception('', 0);
14
+	}
15
+
16
+	/**
17
+	 * @covers \SwaggerGen\Exception::__construct
18
+	 */
19
+	public function testConstructor1()
20
+	{
21
+		$this->expectException('\SwaggerGen\Exception', 'This is a message');
22
+
23
+		throw new \SwaggerGen\Exception('This is a message', 0);
24
+	}
25
+
26
+	/**
27
+	 * @covers \SwaggerGen\Exception::__construct
28
+	 */
29
+	public function testConstructor2()
30
+	{
31
+		$this->expectException('\SwaggerGen\Exception', 'This is a message', 1234);
32
+
33
+		throw new \SwaggerGen\Exception('This is a message', 1234);
34
+	}
35 35
 
36 36
 }
Please login to merge, or discard this patch.
tests/output/global response/source.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -11,15 +11,15 @@
 block discarded – undo
11 11
 class Example
12 12
 {
13 13
 
14
-    /**
15
-     * @rest\endpoint /endpoint/{listid}
16
-     * @rest\method GET Something
17
-     * @rest\param listid
18
-     * @rest\response 200
19
-     */
20
-    public function Dummy()
21
-    {
14
+	/**
15
+	 * @rest\endpoint /endpoint/{listid}
16
+	 * @rest\method GET Something
17
+	 * @rest\param listid
18
+	 * @rest\response 200
19
+	 */
20
+	public function Dummy()
21
+	{
22 22
 
23
-    }
23
+	}
24 24
 
25 25
 }
Please login to merge, or discard this patch.
SwaggerGen/Swagger/Operation.php 1 patch
Indentation   +225 added lines, -225 removed lines patch added patch discarded remove patch
@@ -16,230 +16,230 @@
 block discarded – undo
16 16
 class Operation extends AbstractDocumentableObject
17 17
 {
18 18
 
19
-    private $tags = array();
20
-    private $summary;
21
-    private $description;
22
-    private $consumes = array();
23
-    private $produces = array();
24
-
25
-    /**
26
-     * @var IParameter[]
27
-     */
28
-    private $parameters = array();
29
-    private $responses = array();
30
-    private $schemes = array();
31
-    private $deprecated = false;
32
-    private $security = array();
33
-
34
-    /**
35
-     * @var string
36
-     */
37
-    private $operationId = null;
38
-
39
-    public function getConsumes(): array
40
-    {
41
-        return $this->consumes;
42
-    }
43
-
44
-    /**
45
-     * @param string $summary
46
-     */
47
-    public function __construct(AbstractObject $parent, $summary = null, ?Tag $tag = null)
48
-    {
49
-        parent::__construct($parent);
50
-        $this->summary = $summary;
51
-        if ($tag) {
52
-            $this->tags[] = $tag->getName();
53
-        }
54
-    }
55
-
56
-    /**
57
-     * @param string $command
58
-     * @param string $data
59
-     * @return AbstractObject|boolean
60
-     * @throws Exception
61
-     * @throws Exception
62
-     * @throws Exception
63
-     * @throws Exception
64
-     * @throws Exception
65
-     * @throws Exception
66
-     * @throws Exception
67
-     */
68
-    public function handleCommand($command, $data = null)
69
-    {
70
-        switch (strtolower($command)) {
71
-            // string
72
-            case 'summary':
73
-            case 'description':
74
-                $this->$command = $data;
75
-                return $this;
76
-
77
-            // string[]
78
-            case 'tags':
79
-            case 'schemes':
80
-                $this->$command = array_merge($this->$command, self::wordSplit($data));
81
-                return $this;
82
-
83
-            // MIME[]
84
-            case 'consumes':
85
-            case 'produces':
86
-                $this->$command = array_merge($this->$command, self::translateMimeTypes(self::wordSplit($data)));
87
-                return $this;
88
-
89
-            // boolean
90
-            case 'deprecated':
91
-                $this->deprecated = true;
92
-                return $this;
93
-
94
-            case 'error':
95
-                $code = self::wordShift($data);
96
-                $reasoncode = Response::getCode($code);
97
-                if ($reasoncode === null) {
98
-                    throw new Exception("Invalid error code: '$code'");
99
-                }
100
-                $description = $data;
101
-                $Error = new Error($this, $reasoncode, $description);
102
-                $this->responses[$reasoncode] = $Error;
103
-                return $Error;
104
-
105
-            case 'errors':
106
-                foreach (self::wordSplit($data) as $code) {
107
-                    $reasoncode = Response::getCode($code);
108
-                    if ($reasoncode === null) {
109
-                        throw new Exception("Invalid error code: '$code'");
110
-                    }
111
-                    $this->responses[$reasoncode] = new Error($this, $reasoncode);
112
-                }
113
-                return $this;
114
-
115
-            case 'path':
116
-            case 'query':
117
-            case 'query?':
118
-            case 'header':
119
-            case 'header?':
120
-            case 'form':
121
-            case 'form?':
122
-                $in = rtrim($command, '?');
123
-                $parameter = new Parameter($this, $in, $data, substr($command, -1) !== '?');
124
-                $this->parameters[$parameter->getName()] = $parameter;
125
-                return $parameter;
126
-
127
-            case 'body':
128
-            case 'body?':
129
-                $parameter = new BodyParameter($this, $data, substr($command, -1) !== '?');
130
-                $this->parameters[$parameter->getName()] = $parameter;
131
-                return $parameter;
132
-
133
-            case 'param':
134
-            case 'parameter':
135
-                $parameter = new ParameterReference($this, $data);
136
-                $this->parameters[$parameter->getName()] = $parameter;
137
-                return $this;
138
-
139
-            case 'response':
140
-                $code = self::wordShift($data);
141
-                $reasoncode = Response::getCode($code);
142
-                if ($reasoncode === null) {
143
-                    $reference = $code;
144
-                    $code = self::wordShift($data);
145
-                    $reasoncode = Response::getCode($code);
146
-                    if ($reasoncode === null) {
147
-                        throw new Exception("Invalid response code: '$reference'");
148
-                    }
149
-                    $this->responses[$reasoncode] = new ResponseReference($this, $reference);
150
-                    return $this;
151
-                } else {
152
-                    $definition = self::wordShift($data);
153
-                    $description = $data;
154
-                    $Response = new Response($this, $reasoncode, $definition, $description);
155
-                    $this->responses[$reasoncode] = $Response;
156
-                    return $Response;
157
-                }
158
-
159
-            case 'require':
160
-                $name = self::wordShift($data);
161
-                if (empty($name)) {
162
-                    throw new Exception('Empty security requirement name');
163
-                }
164
-                $scopes = self::wordSplit($data);
165
-                sort($scopes);
166
-                $this->security[] = array(
167
-                    $name => empty($scopes) ? array() : $scopes,
168
-                );
169
-                return $this;
170
-
171
-            case 'id':
172
-                $operationId = self::trim($data);
173
-                if ($this->getSwagger()->hasOperationId($operationId)) {
174
-                    throw new Exception("Duplicate operation id '{$operationId}'");
175
-                }
176
-                $this->operationId = $operationId;
177
-                return $this;
178
-        }
179
-
180
-        return parent::handleCommand($command, $data);
181
-    }
182
-
183
-    /**
184
-     * @throws Exception
185
-     */
186
-    public function toArray()
187
-    {
188
-        if (empty($this->responses)) {
189
-            throw new Exception('No response defined for operation');
190
-        }
191
-        ksort($this->responses);
192
-
193
-        $tags = array_unique($this->tags);
194
-        sort($tags);
195
-
196
-        $schemes = array_unique($this->schemes);
197
-        sort($schemes);
198
-
199
-        $consumes = array_unique($this->consumes);
200
-        sort($consumes);
201
-
202
-        $produces = array_unique($this->produces);
203
-        sort($produces);
204
-
205
-        foreach ($this->security as $security) {
206
-            foreach ($security as $name => $scope) {
207
-                if ($this->getSwagger()->getSecurity($name) === false) {
208
-                    throw new Exception("Required security scheme not defined: '{$name}'");
209
-                }
210
-            }
211
-        }
212
-
213
-        $parameters = $this->parameters ? array_values($this->parameters) : null;
214
-
215
-        return self::arrayFilterNull(array_merge(array(
216
-            'deprecated' => $this->deprecated ? true : null,
217
-            'tags' => $tags,
218
-            'summary' => empty($this->summary) ? null : $this->summary,
219
-            'description' => empty($this->description) ? null : $this->description,
220
-            'operationId' => $this->operationId,
221
-            'consumes' => $consumes,
222
-            'produces' => $produces,
223
-            'parameters' => $parameters ? self::objectsToArray($parameters) : null,
224
-            'schemes' => $schemes,
225
-            'responses' => $this->responses ? self::objectsToArray($this->responses) : null,
226
-            'security' => $this->security,
227
-        ), parent::toArray()));
228
-    }
229
-
230
-    /**
231
-     * Return the operation ID
232
-     *
233
-     * @return string
234
-     */
235
-    public function getId()
236
-    {
237
-        return $this->operationId;
238
-    }
239
-
240
-    public function __toString()
241
-    {
242
-        return __CLASS__ . ' ' . $this->summary;
243
-    }
19
+	private $tags = array();
20
+	private $summary;
21
+	private $description;
22
+	private $consumes = array();
23
+	private $produces = array();
24
+
25
+	/**
26
+	 * @var IParameter[]
27
+	 */
28
+	private $parameters = array();
29
+	private $responses = array();
30
+	private $schemes = array();
31
+	private $deprecated = false;
32
+	private $security = array();
33
+
34
+	/**
35
+	 * @var string
36
+	 */
37
+	private $operationId = null;
38
+
39
+	public function getConsumes(): array
40
+	{
41
+		return $this->consumes;
42
+	}
43
+
44
+	/**
45
+	 * @param string $summary
46
+	 */
47
+	public function __construct(AbstractObject $parent, $summary = null, ?Tag $tag = null)
48
+	{
49
+		parent::__construct($parent);
50
+		$this->summary = $summary;
51
+		if ($tag) {
52
+			$this->tags[] = $tag->getName();
53
+		}
54
+	}
55
+
56
+	/**
57
+	 * @param string $command
58
+	 * @param string $data
59
+	 * @return AbstractObject|boolean
60
+	 * @throws Exception
61
+	 * @throws Exception
62
+	 * @throws Exception
63
+	 * @throws Exception
64
+	 * @throws Exception
65
+	 * @throws Exception
66
+	 * @throws Exception
67
+	 */
68
+	public function handleCommand($command, $data = null)
69
+	{
70
+		switch (strtolower($command)) {
71
+			// string
72
+			case 'summary':
73
+			case 'description':
74
+				$this->$command = $data;
75
+				return $this;
76
+
77
+			// string[]
78
+			case 'tags':
79
+			case 'schemes':
80
+				$this->$command = array_merge($this->$command, self::wordSplit($data));
81
+				return $this;
82
+
83
+			// MIME[]
84
+			case 'consumes':
85
+			case 'produces':
86
+				$this->$command = array_merge($this->$command, self::translateMimeTypes(self::wordSplit($data)));
87
+				return $this;
88
+
89
+			// boolean
90
+			case 'deprecated':
91
+				$this->deprecated = true;
92
+				return $this;
93
+
94
+			case 'error':
95
+				$code = self::wordShift($data);
96
+				$reasoncode = Response::getCode($code);
97
+				if ($reasoncode === null) {
98
+					throw new Exception("Invalid error code: '$code'");
99
+				}
100
+				$description = $data;
101
+				$Error = new Error($this, $reasoncode, $description);
102
+				$this->responses[$reasoncode] = $Error;
103
+				return $Error;
104
+
105
+			case 'errors':
106
+				foreach (self::wordSplit($data) as $code) {
107
+					$reasoncode = Response::getCode($code);
108
+					if ($reasoncode === null) {
109
+						throw new Exception("Invalid error code: '$code'");
110
+					}
111
+					$this->responses[$reasoncode] = new Error($this, $reasoncode);
112
+				}
113
+				return $this;
114
+
115
+			case 'path':
116
+			case 'query':
117
+			case 'query?':
118
+			case 'header':
119
+			case 'header?':
120
+			case 'form':
121
+			case 'form?':
122
+				$in = rtrim($command, '?');
123
+				$parameter = new Parameter($this, $in, $data, substr($command, -1) !== '?');
124
+				$this->parameters[$parameter->getName()] = $parameter;
125
+				return $parameter;
126
+
127
+			case 'body':
128
+			case 'body?':
129
+				$parameter = new BodyParameter($this, $data, substr($command, -1) !== '?');
130
+				$this->parameters[$parameter->getName()] = $parameter;
131
+				return $parameter;
132
+
133
+			case 'param':
134
+			case 'parameter':
135
+				$parameter = new ParameterReference($this, $data);
136
+				$this->parameters[$parameter->getName()] = $parameter;
137
+				return $this;
138
+
139
+			case 'response':
140
+				$code = self::wordShift($data);
141
+				$reasoncode = Response::getCode($code);
142
+				if ($reasoncode === null) {
143
+					$reference = $code;
144
+					$code = self::wordShift($data);
145
+					$reasoncode = Response::getCode($code);
146
+					if ($reasoncode === null) {
147
+						throw new Exception("Invalid response code: '$reference'");
148
+					}
149
+					$this->responses[$reasoncode] = new ResponseReference($this, $reference);
150
+					return $this;
151
+				} else {
152
+					$definition = self::wordShift($data);
153
+					$description = $data;
154
+					$Response = new Response($this, $reasoncode, $definition, $description);
155
+					$this->responses[$reasoncode] = $Response;
156
+					return $Response;
157
+				}
158
+
159
+			case 'require':
160
+				$name = self::wordShift($data);
161
+				if (empty($name)) {
162
+					throw new Exception('Empty security requirement name');
163
+				}
164
+				$scopes = self::wordSplit($data);
165
+				sort($scopes);
166
+				$this->security[] = array(
167
+					$name => empty($scopes) ? array() : $scopes,
168
+				);
169
+				return $this;
170
+
171
+			case 'id':
172
+				$operationId = self::trim($data);
173
+				if ($this->getSwagger()->hasOperationId($operationId)) {
174
+					throw new Exception("Duplicate operation id '{$operationId}'");
175
+				}
176
+				$this->operationId = $operationId;
177
+				return $this;
178
+		}
179
+
180
+		return parent::handleCommand($command, $data);
181
+	}
182
+
183
+	/**
184
+	 * @throws Exception
185
+	 */
186
+	public function toArray()
187
+	{
188
+		if (empty($this->responses)) {
189
+			throw new Exception('No response defined for operation');
190
+		}
191
+		ksort($this->responses);
192
+
193
+		$tags = array_unique($this->tags);
194
+		sort($tags);
195
+
196
+		$schemes = array_unique($this->schemes);
197
+		sort($schemes);
198
+
199
+		$consumes = array_unique($this->consumes);
200
+		sort($consumes);
201
+
202
+		$produces = array_unique($this->produces);
203
+		sort($produces);
204
+
205
+		foreach ($this->security as $security) {
206
+			foreach ($security as $name => $scope) {
207
+				if ($this->getSwagger()->getSecurity($name) === false) {
208
+					throw new Exception("Required security scheme not defined: '{$name}'");
209
+				}
210
+			}
211
+		}
212
+
213
+		$parameters = $this->parameters ? array_values($this->parameters) : null;
214
+
215
+		return self::arrayFilterNull(array_merge(array(
216
+			'deprecated' => $this->deprecated ? true : null,
217
+			'tags' => $tags,
218
+			'summary' => empty($this->summary) ? null : $this->summary,
219
+			'description' => empty($this->description) ? null : $this->description,
220
+			'operationId' => $this->operationId,
221
+			'consumes' => $consumes,
222
+			'produces' => $produces,
223
+			'parameters' => $parameters ? self::objectsToArray($parameters) : null,
224
+			'schemes' => $schemes,
225
+			'responses' => $this->responses ? self::objectsToArray($this->responses) : null,
226
+			'security' => $this->security,
227
+		), parent::toArray()));
228
+	}
229
+
230
+	/**
231
+	 * Return the operation ID
232
+	 *
233
+	 * @return string
234
+	 */
235
+	public function getId()
236
+	{
237
+		return $this->operationId;
238
+	}
239
+
240
+	public function __toString()
241
+	{
242
+		return __CLASS__ . ' ' . $this->summary;
243
+	}
244 244
 
245 245
 }
Please login to merge, or discard this patch.
SwaggerGen/Parser/Php/Parser.php 1 patch
Indentation   +366 added lines, -366 removed lines patch added patch discarded remove patch
@@ -20,376 +20,376 @@
 block discarded – undo
20 20
 class Parser extends Entity\AbstractEntity implements IParser
21 21
 {
22 22
 
23
-    const COMMENT_TAG = 'rest';
23
+	const COMMENT_TAG = 'rest';
24 24
 
25 25
 // transient
26 26
 
27
-    private $current_file = null;
28
-    private $files_queued = [];
29
-    private $files_done = [];
30
-    private $dirs = [];
27
+	private $current_file = null;
28
+	private $files_queued = [];
29
+	private $files_done = [];
30
+	private $dirs = [];
31 31
 // States
32 32
 
33
-    /** @var Statement[] */
34
-    public $statements = [];
35
-
36
-    /**
37
-     * @var Statement[]|null
38
-     */
39
-    private $lastStatements = [];
40
-
41
-    /**
42
-     * @var Entity\ParserClass[]
43
-     */
44
-    public $Classes = [];
45
-
46
-    /**
47
-     * @var Entity\ParserFunction[]
48
-     */
49
-    public $Functions = [];
50
-
51
-    /**
52
-     * @var AbstractPreprocessor
53
-     */
54
-    private $Preprocessor;
55
-
56
-    /**
57
-     * Directories available to all parse calls
58
-     *
59
-     * @var string[]
60
-     */
61
-    protected $common_dirs = [];
62
-
63
-    public function __construct(array $dirs = [])
64
-    {
65
-        foreach ($dirs as $dir) {
66
-            $this->common_dirs[] = realpath($dir);
67
-        }
68
-
69
-        $this->Preprocessor = new Preprocessor(self::COMMENT_TAG);
70
-    }
71
-
72
-    public function addDirs(array $dirs)
73
-    {
74
-        foreach ($dirs as $dir) {
75
-            $this->common_dirs[] = realpath($dir);
76
-        }
77
-    }
78
-
79
-    private function extractStatements()
80
-    {
81
-        // Core comments
82
-        $Statements = $this->statements;
83
-
84
-        // Functions
85
-        foreach ($this->Functions as $Function) {
86
-            if ($Function->hasCommand('method')) {
87
-                $Statements = array_merge($Statements, $Function->Statements);
88
-            }
89
-        }
90
-
91
-        // Classes
92
-        foreach ($this->Classes as $Class) {
93
-            $Statements = array_merge($Statements, $Class->Statements);
94
-            foreach ($Class->Methods as $Method) {
95
-                if ($Method->hasCommand('method')) {
96
-                    $Statements = array_merge($Statements, $Method->Statements);
97
-                }
98
-            }
99
-        }
100
-
101
-        return $Statements;
102
-    }
103
-
104
-    /**
105
-     * @throws Exception
106
-     */
107
-    public function parse($file, array $dirs = [], array $defines = [])
108
-    {
109
-        $this->dirs = $this->common_dirs;
110
-        foreach ($dirs as $dir) {
111
-            $this->dirs[] = realpath($dir);
112
-        }
113
-
114
-        $this->parseFiles(array($file), $defines);
115
-
116
-        // Inherit classes
117
-        foreach ($this->Classes as $Class) {
118
-            $this->inherit($Class);
119
-        }
120
-
121
-        // Expand functions with used and seen functions/methods.
122
-        foreach ($this->Classes as $Class) {
123
-            foreach ($Class->Methods as $Method) {
124
-                $Method->Statements = $this->expand($Method->Statements, $Class);
125
-            }
126
-        }
127
-
128
-        return $this->extractStatements();
129
-    }
130
-
131
-    /**
132
-     * Convert a T_*_COMMENT string to an array of Statements
133
-     * @param array $token
134
-     * @return Statement[]
135
-     */
136
-    public function tokenToStatements($token)
137
-    {
138
-        $comment = $token[1];
139
-        $commentLineNumber = $token[2];
140
-        $commentLines = [];
141
-
142
-        $match = [];
143
-        if (preg_match('~^/\*\*?\s*(.*)\s*\*\/$~sm', $comment, $match) === 1) {
144
-            $lines = preg_split('~\n~', $match[0]);
145
-            foreach ($lines as $line) {
146
-                if (preg_match('~^\s*\*?\s*(.*?)\s*$~', $line, $match) === 1) {
147
-                    if (!empty($match[1])) {
148
-                        $commentLines[] = trim($match[1]);
149
-                    }
150
-                }
151
-            }
152
-        } elseif (preg_match('~^//\s*(.*)$~', $comment, $match) === 1) {
153
-            $commentLines[] = trim($match[1]);
154
-        }
155
-        // to commands
156
-        $match = [];
157
-        $command = null;
158
-        $data = '';
159
-        $commandLineNumber = 0;
160
-        $statements = [];
161
-        foreach ($commentLines as $lineNumber => $line) {
162
-            // If new @-command, store any old and start new
163
-            if ($command !== null && chr(ord($line)) === '@') {
164
-                $statements[] = new Statement($command, $data, $this->current_file, $commentLineNumber + $commandLineNumber);
165
-                $command = null;
166
-                $data = '';
167
-            }
168
-
169
-            if (preg_match('~^@' . preg_quote(self::COMMENT_TAG) . '\\\\([a-z][-a-z]*[?!]?)\\s*(.*)$~', $line, $match) === 1) {
170
-                $command = $match[1];
171
-                $data = $match[2];
172
-                $commandLineNumber = $lineNumber;
173
-            } elseif ($command !== null) {
174
-                if ($lineNumber < count($commentLines) - 1) {
175
-                    $data .= ' ' . $line;
176
-                } else {
177
-                    $data .= preg_replace('~\s*\**\/\s*$~', '', $line);
178
-                }
179
-            }
180
-        }
181
-
182
-        if ($command !== null) {
183
-            $statements[] = new Statement($command, $data, $this->current_file, $commentLineNumber + $commandLineNumber);
184
-        }
185
-
186
-        return $statements;
187
-    }
188
-
189
-    public function queueClass($classname)
190
-    {
191
-        foreach ($this->dirs as $dir) {
192
-            $paths = array(
193
-                $dir . DIRECTORY_SEPARATOR . $classname . '.php',
194
-                $dir . DIRECTORY_SEPARATOR . $classname . '.class.php',
195
-            );
196
-
197
-            foreach ($paths as $path) {
198
-                $realpath = realpath($path);
199
-                if (in_array($realpath, $this->files_done)) {
200
-                    return;
201
-                } elseif (is_file($realpath)) {
202
-                    $this->files_queued[] = $realpath;
203
-                    return;
204
-                }
205
-            }
206
-        }
207
-
208
-        // assume it's a class;
209
-    }
210
-
211
-    /**
212
-     * Add to the queue any classes based on the commands.
213
-     * @param Statement[] $Statements
214
-     */
215
-    public function queueClassesFromComments(array $Statements)
216
-    {
217
-        foreach ($Statements as $Statement) {
218
-            if (in_array($Statement->getCommand(), array('uses', 'see'))) {
219
-                $match = [];
220
-                if (preg_match('~^(\w+)(::|->)?(\w+)?(?:\(\))?$~', $Statement->getData(), $match) === 1) {
221
-                    if (!in_array($match[1], array('self', '$this'))) {
222
-                        $this->queueClass($match[1]);
223
-                    }
224
-                }
225
-            }
226
-        }
227
-    }
228
-
229
-    private function parseTokens($source)
230
-    {
231
-        $mode = null;
232
-        $namespace = '';
233
-
234
-        $tokens = token_get_all($source);
235
-        $token = reset($tokens);
236
-        while ($token) {
237
-            switch ($token[0]) {
238
-                case T_NAMESPACE:
239
-                    $mode = T_NAMESPACE;
240
-                    break;
241
-
242
-                case T_NS_SEPARATOR:
243
-                case T_STRING:
244
-                    if ($mode === T_NAMESPACE) {
245
-                        $namespace .= $token[1];
246
-                    }
247
-                    break;
248
-
249
-                case ';':
250
-                    $mode = null;
251
-                    break;
252
-
253
-                case T_CLASS:
254
-                case T_INTERFACE:
255
-                    $Class = new Entity\ParserClass($this, $tokens, $this->lastStatements);
256
-                    $this->Classes[strtolower($Class->name)] = $Class;
257
-                    $this->lastStatements = null;
258
-                    break;
259
-
260
-                case T_FUNCTION:
261
-                    $Function = new Entity\ParserFunction($this, $tokens, $this->lastStatements);
262
-                    $this->Functions[strtolower($Function->name)] = $Function;
263
-                    $this->lastStatements = null;
264
-                    break;
265
-
266
-                case T_COMMENT:
267
-                    if ($this->lastStatements !== null) {
268
-                        $this->statements = array_merge($this->statements, $this->lastStatements);
269
-                        $this->lastStatements = null;
270
-                    }
271
-                    $Statements = $this->tokenToStatements($token);
272
-                    $this->queueClassesFromComments($Statements);
273
-                    $this->statements = array_merge($this->statements, $Statements);
274
-                    break;
275
-
276
-                case T_DOC_COMMENT:
277
-                    if ($this->lastStatements !== null) {
278
-                        $this->statements = array_merge($this->statements, $this->lastStatements);
279
-                    }
280
-                    $Statements = $this->tokenToStatements($token);
281
-                    $this->queueClassesFromComments($Statements);
282
-                    $this->lastStatements = $Statements;
283
-                    break;
284
-            }
285
-
286
-            $token = next($tokens);
287
-        }
288
-    }
289
-
290
-    private function parseFiles(array $files, array $defines = [])
291
-    {
292
-        $this->files_queued = $files;
293
-
294
-        $index = 0;
295
-        while (($file = array_shift($this->files_queued)) !== null) {
296
-            $file = realpath($file);
297
-
298
-            // @todo Test if this works
299
-            if (in_array($file, $this->files_done)) {
300
-                continue;
301
-            }
302
-
303
-            $this->current_file = $file;
304
-            $this->files_done[] = $file;
305
-            ++$index;
306
-
307
-            $this->Preprocessor->resetDefines();
308
-            $this->Preprocessor->addDefines($defines);
309
-            $source = $this->Preprocessor->preprocessFile($file);
310
-
311
-            $this->parseTokens($source);
312
-
313
-            if ($this->lastStatements !== null) {
314
-                $this->statements = array_merge($this->statements, $this->lastStatements);
315
-                $this->lastStatements = null;
316
-            }
317
-        }
318
-
319
-        $this->current_file = null;
320
-    }
321
-
322
-    /**
323
-     * Inherit the statements
324
-     * @param ParserClass $Class
325
-     */
326
-    private function inherit(Entity\ParserClass $Class)
327
-    {
328
-        $inherits = array_merge(array($Class->extends), $Class->implements);
329
-        while (($inherit = array_shift($inherits)) !== null) {
330
-            if (isset($this->Classes[strtolower($inherit)])) {
331
-                $inheritedClass = $this->Classes[strtolower($inherit)];
332
-                $this->inherit($inheritedClass);
333
-
334
-                foreach ($inheritedClass->Methods as $name => $Method) {
335
-                    if (!isset($Class->Methods[$name])) {
336
-                        $Class->Methods[$name] = $Method;
337
-                    }
338
-                }
339
-            }
340
-        }
341
-    }
342
-
343
-    /**
344
-     * Expands a set of comments with comments of methods referred to by rest\uses statements.
345
-     *
346
-     * @param Statement[] $Statements
347
-     * @return Statement[]
348
-     * @throws Exception
349
-     * @throws Exception
350
-     * @throws Exception
351
-     */
352
-    private function expand(array $Statements, ?ParserClass $Self = null)
353
-    {
354
-        $output = [];
355
-
356
-        $match = [];
357
-        foreach ($Statements as $Statement) {
358
-            if (in_array($Statement->getCommand(), array('uses', 'see'))) {
359
-                if (preg_match('/^((?:\\w+)|\$this)(?:(::|->)(\\w+))?(?:\\(\\))?$/', strtolower($Statement->getData()), $match) === 1) {
360
-                    if (count($match) >= 3) {
361
-                        $Class = null;
362
-                        if (in_array($match[1], array('$this', 'self', 'static'))) {
363
-                            $Class = $Self;
364
-                        } elseif (isset($this->Classes[$match[1]])) {
365
-                            $Class = $this->Classes[$match[1]];
366
-                        }
367
-
368
-                        if ($Class) {
369
-                            if (isset($Class->Methods[$match[3]])) {
370
-                                $Method = $Class->Methods[$match[3]];
371
-                                $Method->Statements = $this->expand($Method->Statements, $Class);
372
-                                $output = array_merge($output, $Method->Statements);
373
-                            } else {
374
-                                throw new Exception("Method '{$match[3]}' for class '{$match[1]}' not found");
375
-                            }
376
-                        } else {
377
-                            throw new Exception("Class '{$match[1]}' not found");
378
-                        }
379
-                    } elseif (isset($this->Functions[$match[1]])) {
380
-                        $Function = $this->Functions[$match[1]];
381
-                        $Function->Statements = $this->expand($Function->Statements);
382
-                        $output = array_merge($output, $Function->Statements);
383
-                    } else {
384
-                        throw new Exception("Function '{$match[1]}' not found");
385
-                    }
386
-                }
387
-            } else {
388
-                $output[] = $Statement;
389
-            }
390
-        }
391
-
392
-        return $output;
393
-    }
33
+	/** @var Statement[] */
34
+	public $statements = [];
35
+
36
+	/**
37
+	 * @var Statement[]|null
38
+	 */
39
+	private $lastStatements = [];
40
+
41
+	/**
42
+	 * @var Entity\ParserClass[]
43
+	 */
44
+	public $Classes = [];
45
+
46
+	/**
47
+	 * @var Entity\ParserFunction[]
48
+	 */
49
+	public $Functions = [];
50
+
51
+	/**
52
+	 * @var AbstractPreprocessor
53
+	 */
54
+	private $Preprocessor;
55
+
56
+	/**
57
+	 * Directories available to all parse calls
58
+	 *
59
+	 * @var string[]
60
+	 */
61
+	protected $common_dirs = [];
62
+
63
+	public function __construct(array $dirs = [])
64
+	{
65
+		foreach ($dirs as $dir) {
66
+			$this->common_dirs[] = realpath($dir);
67
+		}
68
+
69
+		$this->Preprocessor = new Preprocessor(self::COMMENT_TAG);
70
+	}
71
+
72
+	public function addDirs(array $dirs)
73
+	{
74
+		foreach ($dirs as $dir) {
75
+			$this->common_dirs[] = realpath($dir);
76
+		}
77
+	}
78
+
79
+	private function extractStatements()
80
+	{
81
+		// Core comments
82
+		$Statements = $this->statements;
83
+
84
+		// Functions
85
+		foreach ($this->Functions as $Function) {
86
+			if ($Function->hasCommand('method')) {
87
+				$Statements = array_merge($Statements, $Function->Statements);
88
+			}
89
+		}
90
+
91
+		// Classes
92
+		foreach ($this->Classes as $Class) {
93
+			$Statements = array_merge($Statements, $Class->Statements);
94
+			foreach ($Class->Methods as $Method) {
95
+				if ($Method->hasCommand('method')) {
96
+					$Statements = array_merge($Statements, $Method->Statements);
97
+				}
98
+			}
99
+		}
100
+
101
+		return $Statements;
102
+	}
103
+
104
+	/**
105
+	 * @throws Exception
106
+	 */
107
+	public function parse($file, array $dirs = [], array $defines = [])
108
+	{
109
+		$this->dirs = $this->common_dirs;
110
+		foreach ($dirs as $dir) {
111
+			$this->dirs[] = realpath($dir);
112
+		}
113
+
114
+		$this->parseFiles(array($file), $defines);
115
+
116
+		// Inherit classes
117
+		foreach ($this->Classes as $Class) {
118
+			$this->inherit($Class);
119
+		}
120
+
121
+		// Expand functions with used and seen functions/methods.
122
+		foreach ($this->Classes as $Class) {
123
+			foreach ($Class->Methods as $Method) {
124
+				$Method->Statements = $this->expand($Method->Statements, $Class);
125
+			}
126
+		}
127
+
128
+		return $this->extractStatements();
129
+	}
130
+
131
+	/**
132
+	 * Convert a T_*_COMMENT string to an array of Statements
133
+	 * @param array $token
134
+	 * @return Statement[]
135
+	 */
136
+	public function tokenToStatements($token)
137
+	{
138
+		$comment = $token[1];
139
+		$commentLineNumber = $token[2];
140
+		$commentLines = [];
141
+
142
+		$match = [];
143
+		if (preg_match('~^/\*\*?\s*(.*)\s*\*\/$~sm', $comment, $match) === 1) {
144
+			$lines = preg_split('~\n~', $match[0]);
145
+			foreach ($lines as $line) {
146
+				if (preg_match('~^\s*\*?\s*(.*?)\s*$~', $line, $match) === 1) {
147
+					if (!empty($match[1])) {
148
+						$commentLines[] = trim($match[1]);
149
+					}
150
+				}
151
+			}
152
+		} elseif (preg_match('~^//\s*(.*)$~', $comment, $match) === 1) {
153
+			$commentLines[] = trim($match[1]);
154
+		}
155
+		// to commands
156
+		$match = [];
157
+		$command = null;
158
+		$data = '';
159
+		$commandLineNumber = 0;
160
+		$statements = [];
161
+		foreach ($commentLines as $lineNumber => $line) {
162
+			// If new @-command, store any old and start new
163
+			if ($command !== null && chr(ord($line)) === '@') {
164
+				$statements[] = new Statement($command, $data, $this->current_file, $commentLineNumber + $commandLineNumber);
165
+				$command = null;
166
+				$data = '';
167
+			}
168
+
169
+			if (preg_match('~^@' . preg_quote(self::COMMENT_TAG) . '\\\\([a-z][-a-z]*[?!]?)\\s*(.*)$~', $line, $match) === 1) {
170
+				$command = $match[1];
171
+				$data = $match[2];
172
+				$commandLineNumber = $lineNumber;
173
+			} elseif ($command !== null) {
174
+				if ($lineNumber < count($commentLines) - 1) {
175
+					$data .= ' ' . $line;
176
+				} else {
177
+					$data .= preg_replace('~\s*\**\/\s*$~', '', $line);
178
+				}
179
+			}
180
+		}
181
+
182
+		if ($command !== null) {
183
+			$statements[] = new Statement($command, $data, $this->current_file, $commentLineNumber + $commandLineNumber);
184
+		}
185
+
186
+		return $statements;
187
+	}
188
+
189
+	public function queueClass($classname)
190
+	{
191
+		foreach ($this->dirs as $dir) {
192
+			$paths = array(
193
+				$dir . DIRECTORY_SEPARATOR . $classname . '.php',
194
+				$dir . DIRECTORY_SEPARATOR . $classname . '.class.php',
195
+			);
196
+
197
+			foreach ($paths as $path) {
198
+				$realpath = realpath($path);
199
+				if (in_array($realpath, $this->files_done)) {
200
+					return;
201
+				} elseif (is_file($realpath)) {
202
+					$this->files_queued[] = $realpath;
203
+					return;
204
+				}
205
+			}
206
+		}
207
+
208
+		// assume it's a class;
209
+	}
210
+
211
+	/**
212
+	 * Add to the queue any classes based on the commands.
213
+	 * @param Statement[] $Statements
214
+	 */
215
+	public function queueClassesFromComments(array $Statements)
216
+	{
217
+		foreach ($Statements as $Statement) {
218
+			if (in_array($Statement->getCommand(), array('uses', 'see'))) {
219
+				$match = [];
220
+				if (preg_match('~^(\w+)(::|->)?(\w+)?(?:\(\))?$~', $Statement->getData(), $match) === 1) {
221
+					if (!in_array($match[1], array('self', '$this'))) {
222
+						$this->queueClass($match[1]);
223
+					}
224
+				}
225
+			}
226
+		}
227
+	}
228
+
229
+	private function parseTokens($source)
230
+	{
231
+		$mode = null;
232
+		$namespace = '';
233
+
234
+		$tokens = token_get_all($source);
235
+		$token = reset($tokens);
236
+		while ($token) {
237
+			switch ($token[0]) {
238
+				case T_NAMESPACE:
239
+					$mode = T_NAMESPACE;
240
+					break;
241
+
242
+				case T_NS_SEPARATOR:
243
+				case T_STRING:
244
+					if ($mode === T_NAMESPACE) {
245
+						$namespace .= $token[1];
246
+					}
247
+					break;
248
+
249
+				case ';':
250
+					$mode = null;
251
+					break;
252
+
253
+				case T_CLASS:
254
+				case T_INTERFACE:
255
+					$Class = new Entity\ParserClass($this, $tokens, $this->lastStatements);
256
+					$this->Classes[strtolower($Class->name)] = $Class;
257
+					$this->lastStatements = null;
258
+					break;
259
+
260
+				case T_FUNCTION:
261
+					$Function = new Entity\ParserFunction($this, $tokens, $this->lastStatements);
262
+					$this->Functions[strtolower($Function->name)] = $Function;
263
+					$this->lastStatements = null;
264
+					break;
265
+
266
+				case T_COMMENT:
267
+					if ($this->lastStatements !== null) {
268
+						$this->statements = array_merge($this->statements, $this->lastStatements);
269
+						$this->lastStatements = null;
270
+					}
271
+					$Statements = $this->tokenToStatements($token);
272
+					$this->queueClassesFromComments($Statements);
273
+					$this->statements = array_merge($this->statements, $Statements);
274
+					break;
275
+
276
+				case T_DOC_COMMENT:
277
+					if ($this->lastStatements !== null) {
278
+						$this->statements = array_merge($this->statements, $this->lastStatements);
279
+					}
280
+					$Statements = $this->tokenToStatements($token);
281
+					$this->queueClassesFromComments($Statements);
282
+					$this->lastStatements = $Statements;
283
+					break;
284
+			}
285
+
286
+			$token = next($tokens);
287
+		}
288
+	}
289
+
290
+	private function parseFiles(array $files, array $defines = [])
291
+	{
292
+		$this->files_queued = $files;
293
+
294
+		$index = 0;
295
+		while (($file = array_shift($this->files_queued)) !== null) {
296
+			$file = realpath($file);
297
+
298
+			// @todo Test if this works
299
+			if (in_array($file, $this->files_done)) {
300
+				continue;
301
+			}
302
+
303
+			$this->current_file = $file;
304
+			$this->files_done[] = $file;
305
+			++$index;
306
+
307
+			$this->Preprocessor->resetDefines();
308
+			$this->Preprocessor->addDefines($defines);
309
+			$source = $this->Preprocessor->preprocessFile($file);
310
+
311
+			$this->parseTokens($source);
312
+
313
+			if ($this->lastStatements !== null) {
314
+				$this->statements = array_merge($this->statements, $this->lastStatements);
315
+				$this->lastStatements = null;
316
+			}
317
+		}
318
+
319
+		$this->current_file = null;
320
+	}
321
+
322
+	/**
323
+	 * Inherit the statements
324
+	 * @param ParserClass $Class
325
+	 */
326
+	private function inherit(Entity\ParserClass $Class)
327
+	{
328
+		$inherits = array_merge(array($Class->extends), $Class->implements);
329
+		while (($inherit = array_shift($inherits)) !== null) {
330
+			if (isset($this->Classes[strtolower($inherit)])) {
331
+				$inheritedClass = $this->Classes[strtolower($inherit)];
332
+				$this->inherit($inheritedClass);
333
+
334
+				foreach ($inheritedClass->Methods as $name => $Method) {
335
+					if (!isset($Class->Methods[$name])) {
336
+						$Class->Methods[$name] = $Method;
337
+					}
338
+				}
339
+			}
340
+		}
341
+	}
342
+
343
+	/**
344
+	 * Expands a set of comments with comments of methods referred to by rest\uses statements.
345
+	 *
346
+	 * @param Statement[] $Statements
347
+	 * @return Statement[]
348
+	 * @throws Exception
349
+	 * @throws Exception
350
+	 * @throws Exception
351
+	 */
352
+	private function expand(array $Statements, ?ParserClass $Self = null)
353
+	{
354
+		$output = [];
355
+
356
+		$match = [];
357
+		foreach ($Statements as $Statement) {
358
+			if (in_array($Statement->getCommand(), array('uses', 'see'))) {
359
+				if (preg_match('/^((?:\\w+)|\$this)(?:(::|->)(\\w+))?(?:\\(\\))?$/', strtolower($Statement->getData()), $match) === 1) {
360
+					if (count($match) >= 3) {
361
+						$Class = null;
362
+						if (in_array($match[1], array('$this', 'self', 'static'))) {
363
+							$Class = $Self;
364
+						} elseif (isset($this->Classes[$match[1]])) {
365
+							$Class = $this->Classes[$match[1]];
366
+						}
367
+
368
+						if ($Class) {
369
+							if (isset($Class->Methods[$match[3]])) {
370
+								$Method = $Class->Methods[$match[3]];
371
+								$Method->Statements = $this->expand($Method->Statements, $Class);
372
+								$output = array_merge($output, $Method->Statements);
373
+							} else {
374
+								throw new Exception("Method '{$match[3]}' for class '{$match[1]}' not found");
375
+							}
376
+						} else {
377
+							throw new Exception("Class '{$match[1]}' not found");
378
+						}
379
+					} elseif (isset($this->Functions[$match[1]])) {
380
+						$Function = $this->Functions[$match[1]];
381
+						$Function->Statements = $this->expand($Function->Statements);
382
+						$output = array_merge($output, $Function->Statements);
383
+					} else {
384
+						throw new Exception("Function '{$match[1]}' not found");
385
+					}
386
+				}
387
+			} else {
388
+				$output[] = $Statement;
389
+			}
390
+		}
391
+
392
+		return $output;
393
+	}
394 394
 
395 395
 }
Please login to merge, or discard this patch.