Completed
Pull Request — master (#50)
by
unknown
18s
created
SwaggerGen/Swagger/Type/AbstractRegexType.php 1 patch
Upper-Lower-Casing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 
46 46
 		$match = array();
47 47
 		if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_DEFAULT_START . $this->regex . self::REGEX_DEFAULT_END . self::REGEX_END, $definition, $match) !== 1) {
48
-			throw new \SwaggerGen\Exception("Unparseable {$this->format} definition: '{$definition}'");
48
+			throw new \SwaggerGen\Exception("unparseable {$this->format} definition: '{$definition}'");
49 49
 		}
50 50
 
51 51
 		if (strtolower($match[1] !== $this->format)) {
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 		$value = parent::validateDefault($value);
62 62
 		
63 63
 		if (preg_match('/' . $this->pattern . '/', $value) !== 1) {
64
-			throw new \SwaggerGen\Exception("Invalid {$this->format} default value");
64
+			throw new \SwaggerGen\Exception("invalid {$this->format} default value");
65 65
 		}
66 66
 		
67 67
 		return $value;
Please login to merge, or discard this patch.
SwaggerGen/Swagger/Type/StringType.php 1 patch
Upper-Lower-Casing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
 	{
162 162
 		if (empty($value)) {
163 163
 			$type = $this->format ?: ($this->enum ? 'enum' : 'string');
164
-			throw new \SwaggerGen\Exception("Empty {$type} default");
164
+			throw new \SwaggerGen\Exception("empty {$type} default");
165 165
 		}
166 166
 
167 167
 		if (!empty($this->enum) && !in_array($value, $this->enum)) {
@@ -170,12 +170,12 @@  discard block
 block discarded – undo
170 170
 
171 171
 		if ($this->maxLength !== null && mb_strlen($value) > $this->maxLength) {
172 172
 			$type = $this->format ?: ($this->enum ? 'enum' : 'string');
173
-			throw new \SwaggerGen\Exception("Default {$type} length beyond maximum: '{$value}'");
173
+			throw new \SwaggerGen\Exception("default {$type} length beyond maximum: '{$value}'");
174 174
 		}
175 175
 
176 176
 		if ($this->minLength !== null && mb_strlen($value) < $this->minLength) {
177 177
 			$type = $this->format ?: ($this->enum ? 'enum' : 'string');
178
-			throw new \SwaggerGen\Exception("Default {$type} length beyond minimum: '{$value}'");
178
+			throw new \SwaggerGen\Exception("default {$type} length beyond minimum: '{$value}'");
179 179
 		}
180 180
 
181 181
 		return $value;
Please login to merge, or discard this patch.
SwaggerGen/Swagger/Type/AbstractType.php 1 patch
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -175,7 +175,7 @@
 block discarded – undo
175 175
 			return new $class($parent, $definition);
176 176
 		} elseif (isset(self::$classTypes[$format])) {
177 177
 			$type = self::$classTypes[$format];
178
-			$class = "\\SwaggerGen\\Swagger\\Type\\{$type}Type";
178
+			$class = "\\SwaggerGen\\Swagger\\Type\\{$type}type";
179 179
 			return new $class($parent, $definition);
180 180
 		} else {
181 181
 			return new ReferenceObjectType($parent, $definition);
Please login to merge, or discard this patch.
SwaggerGen/Swagger/Parameter.php 1 patch
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -111,7 +111,7 @@
 block discarded – undo
111 111
 			$this->Type = new $class($this, $definition);
112 112
 		} elseif (isset(self::$classTypes[$format])) {
113 113
 			$type = self::$classTypes[$format];
114
-			$class = "\\SwaggerGen\\Swagger\\Type\\{$type}Type";
114
+			$class = "\\SwaggerGen\\Swagger\\Type\\{$type}type";
115 115
 			$this->Type = new $class($this, $definition);
116 116
 		} else {
117 117
 			throw new \SwaggerGen\Exception("Type format not recognized: '{$format}'");
Please login to merge, or discard this patch.
tests/output/docblock comment in method/source.php 2 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -16,10 +16,10 @@
 block discarded – undo
16 16
 	public function Dummy()
17 17
 	{
18 18
 		/**
19
-	* @rest\endpoint /v1/users/{id}
20
-	* @rest\method GET Return a JSON with all the user attributes
21
-	* @rest\path Int id The ID of the User
22
-	* @rest\response 200 User
19
+		 * @rest\endpoint /v1/users/{id}
20
+		 * @rest\method GET Return a JSON with all the user attributes
21
+		 * @rest\path Int id The ID of the User
22
+		 * @rest\response 200 User
23 23
 		 */
24 24
 		$app->get('/v1/users/{id:[0-9]+}', function ($request, $response, $args) {
25 25
 			// ...
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@
 block discarded – undo
21 21
 	* @rest\path Int id The ID of the User
22 22
 	* @rest\response 200 User
23 23
 		 */
24
-		$app->get('/v1/users/{id:[0-9]+}', function ($request, $response, $args) {
24
+		$app->get('/v1/users/{id:[0-9]+}', function($request, $response, $args) {
25 25
 			// ...
26 26
 		});
27 27
 	}
Please login to merge, or discard this patch.
tests/Parser/Php/ParserTest.php 1 patch
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -221,41 +221,41 @@
 block discarded – undo
221 221
 		$this->assertStatement($statements[0], 'title', 'Some words');
222 222
 	}
223 223
 
224
-    /**
225
-     * @covers \SwaggerGen\Parser\Php\Parser::parse
226
-     */
227
-    public function testParse_PropertyReadOnly()
228
-    {
229
-        $object = new \SwaggerGen\Parser\Php\Parser();
230
-        $this->assertInstanceOf('\SwaggerGen\Parser\Php\Parser', $object);
231
-
232
-        $statements = $object->parse(__DIR__ . '/ParserTest/testParse_PropertyReadOnly.php');
233
-
234
-        $this->assertCount(4, $statements);
235
-
236
-        $this->assertStatement($statements[0], 'title', 'Some words');
237
-        $this->assertStatement($statements[1], 'version', '2');
238
-        $this->assertStatement($statements[2], 'definition', 'Foo');
239
-        $this->assertStatement($statements[3], 'property!', 'string bar');
240
-    }
241
-
242
-    /**
243
-     * @covers \SwaggerGen\Parser\Php\Parser::parse
244
-     */
245
-    public function testParse_PropertyOptional()
246
-    {
247
-        $object = new \SwaggerGen\Parser\Php\Parser();
248
-        $this->assertInstanceOf('\SwaggerGen\Parser\Php\Parser', $object);
249
-
250
-        $statements = $object->parse(__DIR__ . '/ParserTest/testParse_PropertyOptional.php');
251
-
252
-        $this->assertCount(4, $statements);
253
-
254
-        $this->assertStatement($statements[0], 'title', 'Some words');
255
-        $this->assertStatement($statements[1], 'version', '2');
256
-        $this->assertStatement($statements[2], 'definition', 'Foo');
257
-        $this->assertStatement($statements[3], 'property?', 'string bar');
258
-    }
224
+	/**
225
+	 * @covers \SwaggerGen\Parser\Php\Parser::parse
226
+	 */
227
+	public function testParse_PropertyReadOnly()
228
+	{
229
+		$object = new \SwaggerGen\Parser\Php\Parser();
230
+		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Parser', $object);
231
+
232
+		$statements = $object->parse(__DIR__ . '/ParserTest/testParse_PropertyReadOnly.php');
233
+
234
+		$this->assertCount(4, $statements);
235
+
236
+		$this->assertStatement($statements[0], 'title', 'Some words');
237
+		$this->assertStatement($statements[1], 'version', '2');
238
+		$this->assertStatement($statements[2], 'definition', 'Foo');
239
+		$this->assertStatement($statements[3], 'property!', 'string bar');
240
+	}
241
+
242
+	/**
243
+	 * @covers \SwaggerGen\Parser\Php\Parser::parse
244
+	 */
245
+	public function testParse_PropertyOptional()
246
+	{
247
+		$object = new \SwaggerGen\Parser\Php\Parser();
248
+		$this->assertInstanceOf('\SwaggerGen\Parser\Php\Parser', $object);
249
+
250
+		$statements = $object->parse(__DIR__ . '/ParserTest/testParse_PropertyOptional.php');
251
+
252
+		$this->assertCount(4, $statements);
253
+
254
+		$this->assertStatement($statements[0], 'title', 'Some words');
255
+		$this->assertStatement($statements[1], 'version', '2');
256
+		$this->assertStatement($statements[2], 'definition', 'Foo');
257
+		$this->assertStatement($statements[3], 'property?', 'string bar');
258
+	}
259 259
 
260 260
 	/**
261 261
 	 * @covers \SwaggerGen\Parser\Php\Parser::parse
Please login to merge, or discard this patch.
SwaggerGen/Swagger/Swagger.php 1 patch
Indentation   +369 added lines, -369 removed lines patch added patch discarded remove patch
@@ -13,374 +13,374 @@
 block discarded – undo
13 13
 class Swagger extends AbstractDocumentableObject
14 14
 {
15 15
 
16
-    private $swagger = '2.0';
17
-    private $host;
18
-    private $basePath;
19
-
20
-    /**
21
-     * @var \SwaggerGen\TypeRegistry
22
-     */
23
-    private $typeRegistry = [];
24
-
25
-    /**
26
-     * @var Info $Info
27
-     */
28
-    private $info;
29
-    private $schemes = [];
30
-    private $consumes = [];
31
-    private $produces = [];
32
-
33
-    /**
34
-     * @var \SwaggerGen\Swagger\Path[] $Paths
35
-     */
36
-    private $paths = [];
37
-
38
-    /**
39
-     * @var \SwaggerGen\Swagger\Schema[] $definitions
40
-     */
41
-    private $definitions = [];
42
-
43
-    /**
44
-     * @var \SwaggerGen\Swagger\IParameter[] $parameters
45
-     */
46
-    private $parameters = [];
47
-
48
-    /**
49
-     * @var \SwaggerGen\Swagger\Response[] $responses
50
-     */
51
-    private $responses = [];
52
-
53
-    /**
54
-     * @var Tag[] $Tags
55
-     */
56
-    private $tags = [];
57
-
58
-    /**
59
-     * Default tag for new endpoints/operations. Set by the api command.
60
-     *
61
-     * @var Tag
62
-     */
63
-    private $defaultTag = null;
64
-    private $securityDefinitions = [];
65
-    private $security = [];
66
-
67
-    /**
68
-     * @inheritDoc
69
-     *
70
-     * @param string                   $host
71
-     * @param string                   $basePath
72
-     * @param \SwaggerGen\TypeRegistry $typeRegistry
73
-     */
74
-    public function __construct($host = null, $basePath = null, $typeRegistry = null)
75
-    {
76
-        parent::__construct(null);
77
-
78
-        $this->host = $host;
79
-        $this->basePath = $basePath;
80
-
81
-        $this->info = new Info($this);
82
-
83
-        $this->typeRegistry = $typeRegistry ? $typeRegistry : new \SwaggerGen\TypeRegistry;
84
-    }
85
-
86
-    /**
87
-     * @inheritDoc
88
-     */
89
-    protected function getSwagger()
90
-    {
91
-        return $this;
92
-    }
93
-
94
-    /**
95
-     * @inheritDoc
96
-     */
97
-    protected function getTypeRegistry()
98
-    {
99
-        return $this->typeRegistry;
100
-    }
101
-
102
-    /**
103
-     * Return all consumes
104
-     *
105
-     * @return string
106
-     * @todo Deprecate in favour of a getConsume($name);
107
-     */
108
-    public function getConsumes()
109
-    {
110
-        return $this->consumes;
111
-    }
112
-
113
-    /**
114
-     * Return the named security if it exists. Otherwise return FALSE
115
-     *
116
-     * @param string $name
117
-     *
118
-     * @return boolean|SecurityScheme
119
-     */
120
-    public function getSecurity($name)
121
-    {
122
-        if (isset($this->securityDefinitions[$name])) {
123
-            return $this->securityDefinitions[$name];
124
-        }
125
-
126
-        return false;
127
-    }
128
-
129
-    /**
130
-     * @param string $command
131
-     * @param string $data
132
-     *
133
-     * @return \SwaggerGen\Swagger\AbstractObject|boolean
134
-     */
135
-    public function handleCommand($command, $data = null)
136
-    {
137
-        switch (strtolower($command)) {
138
-            // pass to Info
139
-            case 'title':
140
-            case 'description':
141
-            case 'version':
142
-            case 'terms': // alias
143
-            case 'tos': // alias
144
-            case 'termsofservice':
145
-            case 'contact':
146
-            case 'license':
147
-                return $this->info->handleCommand($command, $data);
148
-
149
-            // string[]
150
-            case 'scheme':
151
-            case 'schemes':
152
-                $this->schemes = array_unique(array_merge($this->schemes, self::wordSplit($data)));
153
-
154
-                return $this;
155
-
156
-            // MIME[]
157
-            case 'consume':
158
-            case 'consumes':
159
-                $this->consumes = array_merge($this->consumes, self::translateMimeTypes(self::wordSplit($data)));
160
-
161
-                return $this;
162
-
163
-            case 'produce':
164
-            case 'produces':
165
-                $this->produces = array_merge($this->produces, self::translateMimeTypes(self::wordSplit($data)));
166
-
167
-                return $this;
168
-
169
-            case 'model':
170
-            case 'model!':
171
-            case 'definition':
172
-            case 'definition!':
173
-                $name = self::wordShift($data);
174
-                if (empty($name)) {
175
-                    throw new \SwaggerGen\Exception('Missing definition name');
176
-                }
177
-                $typeDef = self::wordShift($data);
178
-                if (empty($typeDef)) {
179
-                    $typeDef = 'object';
180
-                }
181
-
182
-                $definition = new Schema($this, $typeDef);
183
-                if (substr($command, -1) === '!') {
184
-                    $definition->setReadOnly();
185
-                }
186
-                $this->definitions[$name] = $definition;
187
-
188
-                return $definition;
189
-
190
-            case 'path':
191
-            case 'query':
192
-            case 'query?':
193
-            case 'header':
194
-            case 'header?':
195
-            case 'form':
196
-            case 'form?':
197
-                $in = rtrim($command, '?');
198
-                $Parameter = new Parameter($this, $in, $data, substr($command, -1) !== '?');
199
-                $this->parameters[$Parameter->getName()] = $Parameter;
200
-
201
-                return $Parameter;
202
-
203
-            case 'body':
204
-            case 'body?':
205
-                $Parameter = new BodyParameter($this, $data, substr($command, -1) !== '?');
206
-                $this->parameters[$Parameter->getName()] = $Parameter;
207
-
208
-                return $Parameter;
209
-
210
-            case 'response':
211
-                $name = self::wordShift($data);
212
-                $definition = self::wordShift($data);
213
-                $description = $data;
214
-                if (empty($description)) {
215
-                    throw new \SwaggerGen\Exception('Response definition missing description');
216
-                }
217
-                $Response = new Response($this, $name, $definition === 'null' ? null : $definition, $description);
218
-                $this->responses[$name] = $Response;
219
-
220
-                return $Response;
221
-
222
-            case 'api': // alias
223
-            case 'tag':
224
-                $tagname = self::wordShift($data);
225
-                if (empty($tagname)) {
226
-                    throw new \SwaggerGen\Exception('Missing tag name');
227
-                }
228
-
229
-                $Tag = null;
230
-                foreach ($this->tags as $T) {
231
-                    if ($T->getName() === $tagname) {
232
-                        $Tag = $T;
233
-                        break;
234
-                    }
235
-                }
236
-                if (!$Tag) {
237
-                    $Tag = new Tag($this, $tagname, $data);
238
-                    $this->tags[] = $Tag;
239
-                }
240
-
241
-                // backwards compatibility
242
-                if ($command === 'api') {
243
-                    $this->defaultTag = $Tag;
244
-                }
245
-
246
-                return $Tag;
247
-
248
-            case 'endpoint':
249
-                $path = self::wordShift($data);
250
-                if (false === $path) {
251
-                    $path = '/';
252
-                } else if ($path[0] !== '/') {
253
-                    $path = '/' . $path;
254
-                }
255
-
256
-                $Tag = null;
257
-                if (($tagname = self::wordShift($data)) !== false) {
258
-                    foreach ($this->tags as $T) {
259
-                        if (strtolower($T->getName()) === strtolower($tagname)) {
260
-                            $Tag = $T;
261
-                            break;
262
-                        }
263
-                    }
264
-                    if (!$Tag) {
265
-                        $Tag = new Tag($this, $tagname, $data);
266
-                        $this->tags[] = $Tag;
267
-                    }
268
-                }
269
-
270
-                if (!isset($this->paths[$path])) {
271
-                    $this->paths[$path] = new Path($this, $Tag ?: $this->defaultTag);
272
-                }
273
-
274
-                return $this->paths[$path];
275
-
276
-            case 'security':
277
-                $name = self::wordShift($data);
278
-                if (empty($name)) {
279
-                    throw new \SwaggerGen\Exception('Missing security name');
280
-                }
281
-                $type = self::wordShift($data);
282
-                if (empty($type)) {
283
-                    throw new \SwaggerGen\Exception('Missing security type');
284
-                }
285
-                $SecurityScheme = new SecurityScheme($this, $type, $data);
286
-                $this->securityDefinitions[$name] = $SecurityScheme;
287
-
288
-                return $SecurityScheme;
289
-
290
-            case 'require':
291
-                $name = self::wordShift($data);
292
-                if (empty($name)) {
293
-                    throw new \SwaggerGen\Exception('Missing require name');
294
-                }
295
-                $scopes = self::wordSplit($data);
296
-                sort($scopes);
297
-                $this->security[] = [
298
-                    $name => empty($scopes) ? [] : $scopes,
299
-                ];
300
-
301
-                return $this;
302
-        }
303
-
304
-        return parent::handleCommand($command, $data);
305
-    }
306
-
307
-    /**
308
-     * @inheritDoc
309
-     */
310
-    public function toArray()
311
-    {
312
-        if (empty($this->paths)) {
313
-            throw new \SwaggerGen\Exception('No path defined');
314
-        }
315
-
316
-        $schemes = array_unique($this->schemes);
317
-        sort($schemes);
318
-
319
-        $consumes = array_unique($this->consumes);
320
-        sort($consumes);
321
-
322
-        $produces = array_unique($this->produces);
323
-        sort($produces);
324
-
325
-        foreach ($this->security as $security) {
326
-            foreach ($security as $name => $scopes) {
327
-                if (!isset($this->securityDefinitions[$name])) {
328
-                    throw new \SwaggerGen\Exception("Required security scheme not defined: '{$name}'");
329
-                }
330
-            }
331
-        }
332
-
333
-        return self::arrayFilterNull(array_merge([
334
-            'swagger'             => $this->swagger,
335
-            'info'                => $this->info->toArray(),
336
-            'host'                => empty($this->host) ? null : $this->host,
337
-            'basePath'            => empty($this->basePath) ? null : $this->basePath,
338
-            'consumes'            => $consumes,
339
-            'produces'            => $produces,
340
-            'schemes'             => $schemes,
341
-            'paths'               => self::objectsToArray($this->paths),
342
-            'definitions'         => self::objectsToArray($this->definitions),
343
-            'parameters'          => self::objectsToArray($this->parameters),
344
-            'responses'           => self::objectsToArray($this->responses),
345
-            'securityDefinitions' => self::objectsToArray($this->securityDefinitions),
346
-            'security'            => $this->security,
347
-            'tags'                => self::objectsToArray($this->tags),
348
-        ], parent::toArray()));
349
-    }
350
-
351
-    public function __toString()
352
-    {
353
-        return __CLASS__;
354
-    }
355
-
356
-    /**
357
-     * Check if an operation with the given id exists.
358
-     *
359
-     * @param string $operationId
360
-     *
361
-     * @return boolean
362
-     */
363
-    public function hasOperationId($operationId)
364
-    {
365
-        foreach ($this->paths as $path) {
366
-            if ($path->hasOperationId($operationId)) {
367
-                return true;
368
-            }
369
-        }
370
-
371
-        return false;
372
-    }
373
-
374
-    /**
375
-     * Check if a definition with the given name exists
376
-     *
377
-     * @param string $name
378
-     *
379
-     * @return boolean
380
-     */
381
-    public function hasDefinition($name)
382
-    {
383
-        return isset($this->definitions[$name]);
384
-    }
16
+	private $swagger = '2.0';
17
+	private $host;
18
+	private $basePath;
19
+
20
+	/**
21
+	 * @var \SwaggerGen\TypeRegistry
22
+	 */
23
+	private $typeRegistry = [];
24
+
25
+	/**
26
+	 * @var Info $Info
27
+	 */
28
+	private $info;
29
+	private $schemes = [];
30
+	private $consumes = [];
31
+	private $produces = [];
32
+
33
+	/**
34
+	 * @var \SwaggerGen\Swagger\Path[] $Paths
35
+	 */
36
+	private $paths = [];
37
+
38
+	/**
39
+	 * @var \SwaggerGen\Swagger\Schema[] $definitions
40
+	 */
41
+	private $definitions = [];
42
+
43
+	/**
44
+	 * @var \SwaggerGen\Swagger\IParameter[] $parameters
45
+	 */
46
+	private $parameters = [];
47
+
48
+	/**
49
+	 * @var \SwaggerGen\Swagger\Response[] $responses
50
+	 */
51
+	private $responses = [];
52
+
53
+	/**
54
+	 * @var Tag[] $Tags
55
+	 */
56
+	private $tags = [];
57
+
58
+	/**
59
+	 * Default tag for new endpoints/operations. Set by the api command.
60
+	 *
61
+	 * @var Tag
62
+	 */
63
+	private $defaultTag = null;
64
+	private $securityDefinitions = [];
65
+	private $security = [];
66
+
67
+	/**
68
+	 * @inheritDoc
69
+	 *
70
+	 * @param string                   $host
71
+	 * @param string                   $basePath
72
+	 * @param \SwaggerGen\TypeRegistry $typeRegistry
73
+	 */
74
+	public function __construct($host = null, $basePath = null, $typeRegistry = null)
75
+	{
76
+		parent::__construct(null);
77
+
78
+		$this->host = $host;
79
+		$this->basePath = $basePath;
80
+
81
+		$this->info = new Info($this);
82
+
83
+		$this->typeRegistry = $typeRegistry ? $typeRegistry : new \SwaggerGen\TypeRegistry;
84
+	}
85
+
86
+	/**
87
+	 * @inheritDoc
88
+	 */
89
+	protected function getSwagger()
90
+	{
91
+		return $this;
92
+	}
93
+
94
+	/**
95
+	 * @inheritDoc
96
+	 */
97
+	protected function getTypeRegistry()
98
+	{
99
+		return $this->typeRegistry;
100
+	}
101
+
102
+	/**
103
+	 * Return all consumes
104
+	 *
105
+	 * @return string
106
+	 * @todo Deprecate in favour of a getConsume($name);
107
+	 */
108
+	public function getConsumes()
109
+	{
110
+		return $this->consumes;
111
+	}
112
+
113
+	/**
114
+	 * Return the named security if it exists. Otherwise return FALSE
115
+	 *
116
+	 * @param string $name
117
+	 *
118
+	 * @return boolean|SecurityScheme
119
+	 */
120
+	public function getSecurity($name)
121
+	{
122
+		if (isset($this->securityDefinitions[$name])) {
123
+			return $this->securityDefinitions[$name];
124
+		}
125
+
126
+		return false;
127
+	}
128
+
129
+	/**
130
+	 * @param string $command
131
+	 * @param string $data
132
+	 *
133
+	 * @return \SwaggerGen\Swagger\AbstractObject|boolean
134
+	 */
135
+	public function handleCommand($command, $data = null)
136
+	{
137
+		switch (strtolower($command)) {
138
+			// pass to Info
139
+			case 'title':
140
+			case 'description':
141
+			case 'version':
142
+			case 'terms': // alias
143
+			case 'tos': // alias
144
+			case 'termsofservice':
145
+			case 'contact':
146
+			case 'license':
147
+				return $this->info->handleCommand($command, $data);
148
+
149
+			// string[]
150
+			case 'scheme':
151
+			case 'schemes':
152
+				$this->schemes = array_unique(array_merge($this->schemes, self::wordSplit($data)));
153
+
154
+				return $this;
155
+
156
+			// MIME[]
157
+			case 'consume':
158
+			case 'consumes':
159
+				$this->consumes = array_merge($this->consumes, self::translateMimeTypes(self::wordSplit($data)));
160
+
161
+				return $this;
162
+
163
+			case 'produce':
164
+			case 'produces':
165
+				$this->produces = array_merge($this->produces, self::translateMimeTypes(self::wordSplit($data)));
166
+
167
+				return $this;
168
+
169
+			case 'model':
170
+			case 'model!':
171
+			case 'definition':
172
+			case 'definition!':
173
+				$name = self::wordShift($data);
174
+				if (empty($name)) {
175
+					throw new \SwaggerGen\Exception('Missing definition name');
176
+				}
177
+				$typeDef = self::wordShift($data);
178
+				if (empty($typeDef)) {
179
+					$typeDef = 'object';
180
+				}
181
+
182
+				$definition = new Schema($this, $typeDef);
183
+				if (substr($command, -1) === '!') {
184
+					$definition->setReadOnly();
185
+				}
186
+				$this->definitions[$name] = $definition;
187
+
188
+				return $definition;
189
+
190
+			case 'path':
191
+			case 'query':
192
+			case 'query?':
193
+			case 'header':
194
+			case 'header?':
195
+			case 'form':
196
+			case 'form?':
197
+				$in = rtrim($command, '?');
198
+				$Parameter = new Parameter($this, $in, $data, substr($command, -1) !== '?');
199
+				$this->parameters[$Parameter->getName()] = $Parameter;
200
+
201
+				return $Parameter;
202
+
203
+			case 'body':
204
+			case 'body?':
205
+				$Parameter = new BodyParameter($this, $data, substr($command, -1) !== '?');
206
+				$this->parameters[$Parameter->getName()] = $Parameter;
207
+
208
+				return $Parameter;
209
+
210
+			case 'response':
211
+				$name = self::wordShift($data);
212
+				$definition = self::wordShift($data);
213
+				$description = $data;
214
+				if (empty($description)) {
215
+					throw new \SwaggerGen\Exception('Response definition missing description');
216
+				}
217
+				$Response = new Response($this, $name, $definition === 'null' ? null : $definition, $description);
218
+				$this->responses[$name] = $Response;
219
+
220
+				return $Response;
221
+
222
+			case 'api': // alias
223
+			case 'tag':
224
+				$tagname = self::wordShift($data);
225
+				if (empty($tagname)) {
226
+					throw new \SwaggerGen\Exception('Missing tag name');
227
+				}
228
+
229
+				$Tag = null;
230
+				foreach ($this->tags as $T) {
231
+					if ($T->getName() === $tagname) {
232
+						$Tag = $T;
233
+						break;
234
+					}
235
+				}
236
+				if (!$Tag) {
237
+					$Tag = new Tag($this, $tagname, $data);
238
+					$this->tags[] = $Tag;
239
+				}
240
+
241
+				// backwards compatibility
242
+				if ($command === 'api') {
243
+					$this->defaultTag = $Tag;
244
+				}
245
+
246
+				return $Tag;
247
+
248
+			case 'endpoint':
249
+				$path = self::wordShift($data);
250
+				if (false === $path) {
251
+					$path = '/';
252
+				} else if ($path[0] !== '/') {
253
+					$path = '/' . $path;
254
+				}
255
+
256
+				$Tag = null;
257
+				if (($tagname = self::wordShift($data)) !== false) {
258
+					foreach ($this->tags as $T) {
259
+						if (strtolower($T->getName()) === strtolower($tagname)) {
260
+							$Tag = $T;
261
+							break;
262
+						}
263
+					}
264
+					if (!$Tag) {
265
+						$Tag = new Tag($this, $tagname, $data);
266
+						$this->tags[] = $Tag;
267
+					}
268
+				}
269
+
270
+				if (!isset($this->paths[$path])) {
271
+					$this->paths[$path] = new Path($this, $Tag ?: $this->defaultTag);
272
+				}
273
+
274
+				return $this->paths[$path];
275
+
276
+			case 'security':
277
+				$name = self::wordShift($data);
278
+				if (empty($name)) {
279
+					throw new \SwaggerGen\Exception('Missing security name');
280
+				}
281
+				$type = self::wordShift($data);
282
+				if (empty($type)) {
283
+					throw new \SwaggerGen\Exception('Missing security type');
284
+				}
285
+				$SecurityScheme = new SecurityScheme($this, $type, $data);
286
+				$this->securityDefinitions[$name] = $SecurityScheme;
287
+
288
+				return $SecurityScheme;
289
+
290
+			case 'require':
291
+				$name = self::wordShift($data);
292
+				if (empty($name)) {
293
+					throw new \SwaggerGen\Exception('Missing require name');
294
+				}
295
+				$scopes = self::wordSplit($data);
296
+				sort($scopes);
297
+				$this->security[] = [
298
+					$name => empty($scopes) ? [] : $scopes,
299
+				];
300
+
301
+				return $this;
302
+		}
303
+
304
+		return parent::handleCommand($command, $data);
305
+	}
306
+
307
+	/**
308
+	 * @inheritDoc
309
+	 */
310
+	public function toArray()
311
+	{
312
+		if (empty($this->paths)) {
313
+			throw new \SwaggerGen\Exception('No path defined');
314
+		}
315
+
316
+		$schemes = array_unique($this->schemes);
317
+		sort($schemes);
318
+
319
+		$consumes = array_unique($this->consumes);
320
+		sort($consumes);
321
+
322
+		$produces = array_unique($this->produces);
323
+		sort($produces);
324
+
325
+		foreach ($this->security as $security) {
326
+			foreach ($security as $name => $scopes) {
327
+				if (!isset($this->securityDefinitions[$name])) {
328
+					throw new \SwaggerGen\Exception("Required security scheme not defined: '{$name}'");
329
+				}
330
+			}
331
+		}
332
+
333
+		return self::arrayFilterNull(array_merge([
334
+			'swagger'             => $this->swagger,
335
+			'info'                => $this->info->toArray(),
336
+			'host'                => empty($this->host) ? null : $this->host,
337
+			'basePath'            => empty($this->basePath) ? null : $this->basePath,
338
+			'consumes'            => $consumes,
339
+			'produces'            => $produces,
340
+			'schemes'             => $schemes,
341
+			'paths'               => self::objectsToArray($this->paths),
342
+			'definitions'         => self::objectsToArray($this->definitions),
343
+			'parameters'          => self::objectsToArray($this->parameters),
344
+			'responses'           => self::objectsToArray($this->responses),
345
+			'securityDefinitions' => self::objectsToArray($this->securityDefinitions),
346
+			'security'            => $this->security,
347
+			'tags'                => self::objectsToArray($this->tags),
348
+		], parent::toArray()));
349
+	}
350
+
351
+	public function __toString()
352
+	{
353
+		return __CLASS__;
354
+	}
355
+
356
+	/**
357
+	 * Check if an operation with the given id exists.
358
+	 *
359
+	 * @param string $operationId
360
+	 *
361
+	 * @return boolean
362
+	 */
363
+	public function hasOperationId($operationId)
364
+	{
365
+		foreach ($this->paths as $path) {
366
+			if ($path->hasOperationId($operationId)) {
367
+				return true;
368
+			}
369
+		}
370
+
371
+		return false;
372
+	}
373
+
374
+	/**
375
+	 * Check if a definition with the given name exists
376
+	 *
377
+	 * @param string $name
378
+	 *
379
+	 * @return boolean
380
+	 */
381
+	public function hasDefinition($name)
382
+	{
383
+		return isset($this->definitions[$name]);
384
+	}
385 385
 
386 386
 }
Please login to merge, or discard this patch.
tests/Parser/Text/PreprocessorTest.php 1 patch
Indentation   +223 added lines, -223 removed lines patch added patch discarded remove patch
@@ -5,129 +5,129 @@  discard block
 block discarded – undo
5 5
 class PreprocessorTest extends \SwaggerGen_TestCase
6 6
 {
7 7
 
8
-    /**
9
-     * @covers \SwaggerGen\Parser\Text\Preprocessor::__construct
10
-     */
11
-    public function testConstructor_Empty()
12
-    {
13
-        $object = new \SwaggerGen\Parser\Text\Preprocessor();
14
-        $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
15
-    }
16
-
17
-    /**
18
-     * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
19
-     */
20
-    public function testPreprocess_Ifdef_NotDefined()
21
-    {
22
-        $object = new \SwaggerGen\Parser\Text\Preprocessor();
23
-        $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
24
-        $out = $object->preprocess('
8
+	/**
9
+	 * @covers \SwaggerGen\Parser\Text\Preprocessor::__construct
10
+	 */
11
+	public function testConstructor_Empty()
12
+	{
13
+		$object = new \SwaggerGen\Parser\Text\Preprocessor();
14
+		$this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
15
+	}
16
+
17
+	/**
18
+	 * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
19
+	 */
20
+	public function testPreprocess_Ifdef_NotDefined()
21
+	{
22
+		$object = new \SwaggerGen\Parser\Text\Preprocessor();
23
+		$this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
24
+		$out = $object->preprocess('
25 25
 			ifdef test
26 26
 			whatever
27 27
 			endif
28 28
 		');
29 29
 
30
-        $this->assertEquals('
30
+		$this->assertEquals('
31 31
 
32 32
 
33 33
 
34 34
 		', $out);
35
-    }
36
-
37
-    /**
38
-     * @covers \SwaggerGen\Parser\Text\Preprocessor::define
39
-     * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
40
-     */
41
-    public function testPreprocess_Ifdef_Defined()
42
-    {
43
-        $object = new \SwaggerGen\Parser\Text\Preprocessor();
44
-        $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
45
-        $object->define('test');
46
-        $out = $object->preprocess('
35
+	}
36
+
37
+	/**
38
+	 * @covers \SwaggerGen\Parser\Text\Preprocessor::define
39
+	 * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
40
+	 */
41
+	public function testPreprocess_Ifdef_Defined()
42
+	{
43
+		$object = new \SwaggerGen\Parser\Text\Preprocessor();
44
+		$this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
45
+		$object->define('test');
46
+		$out = $object->preprocess('
47 47
 			ifdef test
48 48
 			whatever
49 49
 			endif
50 50
 		');
51 51
 
52
-        $this->assertEquals('
52
+		$this->assertEquals('
53 53
 
54 54
 			whatever
55 55
 
56 56
 		', $out);
57
-    }
58
-
59
-    /**
60
-     * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
61
-     */
62
-    public function testPreprocess_Ifndef_NotDefined()
63
-    {
64
-        $object = new \SwaggerGen\Parser\Text\Preprocessor();
65
-        $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
66
-        $out = $object->preprocess('
57
+	}
58
+
59
+	/**
60
+	 * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
61
+	 */
62
+	public function testPreprocess_Ifndef_NotDefined()
63
+	{
64
+		$object = new \SwaggerGen\Parser\Text\Preprocessor();
65
+		$this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
66
+		$out = $object->preprocess('
67 67
 			ifndef test
68 68
 			whatever
69 69
 			endif
70 70
 		');
71 71
 
72
-        $this->assertEquals('
72
+		$this->assertEquals('
73 73
 
74 74
 			whatever
75 75
 
76 76
 		', $out);
77
-    }
78
-
79
-    /**
80
-     * @covers \SwaggerGen\Parser\Text\Preprocessor::define
81
-     * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
82
-     */
83
-    public function testPreprocess_Ifndef_Defined()
84
-    {
85
-        $object = new \SwaggerGen\Parser\Text\Preprocessor();
86
-        $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
87
-        $object->define('test');
88
-        $out = $object->preprocess('
77
+	}
78
+
79
+	/**
80
+	 * @covers \SwaggerGen\Parser\Text\Preprocessor::define
81
+	 * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
82
+	 */
83
+	public function testPreprocess_Ifndef_Defined()
84
+	{
85
+		$object = new \SwaggerGen\Parser\Text\Preprocessor();
86
+		$this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
87
+		$object->define('test');
88
+		$out = $object->preprocess('
89 89
 			ifndef test
90 90
 			whatever
91 91
 			endif
92 92
 		');
93 93
 
94
-        $this->assertEquals('
94
+		$this->assertEquals('
95 95
 
96 96
 
97 97
 
98 98
 		', $out);
99
-    }
100
-
101
-    /**
102
-     * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
103
-     */
104
-    public function testPreprocess_Define()
105
-    {
106
-        $object = new \SwaggerGen\Parser\Text\Preprocessor();
107
-        $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
108
-        $out = $object->preprocess('
99
+	}
100
+
101
+	/**
102
+	 * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
103
+	 */
104
+	public function testPreprocess_Define()
105
+	{
106
+		$object = new \SwaggerGen\Parser\Text\Preprocessor();
107
+		$this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
108
+		$out = $object->preprocess('
109 109
 			define test
110 110
 			ifndef test
111 111
 			whatever
112 112
 			endif
113 113
 		');
114 114
 
115
-        $this->assertEquals('
115
+		$this->assertEquals('
116 116
 
117 117
 
118 118
 
119 119
 
120 120
 		', $out);
121
-    }
122
-
123
-    /**
124
-     * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
125
-     */
126
-    public function testPreprocess_Undef()
127
-    {
128
-        $object = new \SwaggerGen\Parser\Text\Preprocessor();
129
-        $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
130
-        $out = $object->preprocess('
121
+	}
122
+
123
+	/**
124
+	 * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
125
+	 */
126
+	public function testPreprocess_Undef()
127
+	{
128
+		$object = new \SwaggerGen\Parser\Text\Preprocessor();
129
+		$this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
130
+		$out = $object->preprocess('
131 131
 			define test
132 132
 			undef test
133 133
 			ifdef test
@@ -135,133 +135,133 @@  discard block
 block discarded – undo
135 135
 			endif
136 136
 		');
137 137
 
138
-        $this->assertEquals('
138
+		$this->assertEquals('
139 139
 
140 140
 
141 141
 
142 142
 
143 143
 
144 144
 		', $out);
145
-    }
146
-
147
-    /**
148
-     * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
149
-     */
150
-    public function testPreprocess_If_NotDefined()
151
-    {
152
-        $object = new \SwaggerGen\Parser\Text\Preprocessor();
153
-        $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
154
-        $out = $object->preprocess('
145
+	}
146
+
147
+	/**
148
+	 * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
149
+	 */
150
+	public function testPreprocess_If_NotDefined()
151
+	{
152
+		$object = new \SwaggerGen\Parser\Text\Preprocessor();
153
+		$this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
154
+		$out = $object->preprocess('
155 155
 			if test red
156 156
 			whatever
157 157
 			endif
158 158
 		');
159 159
 
160
-        $this->assertEquals('
160
+		$this->assertEquals('
161 161
 
162 162
 
163 163
 
164 164
 		', $out);
165
-    }
166
-
167
-    /**
168
-     * @covers \SwaggerGen\Parser\Text\Preprocessor::define
169
-     * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
170
-     */
171
-    public function testPreprocess_If_AnyValue()
172
-    {
173
-        $object = new \SwaggerGen\Parser\Text\Preprocessor();
174
-        $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
175
-        $object->define('test', 'green');
176
-        $out = $object->preprocess('
165
+	}
166
+
167
+	/**
168
+	 * @covers \SwaggerGen\Parser\Text\Preprocessor::define
169
+	 * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
170
+	 */
171
+	public function testPreprocess_If_AnyValue()
172
+	{
173
+		$object = new \SwaggerGen\Parser\Text\Preprocessor();
174
+		$this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
175
+		$object->define('test', 'green');
176
+		$out = $object->preprocess('
177 177
 			if test
178 178
 			whatever
179 179
 			endif
180 180
 		');
181 181
 
182
-        $this->assertEquals('
182
+		$this->assertEquals('
183 183
 
184 184
 			whatever
185 185
 
186 186
 		', $out);
187
-    }
188
-
189
-    /**
190
-     * @covers \SwaggerGen\Parser\Text\Preprocessor::define
191
-     * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
192
-     */
193
-    public function testPreprocess_If_NoValue()
194
-    {
195
-        $object = new \SwaggerGen\Parser\Text\Preprocessor();
196
-        $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
197
-        $object->define('test');
198
-        $out = $object->preprocess('
187
+	}
188
+
189
+	/**
190
+	 * @covers \SwaggerGen\Parser\Text\Preprocessor::define
191
+	 * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
192
+	 */
193
+	public function testPreprocess_If_NoValue()
194
+	{
195
+		$object = new \SwaggerGen\Parser\Text\Preprocessor();
196
+		$this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
197
+		$object->define('test');
198
+		$out = $object->preprocess('
199 199
 			if test red
200 200
 			whatever
201 201
 			endif
202 202
 		');
203 203
 
204
-        $this->assertEquals('
204
+		$this->assertEquals('
205 205
 
206 206
 
207 207
 
208 208
 		', $out);
209
-    }
210
-
211
-    /**
212
-     * @covers \SwaggerGen\Parser\Text\Preprocessor::define
213
-     * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
214
-     */
215
-    public function testPreprocess_If_Mismatch()
216
-    {
217
-        $object = new \SwaggerGen\Parser\Text\Preprocessor();
218
-        $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
219
-        $object->define('test', 'green');
220
-        $out = $object->preprocess('
209
+	}
210
+
211
+	/**
212
+	 * @covers \SwaggerGen\Parser\Text\Preprocessor::define
213
+	 * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
214
+	 */
215
+	public function testPreprocess_If_Mismatch()
216
+	{
217
+		$object = new \SwaggerGen\Parser\Text\Preprocessor();
218
+		$this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
219
+		$object->define('test', 'green');
220
+		$out = $object->preprocess('
221 221
 			if test red
222 222
 			whatever
223 223
 			endif
224 224
 		');
225 225
 
226
-        $this->assertEquals('
226
+		$this->assertEquals('
227 227
 
228 228
 
229 229
 
230 230
 		', $out);
231
-    }
232
-
233
-    /**
234
-     * @covers \SwaggerGen\Parser\Text\Preprocessor::define
235
-     * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
236
-     */
237
-    public function testPreprocess_If_Match()
238
-    {
239
-        $object = new \SwaggerGen\Parser\Text\Preprocessor();
240
-        $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
241
-        $object->define('test', 'red');
242
-        $out = $object->preprocess('
231
+	}
232
+
233
+	/**
234
+	 * @covers \SwaggerGen\Parser\Text\Preprocessor::define
235
+	 * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
236
+	 */
237
+	public function testPreprocess_If_Match()
238
+	{
239
+		$object = new \SwaggerGen\Parser\Text\Preprocessor();
240
+		$this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
241
+		$object->define('test', 'red');
242
+		$out = $object->preprocess('
243 243
 			if test red
244 244
 			whatever
245 245
 			endif
246 246
 		');
247 247
 
248
-        $this->assertEquals('
248
+		$this->assertEquals('
249 249
 
250 250
 			whatever
251 251
 
252 252
 		', $out);
253
-    }
254
-
255
-    /**
256
-     * @covers \SwaggerGen\Parser\Text\Preprocessor::define
257
-     * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
258
-     */
259
-    public function testPreprocess_Else_Match()
260
-    {
261
-        $object = new \SwaggerGen\Parser\Text\Preprocessor();
262
-        $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
263
-        $object->define('test', 'blue');
264
-        $out = $object->preprocess('
253
+	}
254
+
255
+	/**
256
+	 * @covers \SwaggerGen\Parser\Text\Preprocessor::define
257
+	 * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
258
+	 */
259
+	public function testPreprocess_Else_Match()
260
+	{
261
+		$object = new \SwaggerGen\Parser\Text\Preprocessor();
262
+		$this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
263
+		$object->define('test', 'blue');
264
+		$out = $object->preprocess('
265 265
 			if test red
266 266
 			whatever
267 267
 			else
@@ -269,25 +269,25 @@  discard block
 block discarded – undo
269 269
 			endif
270 270
 		');
271 271
 
272
-        $this->assertEquals('
272
+		$this->assertEquals('
273 273
 
274 274
 
275 275
 
276 276
 			otherwise
277 277
 
278 278
 		', $out);
279
-    }
280
-
281
-    /**
282
-     * @covers \SwaggerGen\Parser\Text\Preprocessor::define
283
-     * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
284
-     */
285
-    public function testPreprocess_Elif_Match()
286
-    {
287
-        $object = new \SwaggerGen\Parser\Text\Preprocessor();
288
-        $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
289
-        $object->define('test', 'blue');
290
-        $out = $object->preprocess('
279
+	}
280
+
281
+	/**
282
+	 * @covers \SwaggerGen\Parser\Text\Preprocessor::define
283
+	 * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
284
+	 */
285
+	public function testPreprocess_Elif_Match()
286
+	{
287
+		$object = new \SwaggerGen\Parser\Text\Preprocessor();
288
+		$this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
289
+		$object->define('test', 'blue');
290
+		$out = $object->preprocess('
291 291
 			if test red
292 292
 			whatever
293 293
 			elif test green
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
 			endif
298 298
 		');
299 299
 
300
-        $this->assertEquals('
300
+		$this->assertEquals('
301 301
 
302 302
 
303 303
 
@@ -306,18 +306,18 @@  discard block
 block discarded – undo
306 306
 			otherwise
307 307
 
308 308
 		', $out);
309
-    }
310
-
311
-    /**
312
-     * @covers \SwaggerGen\Parser\Text\Preprocessor::define
313
-     * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
314
-     */
315
-    public function testPreprocess_Elif_NoValue()
316
-    {
317
-        $object = new \SwaggerGen\Parser\Text\Preprocessor();
318
-        $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
319
-        $object->define('test', 'blue');
320
-        $out = $object->preprocess('
309
+	}
310
+
311
+	/**
312
+	 * @covers \SwaggerGen\Parser\Text\Preprocessor::define
313
+	 * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
314
+	 */
315
+	public function testPreprocess_Elif_NoValue()
316
+	{
317
+		$object = new \SwaggerGen\Parser\Text\Preprocessor();
318
+		$this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
319
+		$object->define('test', 'blue');
320
+		$out = $object->preprocess('
321 321
 			if test red
322 322
 			whatever
323 323
 			elif test green
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
 			endif
328 328
 		');
329 329
 
330
-        $this->assertEquals('
330
+		$this->assertEquals('
331 331
 
332 332
 
333 333
 
@@ -336,76 +336,76 @@  discard block
 block discarded – undo
336 336
 			otherwise
337 337
 
338 338
 		', $out);
339
-    }
340
-
341
-    /**
342
-     * @covers \SwaggerGen\Parser\Text\Preprocessor::define
343
-     * @covers \SwaggerGen\Parser\Text\Preprocessor::undefine
344
-     * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
345
-     */
346
-    public function testPreprocess_Undefine()
347
-    {
348
-        $object = new \SwaggerGen\Parser\Text\Preprocessor();
349
-        $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
350
-        $object->define('test');
351
-        $object->undefine('test');
352
-        $out = $object->preprocess('
339
+	}
340
+
341
+	/**
342
+	 * @covers \SwaggerGen\Parser\Text\Preprocessor::define
343
+	 * @covers \SwaggerGen\Parser\Text\Preprocessor::undefine
344
+	 * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
345
+	 */
346
+	public function testPreprocess_Undefine()
347
+	{
348
+		$object = new \SwaggerGen\Parser\Text\Preprocessor();
349
+		$this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
350
+		$object->define('test');
351
+		$object->undefine('test');
352
+		$out = $object->preprocess('
353 353
 			ifdef test
354 354
 			whatever
355 355
 			endif
356 356
 		');
357 357
 
358
-        $this->assertEquals('
358
+		$this->assertEquals('
359 359
 
360 360
 
361 361
 
362 362
 		', $out);
363
-    }
364
-
365
-    /**
366
-     * @covers \SwaggerGen\Parser\Text\Preprocessor::define
367
-     * @covers \SwaggerGen\Parser\Text\Preprocessor::resetDefines
368
-     * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
369
-     */
370
-    public function testPreprocess_ResetDefines()
371
-    {
372
-        $object = new \SwaggerGen\Parser\Text\Preprocessor();
373
-        $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
374
-        $object->define('test');
375
-        $object->resetDefines();
376
-        $out = $object->preprocess('
363
+	}
364
+
365
+	/**
366
+	 * @covers \SwaggerGen\Parser\Text\Preprocessor::define
367
+	 * @covers \SwaggerGen\Parser\Text\Preprocessor::resetDefines
368
+	 * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
369
+	 */
370
+	public function testPreprocess_ResetDefines()
371
+	{
372
+		$object = new \SwaggerGen\Parser\Text\Preprocessor();
373
+		$this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
374
+		$object->define('test');
375
+		$object->resetDefines();
376
+		$out = $object->preprocess('
377 377
 			ifdef test
378 378
 			whatever
379 379
 			endif
380 380
 		');
381 381
 
382
-        $this->assertEquals('
382
+		$this->assertEquals('
383 383
 
384 384
 
385 385
 
386 386
 		', $out);
387
-    }
388
-
389
-    /**
390
-     * @covers \SwaggerGen\Parser\Text\Preprocessor::addDefines
391
-     * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
392
-     */
393
-    public function testPreprocess_AddDefines()
394
-    {
395
-        $object = new \SwaggerGen\Parser\Text\Preprocessor();
396
-        $this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
397
-        $object->addDefines(['test' => true]);
398
-        $out = $object->preprocess('
387
+	}
388
+
389
+	/**
390
+	 * @covers \SwaggerGen\Parser\Text\Preprocessor::addDefines
391
+	 * @covers \SwaggerGen\Parser\Text\Preprocessor::preprocess
392
+	 */
393
+	public function testPreprocess_AddDefines()
394
+	{
395
+		$object = new \SwaggerGen\Parser\Text\Preprocessor();
396
+		$this->assertInstanceOf('\SwaggerGen\Parser\Text\Preprocessor', $object);
397
+		$object->addDefines(['test' => true]);
398
+		$out = $object->preprocess('
399 399
 			ifdef test
400 400
 			whatever
401 401
 			endif
402 402
 		');
403 403
 
404
-        $this->assertEquals('
404
+		$this->assertEquals('
405 405
 
406 406
 			whatever
407 407
 
408 408
 		', $out);
409
-    }
409
+	}
410 410
 
411 411
 }
Please login to merge, or discard this patch.