Completed
Push — master ( 7cc054...2f1531 )
by Martijn
15s
created
SwaggerGen/StatementException.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -15,28 +15,28 @@
 block discarded – undo
15 15
 class StatementException extends \Exception
16 16
 {
17 17
 
18
-    /**
19
-     * @var Statement
20
-     */
21
-    private $statement;
22
-
23
-    /**
24
-     *
25
-     * @param string $message
26
-     * @param int $code
27
-     * @param Throwable $previous
28
-     * @param Statement $statement
29
-     */
30
-    public function __construct($message = "", $code = 0, $previous = null, $statement = null)
31
-    {
32
-        $this->statement = $statement;
33
-
34
-        parent::__construct($message, $code, $previous);
35
-    }
36
-
37
-    public function getStatement()
38
-    {
39
-        return $this->statement;
40
-    }
18
+	/**
19
+	 * @var Statement
20
+	 */
21
+	private $statement;
22
+
23
+	/**
24
+	 *
25
+	 * @param string $message
26
+	 * @param int $code
27
+	 * @param Throwable $previous
28
+	 * @param Statement $statement
29
+	 */
30
+	public function __construct($message = "", $code = 0, $previous = null, $statement = null)
31
+	{
32
+		$this->statement = $statement;
33
+
34
+		parent::__construct($message, $code, $previous);
35
+	}
36
+
37
+	public function getStatement()
38
+	{
39
+		return $this->statement;
40
+	}
41 41
 
42 42
 }
Please login to merge, or discard this patch.
SwaggerGen/SwaggerGen.php 2 patches
Indentation   +212 added lines, -212 removed lines patch added patch discarded remove patch
@@ -38,217 +38,217 @@
 block discarded – undo
38 38
 class SwaggerGen
39 39
 {
40 40
 
41
-    const FORMAT_ARRAY = '';
42
-    const FORMAT_JSON = 'json';
43
-    const FORMAT_JSON_PRETTY = 'json+';
44
-    const FORMAT_YAML = 'yaml';
45
-
46
-    private $host;
47
-    private $basePath;
48
-    private $dirs;
49
-    private $defines = [];
50
-
51
-    /**
52
-     * @var TypeRegistry
53
-     */
54
-    private $typeRegistry;
55
-
56
-    /**
57
-     * Create a new SwaggerGen instance
58
-     *
59
-     * @param string $host
60
-     * @param string $basePath
61
-     * @param string[] $dirs
62
-     * @param TypeRegistry $typeRegistry
63
-     */
64
-    public function __construct($host = '', $basePath = '', $dirs = [], $typeRegistry = null)
65
-    {
66
-        $this->host = $host;
67
-        $this->basePath = $basePath;
68
-        $this->dirs = $dirs;
69
-        $this->typeRegistry = $typeRegistry;
70
-    }
71
-
72
-    /**
73
-     * Set a new type registry
74
-     *
75
-     * @param TypeRegistry $typeRegistry
76
-     */
77
-    public function setTypeRegistry($typeRegistry = null)
78
-    {
79
-        $this->typeRegistry = $typeRegistry;
80
-    }
81
-
82
-    /**
83
-     * @param string $name
84
-     */
85
-    public function define($name, $value = 1)
86
-    {
87
-        $this->defines[$name] = $value;
88
-    }
89
-
90
-    /**
91
-     * @param string $name
92
-     */
93
-    public function undefine($name)
94
-    {
95
-        unset($this->defines[$name]);
96
-    }
97
-
98
-    /**
99
-     * @param string $file
100
-     * @param string[] $dirs
101
-     * @return Statement[]
102
-     * @throws Exception
103
-     */
104
-    private function parsePhpFile(string $file, array $dirs): array
105
-    {
106
-        $Parser = new Parser();
107
-        return $Parser->parse($file, $dirs, $this->defines);
108
-    }
109
-
110
-    /**
111
-     * @param string $file
112
-     * @param string[] $dirs
113
-     * @return Statement[]
114
-     */
115
-    private function parseTextFile($file, $dirs)
116
-    {
117
-        $Parser = new TextParser();
118
-        return $Parser->parse($file, $dirs, $this->defines);
119
-    }
120
-
121
-    /**
122
-     * @param string $text
123
-     * @param string[] $dirs
124
-     * @return Statement[]
125
-     */
126
-    private function parseText(string $text, array $dirs): array
127
-    {
128
-        $Parser = new TextParser();
129
-        return $Parser->parseText($text, $dirs, $this->defines);
130
-    }
131
-
132
-    /**
133
-     * Creates Swagger\Swagger object and populates it with statements
134
-     *
135
-     * This effectively converts the linear list of statements into parse-tree
136
-     * like structure, performing some checks (like rejecting unknown
137
-     * subcommands) during the process. Returned Swagger\Swagger object is
138
-     * ready for serialization with {@see Swagger\Swagger::toArray}
139
-     *
140
-     * @param string $host
141
-     * @param string $basePath
142
-     * @param Statement[] $statements
143
-     * @return Swagger
144
-     * @throws StatementException
145
-     */
146
-    public function parseStatements($host, $basePath, $statements)
147
-    {
148
-        $swagger = new Swagger($host, $basePath, $this->typeRegistry);
149
-
150
-        $stack = array($swagger);
151
-        /* @var AbstractObject[] $stack */
152
-        foreach ($statements as $statement) {
153
-            try {
154
-                $top = end($stack);
155
-
156
-                do {
157
-                    $result = $top->handleCommand($statement->getCommand(), $statement->getData());
158
-
159
-                    if ($result) {
160
-                        if ($result !== $top) {
161
-                            // Remove all similar classes from array first!
162
-                            $classname = get_class($result);
163
-                            $stack = array_filter($stack, function ($class) use ($classname) {
164
-                                return !(is_a($class, $classname));
165
-                            });
166
-
167
-                            $stack[] = $result;
168
-                        }
169
-                    } else {
170
-                        $top = prev($stack);
171
-                    }
172
-                } while (!$result && $top);
173
-            } catch (Exception $e) {
174
-                throw new StatementException($e->getMessage(), $e->getCode(), $e, $statement);
175
-            }
176
-
177
-            if (!$result && !$top) {
178
-                $messages = array("Unsupported or unknown command: {$statement->getCommand()} {$statement->getData()}");
179
-
180
-                $stacktrace = [];
181
-                foreach ($stack as $object) {
182
-                    $stacktrace[] = (string)$object;
183
-                }
184
-                $messages[] = join(', ' . PHP_EOL, $stacktrace);
185
-
186
-                throw new StatementException(join('. ', $messages), 0, null, $statement);
187
-            }
188
-        }
189
-
190
-        return $swagger;
191
-    }
192
-
193
-    /**
194
-     * Get Swagger 2.x output
195
-     *
196
-     * @param string[] $files
197
-     * @param string[] $dirs
198
-     * @param string $format
199
-     * @return array|false|string
200
-     * @throws Exception
201
-     * @throws StatementException
202
-     */
203
-    public function getSwagger(array $files, array $dirs = [], string $format = self::FORMAT_ARRAY)
204
-    {
205
-        $dirs = array_merge($this->dirs, $dirs);
206
-
207
-        $statements = [];
208
-        foreach ($files as $file) {
209
-            switch (pathinfo($file, PATHINFO_EXTENSION)) {
210
-                case 'php':
211
-                    $fileStatements = $this->parsePhpFile($file, $dirs);
212
-                    break;
213
-
214
-                case 'txt':
215
-                    $fileStatements = $this->parseTextFile($file, $dirs);
216
-                    break;
217
-
218
-                default:
219
-                    $fileStatements = $this->parseText($file, $dirs);
220
-                    break;
221
-            }
222
-
223
-            $statements = array_merge($statements, $fileStatements);
224
-        }
225
-
226
-        $output = $this->parseStatements($this->host, $this->basePath, $statements)->toArray();
227
-
228
-        switch ($format) {
229
-            case self::FORMAT_JSON:
230
-                $output = json_encode($output);
231
-                break;
232
-
233
-            case self::FORMAT_JSON_PRETTY:
234
-                $flags = (defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0); // Since PHP 5.4.0
235
-                $output = json_encode($output, $flags);
236
-                break;
237
-
238
-            case self::FORMAT_YAML:
239
-                if (!function_exists('yaml_emit')) {
240
-                    throw new Exception('YAML extension not installed.');
241
-                }
242
-                array_walk_recursive($output, function (&$value) {
243
-                    if (is_object($value)) {
244
-                        $value = (array)$value;
245
-                    }
246
-                });
247
-                $output = yaml_emit($output, YAML_UTF8_ENCODING, YAML_LN_BREAK);
248
-                break;
249
-        }
250
-
251
-        return $output;
252
-    }
41
+	const FORMAT_ARRAY = '';
42
+	const FORMAT_JSON = 'json';
43
+	const FORMAT_JSON_PRETTY = 'json+';
44
+	const FORMAT_YAML = 'yaml';
45
+
46
+	private $host;
47
+	private $basePath;
48
+	private $dirs;
49
+	private $defines = [];
50
+
51
+	/**
52
+	 * @var TypeRegistry
53
+	 */
54
+	private $typeRegistry;
55
+
56
+	/**
57
+	 * Create a new SwaggerGen instance
58
+	 *
59
+	 * @param string $host
60
+	 * @param string $basePath
61
+	 * @param string[] $dirs
62
+	 * @param TypeRegistry $typeRegistry
63
+	 */
64
+	public function __construct($host = '', $basePath = '', $dirs = [], $typeRegistry = null)
65
+	{
66
+		$this->host = $host;
67
+		$this->basePath = $basePath;
68
+		$this->dirs = $dirs;
69
+		$this->typeRegistry = $typeRegistry;
70
+	}
71
+
72
+	/**
73
+	 * Set a new type registry
74
+	 *
75
+	 * @param TypeRegistry $typeRegistry
76
+	 */
77
+	public function setTypeRegistry($typeRegistry = null)
78
+	{
79
+		$this->typeRegistry = $typeRegistry;
80
+	}
81
+
82
+	/**
83
+	 * @param string $name
84
+	 */
85
+	public function define($name, $value = 1)
86
+	{
87
+		$this->defines[$name] = $value;
88
+	}
89
+
90
+	/**
91
+	 * @param string $name
92
+	 */
93
+	public function undefine($name)
94
+	{
95
+		unset($this->defines[$name]);
96
+	}
97
+
98
+	/**
99
+	 * @param string $file
100
+	 * @param string[] $dirs
101
+	 * @return Statement[]
102
+	 * @throws Exception
103
+	 */
104
+	private function parsePhpFile(string $file, array $dirs): array
105
+	{
106
+		$Parser = new Parser();
107
+		return $Parser->parse($file, $dirs, $this->defines);
108
+	}
109
+
110
+	/**
111
+	 * @param string $file
112
+	 * @param string[] $dirs
113
+	 * @return Statement[]
114
+	 */
115
+	private function parseTextFile($file, $dirs)
116
+	{
117
+		$Parser = new TextParser();
118
+		return $Parser->parse($file, $dirs, $this->defines);
119
+	}
120
+
121
+	/**
122
+	 * @param string $text
123
+	 * @param string[] $dirs
124
+	 * @return Statement[]
125
+	 */
126
+	private function parseText(string $text, array $dirs): array
127
+	{
128
+		$Parser = new TextParser();
129
+		return $Parser->parseText($text, $dirs, $this->defines);
130
+	}
131
+
132
+	/**
133
+	 * Creates Swagger\Swagger object and populates it with statements
134
+	 *
135
+	 * This effectively converts the linear list of statements into parse-tree
136
+	 * like structure, performing some checks (like rejecting unknown
137
+	 * subcommands) during the process. Returned Swagger\Swagger object is
138
+	 * ready for serialization with {@see Swagger\Swagger::toArray}
139
+	 *
140
+	 * @param string $host
141
+	 * @param string $basePath
142
+	 * @param Statement[] $statements
143
+	 * @return Swagger
144
+	 * @throws StatementException
145
+	 */
146
+	public function parseStatements($host, $basePath, $statements)
147
+	{
148
+		$swagger = new Swagger($host, $basePath, $this->typeRegistry);
149
+
150
+		$stack = array($swagger);
151
+		/* @var AbstractObject[] $stack */
152
+		foreach ($statements as $statement) {
153
+			try {
154
+				$top = end($stack);
155
+
156
+				do {
157
+					$result = $top->handleCommand($statement->getCommand(), $statement->getData());
158
+
159
+					if ($result) {
160
+						if ($result !== $top) {
161
+							// Remove all similar classes from array first!
162
+							$classname = get_class($result);
163
+							$stack = array_filter($stack, function ($class) use ($classname) {
164
+								return !(is_a($class, $classname));
165
+							});
166
+
167
+							$stack[] = $result;
168
+						}
169
+					} else {
170
+						$top = prev($stack);
171
+					}
172
+				} while (!$result && $top);
173
+			} catch (Exception $e) {
174
+				throw new StatementException($e->getMessage(), $e->getCode(), $e, $statement);
175
+			}
176
+
177
+			if (!$result && !$top) {
178
+				$messages = array("Unsupported or unknown command: {$statement->getCommand()} {$statement->getData()}");
179
+
180
+				$stacktrace = [];
181
+				foreach ($stack as $object) {
182
+					$stacktrace[] = (string)$object;
183
+				}
184
+				$messages[] = join(', ' . PHP_EOL, $stacktrace);
185
+
186
+				throw new StatementException(join('. ', $messages), 0, null, $statement);
187
+			}
188
+		}
189
+
190
+		return $swagger;
191
+	}
192
+
193
+	/**
194
+	 * Get Swagger 2.x output
195
+	 *
196
+	 * @param string[] $files
197
+	 * @param string[] $dirs
198
+	 * @param string $format
199
+	 * @return array|false|string
200
+	 * @throws Exception
201
+	 * @throws StatementException
202
+	 */
203
+	public function getSwagger(array $files, array $dirs = [], string $format = self::FORMAT_ARRAY)
204
+	{
205
+		$dirs = array_merge($this->dirs, $dirs);
206
+
207
+		$statements = [];
208
+		foreach ($files as $file) {
209
+			switch (pathinfo($file, PATHINFO_EXTENSION)) {
210
+				case 'php':
211
+					$fileStatements = $this->parsePhpFile($file, $dirs);
212
+					break;
213
+
214
+				case 'txt':
215
+					$fileStatements = $this->parseTextFile($file, $dirs);
216
+					break;
217
+
218
+				default:
219
+					$fileStatements = $this->parseText($file, $dirs);
220
+					break;
221
+			}
222
+
223
+			$statements = array_merge($statements, $fileStatements);
224
+		}
225
+
226
+		$output = $this->parseStatements($this->host, $this->basePath, $statements)->toArray();
227
+
228
+		switch ($format) {
229
+			case self::FORMAT_JSON:
230
+				$output = json_encode($output);
231
+				break;
232
+
233
+			case self::FORMAT_JSON_PRETTY:
234
+				$flags = (defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0); // Since PHP 5.4.0
235
+				$output = json_encode($output, $flags);
236
+				break;
237
+
238
+			case self::FORMAT_YAML:
239
+				if (!function_exists('yaml_emit')) {
240
+					throw new Exception('YAML extension not installed.');
241
+				}
242
+				array_walk_recursive($output, function (&$value) {
243
+					if (is_object($value)) {
244
+						$value = (array)$value;
245
+					}
246
+				});
247
+				$output = yaml_emit($output, YAML_UTF8_ENCODING, YAML_LN_BREAK);
248
+				break;
249
+		}
250
+
251
+		return $output;
252
+	}
253 253
 
254 254
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
                         if ($result !== $top) {
161 161
                             // Remove all similar classes from array first!
162 162
                             $classname = get_class($result);
163
-                            $stack = array_filter($stack, function ($class) use ($classname) {
163
+                            $stack = array_filter($stack, function($class) use ($classname) {
164 164
                                 return !(is_a($class, $classname));
165 165
                             });
166 166
 
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
 
180 180
                 $stacktrace = [];
181 181
                 foreach ($stack as $object) {
182
-                    $stacktrace[] = (string)$object;
182
+                    $stacktrace[] = (string) $object;
183 183
                 }
184 184
                 $messages[] = join(', ' . PHP_EOL, $stacktrace);
185 185
 
@@ -239,9 +239,9 @@  discard block
 block discarded – undo
239 239
                 if (!function_exists('yaml_emit')) {
240 240
                     throw new Exception('YAML extension not installed.');
241 241
                 }
242
-                array_walk_recursive($output, function (&$value) {
242
+                array_walk_recursive($output, function(&$value) {
243 243
                     if (is_object($value)) {
244
-                        $value = (array)$value;
244
+                        $value = (array) $value;
245 245
                     }
246 246
                 });
247 247
                 $output = yaml_emit($output, YAML_UTF8_ENCODING, YAML_LN_BREAK);
Please login to merge, or discard this patch.
SwaggerGen/Statement.php 1 patch
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -14,61 +14,61 @@
 block discarded – undo
14 14
 class Statement
15 15
 {
16 16
 
17
-    private $command;
18
-    private $data;
19
-    private $file;
20
-    private $line;
17
+	private $command;
18
+	private $data;
19
+	private $file;
20
+	private $line;
21 21
 
22
-    public function __construct($command, $data = null, $file = null, $line = null)
23
-    {
24
-        $this->command = $command;
25
-        $this->data = $data;
26
-        $this->file = $file;
27
-        $this->line = $line;
28
-    }
22
+	public function __construct($command, $data = null, $file = null, $line = null)
23
+	{
24
+		$this->command = $command;
25
+		$this->data = $data;
26
+		$this->file = $file;
27
+		$this->line = $line;
28
+	}
29 29
 
30
-    public function __toString()
31
-    {
32
-        $message = "Command '{$this->command}'";
33
-        $message .= $this->data ? " with data '{$this->data}'" : ' without data';
34
-        $message .= $this->file ? " from static text" : " in file '{$this->file}' on line {$this->line}";
35
-        return $message;
36
-    }
30
+	public function __toString()
31
+	{
32
+		$message = "Command '{$this->command}'";
33
+		$message .= $this->data ? " with data '{$this->data}'" : ' without data';
34
+		$message .= $this->file ? " from static text" : " in file '{$this->file}' on line {$this->line}";
35
+		return $message;
36
+	}
37 37
 
38
-    /**
39
-     * Get the command part of this statement
40
-     * @return string single word, without spaces
41
-     */
42
-    public function getCommand()
43
-    {
44
-        return $this->command;
45
-    }
38
+	/**
39
+	 * Get the command part of this statement
40
+	 * @return string single word, without spaces
41
+	 */
42
+	public function getCommand()
43
+	{
44
+		return $this->command;
45
+	}
46 46
 
47
-    /**
48
-     * Get the data of this statement
49
-     * @return string may contain spaces
50
-     */
51
-    public function getData()
52
-    {
53
-        return $this->data;
54
-    }
47
+	/**
48
+	 * Get the data of this statement
49
+	 * @return string may contain spaces
50
+	 */
51
+	public function getData()
52
+	{
53
+		return $this->data;
54
+	}
55 55
 
56
-    /**
57
-     * Get the file (if available) where this statement was parsed from
58
-     * @return string|null the full filename or null of from static text
59
-     */
60
-    public function getFile()
61
-    {
62
-        return $this->file;
63
-    }
56
+	/**
57
+	 * Get the file (if available) where this statement was parsed from
58
+	 * @return string|null the full filename or null of from static text
59
+	 */
60
+	public function getFile()
61
+	{
62
+		return $this->file;
63
+	}
64 64
 
65
-    /**
66
-     * Get the line number where this statement was found
67
-     * @return int|null the line number
68
-     */
69
-    public function getLine()
70
-    {
71
-        return $this->line;
72
-    }
65
+	/**
66
+	 * Get the line number where this statement was found
67
+	 * @return int|null the line number
68
+	 */
69
+	public function getLine()
70
+	{
71
+		return $this->line;
72
+	}
73 73
 
74 74
 }
Please login to merge, or discard this patch.
SwaggerGen/Swagger/Tag.php 1 patch
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -13,47 +13,47 @@
 block discarded – undo
13 13
 class Tag extends AbstractDocumentableObject
14 14
 {
15 15
 
16
-    private $name;
17
-    private $description;
18
-
19
-    public function __construct(AbstractObject $parent, $name, $description = null)
20
-    {
21
-        parent::__construct($parent);
22
-        $this->name = $name;
23
-        $this->description = $description;
24
-    }
25
-
26
-    /**
27
-     * @param string $command
28
-     * @param string $data
29
-     * @return AbstractObject|boolean
30
-     */
31
-    public function handleCommand($command, $data = null)
32
-    {
33
-        if (strtolower($command) === 'description') {
34
-            $this->description = $data;
35
-            return $this;
36
-        }
37
-
38
-        return parent::handleCommand($command, $data);
39
-    }
40
-
41
-    public function toArray()
42
-    {
43
-        return self::arrayFilterNull(array_merge(array(
44
-            'name' => $this->name,
45
-            'description' => empty($this->description) ? null : $this->description,
46
-        ), parent::toArray()));
47
-    }
48
-
49
-    public function getName()
50
-    {
51
-        return $this->name;
52
-    }
53
-
54
-    public function __toString()
55
-    {
56
-        return __CLASS__ . ' ' . $this->name;
57
-    }
16
+	private $name;
17
+	private $description;
18
+
19
+	public function __construct(AbstractObject $parent, $name, $description = null)
20
+	{
21
+		parent::__construct($parent);
22
+		$this->name = $name;
23
+		$this->description = $description;
24
+	}
25
+
26
+	/**
27
+	 * @param string $command
28
+	 * @param string $data
29
+	 * @return AbstractObject|boolean
30
+	 */
31
+	public function handleCommand($command, $data = null)
32
+	{
33
+		if (strtolower($command) === 'description') {
34
+			$this->description = $data;
35
+			return $this;
36
+		}
37
+
38
+		return parent::handleCommand($command, $data);
39
+	}
40
+
41
+	public function toArray()
42
+	{
43
+		return self::arrayFilterNull(array_merge(array(
44
+			'name' => $this->name,
45
+			'description' => empty($this->description) ? null : $this->description,
46
+		), parent::toArray()));
47
+	}
48
+
49
+	public function getName()
50
+	{
51
+		return $this->name;
52
+	}
53
+
54
+	public function __toString()
55
+	{
56
+		return __CLASS__ . ' ' . $this->name;
57
+	}
58 58
 
59 59
 }
Please login to merge, or discard this patch.
SwaggerGen/Swagger/Parameter.php 3 patches
Indentation   +142 added lines, -142 removed lines patch added patch discarded remove patch
@@ -15,147 +15,147 @@
 block discarded – undo
15 15
 class Parameter extends AbstractObject implements IParameter
16 16
 {
17 17
 
18
-    private static $classTypes = array(
19
-        'integer' => 'Integer',
20
-        'int' => 'Integer',
21
-        'int32' => 'Integer',
22
-        'int64' => 'Integer',
23
-        'long' => 'Integer',
24
-        'float' => 'Number',
25
-        'double' => 'Number',
26
-        'string' => 'String',
27
-        'byte' => 'String',
28
-        'binary' => 'String',
29
-        'password' => 'String',
30
-        'enum' => 'String',
31
-        'uuid' => 'StringUuid',
32
-        'boolean' => 'Boolean',
33
-        'bool' => 'Boolean',
34
-        'array' => 'Array',
35
-        'csv' => 'Array',
36
-        'ssv' => 'Array',
37
-        'tsv' => 'Array',
38
-        'pipes' => 'Array',
39
-        'multi' => 'Array',
40
-        'date' => 'Date',
41
-        'datetime' => 'Date',
42
-        'date-time' => 'Date',
43
-        'file' => 'File',
44
-    );
45
-    private $name = '';
46
-    private $in;
47
-    private $description;
48
-    private $required = false;
49
-
50
-    /**
51
-     * @var Type\AbstractType
52
-     */
53
-    private $Type;
54
-
55
-    /**
56
-     * Returns true if the "multi" array collectionFormat is allowed for this
57
-     * parameter.
58
-     * @return bool
59
-     */
60
-    public function isMulti(): bool
61
-    {
62
-        return in_array($this->in, array('query', 'form'));
63
-    }
64
-
65
-    /**
66
-     * Return true if the parameter is of type 'formData'
67
-     * @return bool
68
-     */
69
-    public function isForm(): bool
70
-    {
71
-        return $this->in === 'form';
72
-    }
73
-
74
-    /**
75
-     * @throws Exception
76
-     */
77
-    public function __construct(AbstractObject $parent, $in, $data, $required = false)
78
-    {
79
-        parent::__construct($parent);
80
-
81
-        if ($in !== 'path' && $in !== 'form' && $in !== 'query' && $in !== 'header') {
82
-            throw new Exception("Invalid in for parameter: '{$in}'");
83
-        }
84
-        $this->in = $in;
85
-
86
-        $definition = self::wordShift($data);
87
-        if (empty($definition)) {
88
-            throw new Exception('No type definition for parameter');
89
-        }
90
-
91
-        $name = self::wordShift($data);
92
-        if (empty($name)) {
93
-            throw new Exception('No name for parameter');
94
-        } else {
95
-            $this->name = $name;
96
-        }
97
-
98
-        $this->description = $data;
99
-        $this->required = (bool)$required;
100
-
101
-        // Parse regex
102
-        $match = array();
103
-        if (preg_match('/^([a-z][a-z0-9]*)/i', $definition, $match) === 1) {
104
-            $format = strtolower($match[1]);
105
-        } elseif (preg_match('/^(\[)(?:.*?)\]$/i', $definition, $match) === 1) {
106
-            $format = 'array';
107
-        } elseif (preg_match('/^(\{)(?:.*?)\}$/i', $definition, $match) === 1) {
108
-            $format = 'object';
109
-        } else {
110
-            throw new Exception('Unparseable parameter format definition: \'' . $definition . '\'');
111
-        }
112
-
113
-        if ($this->getTypeRegistry()->has($format)) {
114
-            $class = $this->getTypeRegistry()->get($format);
115
-            $this->Type = new $class($this, $definition);
116
-        } elseif (isset(self::$classTypes[$format])) {
117
-            $type = self::$classTypes[$format];
118
-            $class = "\\SwaggerGen\\Swagger\\Type\\{$type}Type";
119
-            $this->Type = new $class($this, $definition);
120
-        } else {
121
-            throw new Exception("Type format not recognized: '{$format}'");
122
-        }
123
-    }
124
-
125
-    /**
126
-     * @param string $command
127
-     * @param string $data
128
-     * @return AbstractObject|boolean
129
-     * @throws Exception
130
-     */
131
-    public function handleCommand($command, $data = null)
132
-    {
133
-        // Pass through to Type
134
-        if ($this->Type && $this->Type->handleCommand($command, $data)) {
135
-            return $this;
136
-        }
137
-
138
-        return parent::handleCommand($command, $data);
139
-    }
140
-
141
-    public function toArray()
142
-    {
143
-        return self::arrayFilterNull(array_merge(array(
144
-            'name' => $this->name,
145
-            'in' => $this->in === 'form' ? 'formData' : $this->in,
146
-            'description' => empty($this->description) ? null : $this->description,
147
-            'required' => $this->in === 'path' || $this->required ? true : null,
148
-        ), $this->Type->toArray(), parent::toArray()));
149
-    }
150
-
151
-    public function __toString()
152
-    {
153
-        return __CLASS__ . " {$this->name} {$this->in}";
154
-    }
155
-
156
-    public function getName()
157
-    {
158
-        return $this->name;
159
-    }
18
+	private static $classTypes = array(
19
+		'integer' => 'Integer',
20
+		'int' => 'Integer',
21
+		'int32' => 'Integer',
22
+		'int64' => 'Integer',
23
+		'long' => 'Integer',
24
+		'float' => 'Number',
25
+		'double' => 'Number',
26
+		'string' => 'String',
27
+		'byte' => 'String',
28
+		'binary' => 'String',
29
+		'password' => 'String',
30
+		'enum' => 'String',
31
+		'uuid' => 'StringUuid',
32
+		'boolean' => 'Boolean',
33
+		'bool' => 'Boolean',
34
+		'array' => 'Array',
35
+		'csv' => 'Array',
36
+		'ssv' => 'Array',
37
+		'tsv' => 'Array',
38
+		'pipes' => 'Array',
39
+		'multi' => 'Array',
40
+		'date' => 'Date',
41
+		'datetime' => 'Date',
42
+		'date-time' => 'Date',
43
+		'file' => 'File',
44
+	);
45
+	private $name = '';
46
+	private $in;
47
+	private $description;
48
+	private $required = false;
49
+
50
+	/**
51
+	 * @var Type\AbstractType
52
+	 */
53
+	private $Type;
54
+
55
+	/**
56
+	 * Returns true if the "multi" array collectionFormat is allowed for this
57
+	 * parameter.
58
+	 * @return bool
59
+	 */
60
+	public function isMulti(): bool
61
+	{
62
+		return in_array($this->in, array('query', 'form'));
63
+	}
64
+
65
+	/**
66
+	 * Return true if the parameter is of type 'formData'
67
+	 * @return bool
68
+	 */
69
+	public function isForm(): bool
70
+	{
71
+		return $this->in === 'form';
72
+	}
73
+
74
+	/**
75
+	 * @throws Exception
76
+	 */
77
+	public function __construct(AbstractObject $parent, $in, $data, $required = false)
78
+	{
79
+		parent::__construct($parent);
80
+
81
+		if ($in !== 'path' && $in !== 'form' && $in !== 'query' && $in !== 'header') {
82
+			throw new Exception("Invalid in for parameter: '{$in}'");
83
+		}
84
+		$this->in = $in;
85
+
86
+		$definition = self::wordShift($data);
87
+		if (empty($definition)) {
88
+			throw new Exception('No type definition for parameter');
89
+		}
90
+
91
+		$name = self::wordShift($data);
92
+		if (empty($name)) {
93
+			throw new Exception('No name for parameter');
94
+		} else {
95
+			$this->name = $name;
96
+		}
97
+
98
+		$this->description = $data;
99
+		$this->required = (bool)$required;
100
+
101
+		// Parse regex
102
+		$match = array();
103
+		if (preg_match('/^([a-z][a-z0-9]*)/i', $definition, $match) === 1) {
104
+			$format = strtolower($match[1]);
105
+		} elseif (preg_match('/^(\[)(?:.*?)\]$/i', $definition, $match) === 1) {
106
+			$format = 'array';
107
+		} elseif (preg_match('/^(\{)(?:.*?)\}$/i', $definition, $match) === 1) {
108
+			$format = 'object';
109
+		} else {
110
+			throw new Exception('Unparseable parameter format definition: \'' . $definition . '\'');
111
+		}
112
+
113
+		if ($this->getTypeRegistry()->has($format)) {
114
+			$class = $this->getTypeRegistry()->get($format);
115
+			$this->Type = new $class($this, $definition);
116
+		} elseif (isset(self::$classTypes[$format])) {
117
+			$type = self::$classTypes[$format];
118
+			$class = "\\SwaggerGen\\Swagger\\Type\\{$type}Type";
119
+			$this->Type = new $class($this, $definition);
120
+		} else {
121
+			throw new Exception("Type format not recognized: '{$format}'");
122
+		}
123
+	}
124
+
125
+	/**
126
+	 * @param string $command
127
+	 * @param string $data
128
+	 * @return AbstractObject|boolean
129
+	 * @throws Exception
130
+	 */
131
+	public function handleCommand($command, $data = null)
132
+	{
133
+		// Pass through to Type
134
+		if ($this->Type && $this->Type->handleCommand($command, $data)) {
135
+			return $this;
136
+		}
137
+
138
+		return parent::handleCommand($command, $data);
139
+	}
140
+
141
+	public function toArray()
142
+	{
143
+		return self::arrayFilterNull(array_merge(array(
144
+			'name' => $this->name,
145
+			'in' => $this->in === 'form' ? 'formData' : $this->in,
146
+			'description' => empty($this->description) ? null : $this->description,
147
+			'required' => $this->in === 'path' || $this->required ? true : null,
148
+		), $this->Type->toArray(), parent::toArray()));
149
+	}
150
+
151
+	public function __toString()
152
+	{
153
+		return __CLASS__ . " {$this->name} {$this->in}";
154
+	}
155
+
156
+	public function getName()
157
+	{
158
+		return $this->name;
159
+	}
160 160
 
161 161
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -96,7 +96,7 @@
 block discarded – undo
96 96
         }
97 97
 
98 98
         $this->description = $data;
99
-        $this->required = (bool)$required;
99
+        $this->required = (bool) $required;
100 100
 
101 101
         // Parse regex
102 102
         $match = array();
Please login to merge, or discard this patch.
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -115,7 +115,7 @@
 block discarded – undo
115 115
             $this->Type = new $class($this, $definition);
116 116
         } elseif (isset(self::$classTypes[$format])) {
117 117
             $type = self::$classTypes[$format];
118
-            $class = "\\SwaggerGen\\Swagger\\Type\\{$type}Type";
118
+            $class = "\\SwaggerGen\\Swagger\\Type\\{$type}type";
119 119
             $this->Type = new $class($this, $definition);
120 120
         } else {
121 121
             throw new Exception("Type format not recognized: '{$format}'");
Please login to merge, or discard this patch.
SwaggerGen/Swagger/Response.php 2 patches
Indentation   +172 added lines, -172 removed lines patch added patch discarded remove patch
@@ -16,177 +16,177 @@
 block discarded – undo
16 16
 class Response extends AbstractObject
17 17
 {
18 18
 
19
-    const OK = 200;
20
-    const CREATED = 201;
21
-    const ACCEPTED = 202;
22
-    const NON_AUTHORITATIVE_INFORMATION = 203;
23
-    const NO_CONTENT = 204;
24
-    const RESET_CONTENT = 205;
25
-    const PARTIAL_CONTENT = 206;
26
-    const BAD_REQUEST = 400;
27
-    const UNAUTHORIZED = 401;
28
-    const PAYMENT_REQUIRED = 402;
29
-    const FORBIDDEN = 403;
30
-    const NOT_FOUND = 404;
31
-    const METHOD_NOT_ALLOWED = 405;
32
-    const NOT_ACCEPTABLE = 406;
33
-    const PROXY_AUTHENTICATION_REQUIRED = 407;
34
-    const REQUEST_TIMEOUT = 408;
35
-    const CONFLICT = 409;
36
-    const GONE = 410;
37
-    const LENGTH_REQUIRED = 411;
38
-    const PRECONDITION_FAILED = 412;
39
-    const REQUEST_ENTITY_TOO_LARGE = 413;
40
-    const REQUEST_URI_TOO_LONG = 414;
41
-    const UNSUPPORTED_MEDIA_TYPE = 415;
42
-    const REQUESTED_RANGE_NOT_SATISFIABLE = 416;
43
-    const EXPECTATION_FAILED = 417;
44
-    const UNPROCESSABLE_ENTITY = 422;
45
-    const TOO_MANY_REQUESTS = 429;
46
-    const INTERNAL_SERVER_ERROR = 500;
47
-    const NOT_IMPLEMENTED = 501; // When method is supported for none of the resources
48
-
49
-    protected static $httpCodes = array(
50
-        self::OK => 'OK',
51
-        self::CREATED => 'Created',
52
-        self::ACCEPTED => 'Accepted',
53
-        self::NON_AUTHORITATIVE_INFORMATION => 'Non-Authoritative Information',
54
-        self::NO_CONTENT => 'No Content',
55
-        self::RESET_CONTENT => 'Reset Content',
56
-        self::PARTIAL_CONTENT => 'Partial Content',
57
-        self::BAD_REQUEST => 'Bad Request',
58
-        self::UNAUTHORIZED => 'Unauthorized',
59
-        self::PAYMENT_REQUIRED => 'Payment Required',
60
-        self::FORBIDDEN => 'Forbidden',
61
-        self::NOT_FOUND => 'Not Found',
62
-        self::METHOD_NOT_ALLOWED => 'Method Not Allowed',
63
-        self::NOT_ACCEPTABLE => 'Not Acceptable',
64
-        self::PROXY_AUTHENTICATION_REQUIRED => 'Proxy Authentication Required',
65
-        self::REQUEST_TIMEOUT => 'Request Timeout',
66
-        self::CONFLICT => 'Conflict',
67
-        self::GONE => 'Gone',
68
-        self::LENGTH_REQUIRED => 'Length Required',
69
-        self::PRECONDITION_FAILED => 'Precondition Failed',
70
-        self::REQUEST_ENTITY_TOO_LARGE => 'Request Entity Too Large',
71
-        self::REQUEST_URI_TOO_LONG => 'Request-URI Too Long',
72
-        self::UNSUPPORTED_MEDIA_TYPE => 'Unsupported Media Type',
73
-        self::REQUESTED_RANGE_NOT_SATISFIABLE => 'Requested Range Not Satisfiable',
74
-        self::EXPECTATION_FAILED => 'Expectation Failed',
75
-        self::UNPROCESSABLE_ENTITY => 'Unprocessable Entity',
76
-        self::TOO_MANY_REQUESTS => 'Too Many Requests',
77
-        self::INTERNAL_SERVER_ERROR => 'Internal Server Error',
78
-        self::NOT_IMPLEMENTED => 'Not Implemented',
79
-    );
80
-    private $description = '';
81
-    private $schema;
82
-
83
-    /**
84
-     * @var Header[]
85
-     */
86
-    private $Headers = array();
87
-
88
-    /**
89
-     * JSON examples
90
-     * @var array
91
-     */
92
-    private $examples = array();
93
-
94
-    public static function getCode($search)
95
-    {
96
-        static $lookup = null;
97
-
98
-        if (is_numeric($search)) {
99
-            return intval($search);
100
-        }
101
-
102
-        // build static lookup table
103
-        if (!$lookup) {
104
-            $lookup = array();
105
-            foreach (self::$httpCodes as $code => $text) {
106
-                $lookup[preg_replace('/[^a-z]+/', '', strtolower($text))] = $code;
107
-            }
108
-        }
109
-
110
-        $search = preg_replace('/[^a-z]+/', '', strtolower($search));
111
-        return $lookup[$search] ?? null;
112
-    }
113
-
114
-    /**
115
-     * @throws Exception
116
-     */
117
-    public function __construct(AbstractObject $parent, $code, $definition = null, $description = null)
118
-    {
119
-        parent::__construct($parent);
120
-
121
-        if ($definition) {
122
-            $this->schema = new Schema($this, $definition);
123
-        }
124
-
125
-        if (!empty($description)) {
126
-            $this->description = $description;
127
-        } elseif (isset(self::$httpCodes[$code])) {
128
-            $this->description = self::$httpCodes[$code];
129
-        }
130
-    }
131
-
132
-    /**
133
-     * @param string $command
134
-     * @param string $data
135
-     * @return AbstractObject|boolean
136
-     * @throws Exception
137
-     * @throws Exception
138
-     * @throws Exception
139
-     * @throws Exception
140
-     * @throws Exception
141
-     */
142
-    public function handleCommand($command, $data = null)
143
-    {
144
-        switch (strtolower($command)) {
145
-            case 'header':
146
-                $type = self::wordShift($data);
147
-                if (empty($type)) {
148
-                    throw new Exception('Missing type for header');
149
-                }
150
-                $name = self::wordShift($data);
151
-                if (empty($name)) {
152
-                    throw new Exception('Missing name for header type \'' . $type . '\'');
153
-                }
154
-                $Header = new Header($this, $type, $data);
155
-                $this->Headers[$name] = $Header;
156
-                return $Header;
157
-
158
-            case 'example':
159
-                $name = self::wordShift($data);
160
-                if (empty($name)) {
161
-                    throw new Exception('Missing name for example');
162
-                }
163
-                if ($data === '') {
164
-                    throw new Exception('Missing content for example `' . $name . '`');
165
-                }
166
-                $json = preg_replace_callback('/([^{}:]+)/', function ($match) {
167
-                    json_decode($match[1]);
168
-                    return json_last_error() === JSON_ERROR_NONE ? $match[1] : json_encode($match[1]);
169
-                }, trim($data));
170
-                $this->examples[$name] = json_decode($json, true);
171
-                return $this;
172
-        }
173
-
174
-        return parent::handleCommand($command, $data);
175
-    }
176
-
177
-    public function toArray()
178
-    {
179
-        return self::arrayFilterNull(array_merge(array(
180
-            'description' => $this->description,
181
-            'schema' => $this->schema ? $this->schema->toArray() : null,
182
-            'headers' => self::objectsToArray($this->Headers),
183
-            'examples' => $this->examples,
184
-        ), parent::toArray()));
185
-    }
186
-
187
-    public function __toString()
188
-    {
189
-        return __CLASS__;
190
-    }
19
+	const OK = 200;
20
+	const CREATED = 201;
21
+	const ACCEPTED = 202;
22
+	const NON_AUTHORITATIVE_INFORMATION = 203;
23
+	const NO_CONTENT = 204;
24
+	const RESET_CONTENT = 205;
25
+	const PARTIAL_CONTENT = 206;
26
+	const BAD_REQUEST = 400;
27
+	const UNAUTHORIZED = 401;
28
+	const PAYMENT_REQUIRED = 402;
29
+	const FORBIDDEN = 403;
30
+	const NOT_FOUND = 404;
31
+	const METHOD_NOT_ALLOWED = 405;
32
+	const NOT_ACCEPTABLE = 406;
33
+	const PROXY_AUTHENTICATION_REQUIRED = 407;
34
+	const REQUEST_TIMEOUT = 408;
35
+	const CONFLICT = 409;
36
+	const GONE = 410;
37
+	const LENGTH_REQUIRED = 411;
38
+	const PRECONDITION_FAILED = 412;
39
+	const REQUEST_ENTITY_TOO_LARGE = 413;
40
+	const REQUEST_URI_TOO_LONG = 414;
41
+	const UNSUPPORTED_MEDIA_TYPE = 415;
42
+	const REQUESTED_RANGE_NOT_SATISFIABLE = 416;
43
+	const EXPECTATION_FAILED = 417;
44
+	const UNPROCESSABLE_ENTITY = 422;
45
+	const TOO_MANY_REQUESTS = 429;
46
+	const INTERNAL_SERVER_ERROR = 500;
47
+	const NOT_IMPLEMENTED = 501; // When method is supported for none of the resources
48
+
49
+	protected static $httpCodes = array(
50
+		self::OK => 'OK',
51
+		self::CREATED => 'Created',
52
+		self::ACCEPTED => 'Accepted',
53
+		self::NON_AUTHORITATIVE_INFORMATION => 'Non-Authoritative Information',
54
+		self::NO_CONTENT => 'No Content',
55
+		self::RESET_CONTENT => 'Reset Content',
56
+		self::PARTIAL_CONTENT => 'Partial Content',
57
+		self::BAD_REQUEST => 'Bad Request',
58
+		self::UNAUTHORIZED => 'Unauthorized',
59
+		self::PAYMENT_REQUIRED => 'Payment Required',
60
+		self::FORBIDDEN => 'Forbidden',
61
+		self::NOT_FOUND => 'Not Found',
62
+		self::METHOD_NOT_ALLOWED => 'Method Not Allowed',
63
+		self::NOT_ACCEPTABLE => 'Not Acceptable',
64
+		self::PROXY_AUTHENTICATION_REQUIRED => 'Proxy Authentication Required',
65
+		self::REQUEST_TIMEOUT => 'Request Timeout',
66
+		self::CONFLICT => 'Conflict',
67
+		self::GONE => 'Gone',
68
+		self::LENGTH_REQUIRED => 'Length Required',
69
+		self::PRECONDITION_FAILED => 'Precondition Failed',
70
+		self::REQUEST_ENTITY_TOO_LARGE => 'Request Entity Too Large',
71
+		self::REQUEST_URI_TOO_LONG => 'Request-URI Too Long',
72
+		self::UNSUPPORTED_MEDIA_TYPE => 'Unsupported Media Type',
73
+		self::REQUESTED_RANGE_NOT_SATISFIABLE => 'Requested Range Not Satisfiable',
74
+		self::EXPECTATION_FAILED => 'Expectation Failed',
75
+		self::UNPROCESSABLE_ENTITY => 'Unprocessable Entity',
76
+		self::TOO_MANY_REQUESTS => 'Too Many Requests',
77
+		self::INTERNAL_SERVER_ERROR => 'Internal Server Error',
78
+		self::NOT_IMPLEMENTED => 'Not Implemented',
79
+	);
80
+	private $description = '';
81
+	private $schema;
82
+
83
+	/**
84
+	 * @var Header[]
85
+	 */
86
+	private $Headers = array();
87
+
88
+	/**
89
+	 * JSON examples
90
+	 * @var array
91
+	 */
92
+	private $examples = array();
93
+
94
+	public static function getCode($search)
95
+	{
96
+		static $lookup = null;
97
+
98
+		if (is_numeric($search)) {
99
+			return intval($search);
100
+		}
101
+
102
+		// build static lookup table
103
+		if (!$lookup) {
104
+			$lookup = array();
105
+			foreach (self::$httpCodes as $code => $text) {
106
+				$lookup[preg_replace('/[^a-z]+/', '', strtolower($text))] = $code;
107
+			}
108
+		}
109
+
110
+		$search = preg_replace('/[^a-z]+/', '', strtolower($search));
111
+		return $lookup[$search] ?? null;
112
+	}
113
+
114
+	/**
115
+	 * @throws Exception
116
+	 */
117
+	public function __construct(AbstractObject $parent, $code, $definition = null, $description = null)
118
+	{
119
+		parent::__construct($parent);
120
+
121
+		if ($definition) {
122
+			$this->schema = new Schema($this, $definition);
123
+		}
124
+
125
+		if (!empty($description)) {
126
+			$this->description = $description;
127
+		} elseif (isset(self::$httpCodes[$code])) {
128
+			$this->description = self::$httpCodes[$code];
129
+		}
130
+	}
131
+
132
+	/**
133
+	 * @param string $command
134
+	 * @param string $data
135
+	 * @return AbstractObject|boolean
136
+	 * @throws Exception
137
+	 * @throws Exception
138
+	 * @throws Exception
139
+	 * @throws Exception
140
+	 * @throws Exception
141
+	 */
142
+	public function handleCommand($command, $data = null)
143
+	{
144
+		switch (strtolower($command)) {
145
+			case 'header':
146
+				$type = self::wordShift($data);
147
+				if (empty($type)) {
148
+					throw new Exception('Missing type for header');
149
+				}
150
+				$name = self::wordShift($data);
151
+				if (empty($name)) {
152
+					throw new Exception('Missing name for header type \'' . $type . '\'');
153
+				}
154
+				$Header = new Header($this, $type, $data);
155
+				$this->Headers[$name] = $Header;
156
+				return $Header;
157
+
158
+			case 'example':
159
+				$name = self::wordShift($data);
160
+				if (empty($name)) {
161
+					throw new Exception('Missing name for example');
162
+				}
163
+				if ($data === '') {
164
+					throw new Exception('Missing content for example `' . $name . '`');
165
+				}
166
+				$json = preg_replace_callback('/([^{}:]+)/', function ($match) {
167
+					json_decode($match[1]);
168
+					return json_last_error() === JSON_ERROR_NONE ? $match[1] : json_encode($match[1]);
169
+				}, trim($data));
170
+				$this->examples[$name] = json_decode($json, true);
171
+				return $this;
172
+		}
173
+
174
+		return parent::handleCommand($command, $data);
175
+	}
176
+
177
+	public function toArray()
178
+	{
179
+		return self::arrayFilterNull(array_merge(array(
180
+			'description' => $this->description,
181
+			'schema' => $this->schema ? $this->schema->toArray() : null,
182
+			'headers' => self::objectsToArray($this->Headers),
183
+			'examples' => $this->examples,
184
+		), parent::toArray()));
185
+	}
186
+
187
+	public function __toString()
188
+	{
189
+		return __CLASS__;
190
+	}
191 191
 
192 192
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -163,7 +163,7 @@
 block discarded – undo
163 163
                 if ($data === '') {
164 164
                     throw new Exception('Missing content for example `' . $name . '`');
165 165
                 }
166
-                $json = preg_replace_callback('/([^{}:]+)/', function ($match) {
166
+                $json = preg_replace_callback('/([^{}:]+)/', function($match) {
167 167
                     json_decode($match[1]);
168 168
                     return json_last_error() === JSON_ERROR_NONE ? $match[1] : json_encode($match[1]);
169 169
                 }, trim($data));
Please login to merge, or discard this patch.
SwaggerGen/Swagger/SecurityScheme.php 1 patch
Indentation   +127 added lines, -127 removed lines patch added patch discarded remove patch
@@ -16,132 +16,132 @@
 block discarded – undo
16 16
 class SecurityScheme extends AbstractObject
17 17
 {
18 18
 
19
-    /**
20
-     * 'basic', 'apikey' or 'oauth2'
21
-     * @var string
22
-     */
23
-    private $type;
24
-
25
-    /**
26
-     * @var string
27
-     */
28
-    private $description;
29
-    private $name;
30
-    private $in;
31
-    private $flow;
32
-    private $authorizationUrl;
33
-    private $tokenUrl;
34
-
35
-    /**
36
-     * Map of scope-name => description
37
-     * @var []
38
-     */
39
-    private $scopes = array();
40
-
41
-    /**
42
-     * Create a new SecurityScheme object
43
-     * @param AbstractObject $parent
44
-     * @param string $type
45
-     * @param string $data
46
-     * @throws Exception
47
-     */
48
-    public function __construct(AbstractObject $parent, $type, $data = null)
49
-    {
50
-        parent::__construct($parent);
51
-
52
-        if (!in_array(strtolower($type), array('basic', 'apikey', 'oauth2'))) {
53
-            throw new Exception("Security scheme type must be either 'basic', 'apiKey' or 'oauth2', not '{$type}'");
54
-        }
55
-        $this->type = strtolower($type);
56
-
57
-        switch ($this->type) {
58
-            case 'basic':
59
-                $this->description = $data;
60
-                break;
61
-
62
-            case 'apikey':
63
-                $this->name = self::wordShift($data);
64
-
65
-                $in = strtolower(self::wordShift($data));
66
-                if (!in_array($in, array('query', 'header'))) {
67
-                    throw new Exception("ApiKey in must be either 'query' or 'header', not '{$in}'");
68
-                }
69
-                $this->in = $in;
70
-
71
-                $this->description = $data;
72
-                break;
73
-
74
-            case 'oauth2':
75
-                $flow = strtolower(self::wordShift($data));
76
-                if (!in_array($flow, array('implicit', 'password', 'application', 'accesscode'))) {
77
-                    throw new Exception("OAuth2 flow must be either 'implicit', 'password', 'application' or 'accesscode', not '{$flow}'");
78
-                }
79
-                $this->flow = $flow;
80
-
81
-                if (in_array($flow, array('implicit', 'accesscode'))) {
82
-                    $authUrl = self::wordShift($data);
83
-                    if (!filter_var($authUrl, FILTER_VALIDATE_URL)) {
84
-                        throw new Exception("OAuth2 authorization URL invalid: '{$authUrl}'");
85
-                    }
86
-                    $this->authorizationUrl = $authUrl;
87
-                }
88
-
89
-                if (in_array($flow, array('password', 'application', 'accesscode'))) {
90
-                    $tokenUrl = self::wordShift($data);
91
-                    if (!filter_var($tokenUrl, FILTER_VALIDATE_URL)) {
92
-                        throw new Exception("OAuth2 token URL invalid: '{$tokenUrl}'");
93
-                    }
94
-                    $this->tokenUrl = $tokenUrl;
95
-                }
96
-
97
-                $this->description = $data;
98
-                break;
99
-        }
100
-    }
101
-
102
-    /**
103
-     * @param string $command
104
-     * @param string $data
105
-     * @return AbstractObject|boolean
106
-     * @throws Exception
107
-     */
108
-    public function handleCommand($command, $data = null)
109
-    {
110
-        switch (strtolower($command)) {
111
-            case 'description':
112
-                $this->description = $data;
113
-                return $this;
114
-
115
-            case 'scope':
116
-                if ($this->type !== 'oauth2') {
117
-                    throw new Exception("Cannot set scope on type '{$this->type}'");
118
-                }
119
-
120
-                $name = self::wordShift($data);
121
-                $this->scopes[$name] = $data;
122
-                return $this;
123
-        }
124
-
125
-        return parent::handleCommand($command, $data);
126
-    }
127
-
128
-    public function toArray()
129
-    {
130
-        return self::arrayFilterNull(array_merge(array(
131
-            'type' => $this->type === 'apikey' ? 'apiKey' : $this->type,
132
-            'description' => empty($this->description) ? null : $this->description,
133
-            'name' => $this->name,
134
-            'in' => $this->in,
135
-            'flow' => $this->flow === 'accesscode' ? 'accessCode' : $this->flow,
136
-            'authorizationUrl' => $this->authorizationUrl,
137
-            'tokenUrl' => $this->tokenUrl,
138
-            'scopes' => $this->scopes,
139
-        ), parent::toArray()));
140
-    }
141
-
142
-    public function __toString()
143
-    {
144
-        return __CLASS__ . ' ' . $this->type;
145
-    }
19
+	/**
20
+	 * 'basic', 'apikey' or 'oauth2'
21
+	 * @var string
22
+	 */
23
+	private $type;
24
+
25
+	/**
26
+	 * @var string
27
+	 */
28
+	private $description;
29
+	private $name;
30
+	private $in;
31
+	private $flow;
32
+	private $authorizationUrl;
33
+	private $tokenUrl;
34
+
35
+	/**
36
+	 * Map of scope-name => description
37
+	 * @var []
38
+	 */
39
+	private $scopes = array();
40
+
41
+	/**
42
+	 * Create a new SecurityScheme object
43
+	 * @param AbstractObject $parent
44
+	 * @param string $type
45
+	 * @param string $data
46
+	 * @throws Exception
47
+	 */
48
+	public function __construct(AbstractObject $parent, $type, $data = null)
49
+	{
50
+		parent::__construct($parent);
51
+
52
+		if (!in_array(strtolower($type), array('basic', 'apikey', 'oauth2'))) {
53
+			throw new Exception("Security scheme type must be either 'basic', 'apiKey' or 'oauth2', not '{$type}'");
54
+		}
55
+		$this->type = strtolower($type);
56
+
57
+		switch ($this->type) {
58
+			case 'basic':
59
+				$this->description = $data;
60
+				break;
61
+
62
+			case 'apikey':
63
+				$this->name = self::wordShift($data);
64
+
65
+				$in = strtolower(self::wordShift($data));
66
+				if (!in_array($in, array('query', 'header'))) {
67
+					throw new Exception("ApiKey in must be either 'query' or 'header', not '{$in}'");
68
+				}
69
+				$this->in = $in;
70
+
71
+				$this->description = $data;
72
+				break;
73
+
74
+			case 'oauth2':
75
+				$flow = strtolower(self::wordShift($data));
76
+				if (!in_array($flow, array('implicit', 'password', 'application', 'accesscode'))) {
77
+					throw new Exception("OAuth2 flow must be either 'implicit', 'password', 'application' or 'accesscode', not '{$flow}'");
78
+				}
79
+				$this->flow = $flow;
80
+
81
+				if (in_array($flow, array('implicit', 'accesscode'))) {
82
+					$authUrl = self::wordShift($data);
83
+					if (!filter_var($authUrl, FILTER_VALIDATE_URL)) {
84
+						throw new Exception("OAuth2 authorization URL invalid: '{$authUrl}'");
85
+					}
86
+					$this->authorizationUrl = $authUrl;
87
+				}
88
+
89
+				if (in_array($flow, array('password', 'application', 'accesscode'))) {
90
+					$tokenUrl = self::wordShift($data);
91
+					if (!filter_var($tokenUrl, FILTER_VALIDATE_URL)) {
92
+						throw new Exception("OAuth2 token URL invalid: '{$tokenUrl}'");
93
+					}
94
+					$this->tokenUrl = $tokenUrl;
95
+				}
96
+
97
+				$this->description = $data;
98
+				break;
99
+		}
100
+	}
101
+
102
+	/**
103
+	 * @param string $command
104
+	 * @param string $data
105
+	 * @return AbstractObject|boolean
106
+	 * @throws Exception
107
+	 */
108
+	public function handleCommand($command, $data = null)
109
+	{
110
+		switch (strtolower($command)) {
111
+			case 'description':
112
+				$this->description = $data;
113
+				return $this;
114
+
115
+			case 'scope':
116
+				if ($this->type !== 'oauth2') {
117
+					throw new Exception("Cannot set scope on type '{$this->type}'");
118
+				}
119
+
120
+				$name = self::wordShift($data);
121
+				$this->scopes[$name] = $data;
122
+				return $this;
123
+		}
124
+
125
+		return parent::handleCommand($command, $data);
126
+	}
127
+
128
+	public function toArray()
129
+	{
130
+		return self::arrayFilterNull(array_merge(array(
131
+			'type' => $this->type === 'apikey' ? 'apiKey' : $this->type,
132
+			'description' => empty($this->description) ? null : $this->description,
133
+			'name' => $this->name,
134
+			'in' => $this->in,
135
+			'flow' => $this->flow === 'accesscode' ? 'accessCode' : $this->flow,
136
+			'authorizationUrl' => $this->authorizationUrl,
137
+			'tokenUrl' => $this->tokenUrl,
138
+			'scopes' => $this->scopes,
139
+		), parent::toArray()));
140
+	}
141
+
142
+	public function __toString()
143
+	{
144
+		return __CLASS__ . ' ' . $this->type;
145
+	}
146 146
 
147 147
 }
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/Swagger/Path.php 2 patches
Indentation   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -16,102 +16,102 @@
 block discarded – undo
16 16
 class Path extends AbstractObject
17 17
 {
18 18
 
19
-    private static $methods = array(
20
-        'get',
21
-        'put',
22
-        'post',
23
-        'delete',
24
-        'options',
25
-        'head',
26
-        'patch',
27
-    );
28
-
29
-    /**
30
-     * @var Operation[] $operation
31
-     */
32
-    private $operations = array();
33
-
34
-    /**
35
-     * @var Tag|null $tag ;
36
-     */
37
-    private $tag;
38
-
39
-    public function __construct(AbstractObject $parent, Tag $Tag = null)
40
-    {
41
-        parent::__construct($parent);
42
-        $this->tag = $Tag;
43
-    }
44
-
45
-    /**
46
-     * @param string $command
47
-     * @param string $data
48
-     * @return AbstractObject|boolean
49
-     * @throws Exception
50
-     */
51
-    public function handleCommand($command, $data = null)
52
-    {
53
-        switch (strtolower($command)) {
54
-            case 'method': // alias
55
-            case 'operation':
56
-                $method = strtolower(self::wordShift($data));
57
-
58
-                if (!in_array($method, self::$methods)) {
59
-                    throw new Exception('Unrecognized operation method \'' . $method . '\'');
60
-                }
61
-
62
-                if (isset($this->operations[$method])) {
63
-                    $Operation = $this->operations[$method];
64
-                } else {
65
-                    $summary = $data;
66
-                    $Operation = new Operation($this, $summary, $this->tag);
67
-                    $this->operations[$method] = $Operation;
68
-                }
69
-
70
-                return $Operation;
71
-
72
-            case 'description':
73
-                if ($this->tag) {
74
-                    return $this->tag->handleCommand($command, $data);
75
-                }
76
-                break;
77
-        }
78
-
79
-        return parent::handleCommand($command, $data);
80
-    }
81
-
82
-    public function toArray()
83
-    {
84
-        $methods = self::$methods;
85
-        uksort($this->operations, function ($a, $b) use ($methods) {
86
-            return array_search($a, $methods) - array_search($b, $methods);
87
-        });
88
-
89
-        return self::arrayFilterNull(array_merge(
90
-            self::objectsToArray($this->operations)
91
-            , parent::toArray()));
92
-    }
93
-
94
-    public function __toString()
95
-    {
96
-        end($this->operations);
97
-        return __CLASS__ . ' ' . key($this->operations);
98
-    }
99
-
100
-    /**
101
-     * Check if an operation with the given id is registered to this Path.
102
-     *
103
-     * @param string $operationId
104
-     * @return boolean
105
-     */
106
-    public function hasOperationId($operationId)
107
-    {
108
-        foreach ($this->operations as $operation) {
109
-            if ($operation->getId() === $operationId) {
110
-                return true;
111
-            }
112
-        }
113
-
114
-        return false;
115
-    }
19
+	private static $methods = array(
20
+		'get',
21
+		'put',
22
+		'post',
23
+		'delete',
24
+		'options',
25
+		'head',
26
+		'patch',
27
+	);
28
+
29
+	/**
30
+	 * @var Operation[] $operation
31
+	 */
32
+	private $operations = array();
33
+
34
+	/**
35
+	 * @var Tag|null $tag ;
36
+	 */
37
+	private $tag;
38
+
39
+	public function __construct(AbstractObject $parent, Tag $Tag = null)
40
+	{
41
+		parent::__construct($parent);
42
+		$this->tag = $Tag;
43
+	}
44
+
45
+	/**
46
+	 * @param string $command
47
+	 * @param string $data
48
+	 * @return AbstractObject|boolean
49
+	 * @throws Exception
50
+	 */
51
+	public function handleCommand($command, $data = null)
52
+	{
53
+		switch (strtolower($command)) {
54
+			case 'method': // alias
55
+			case 'operation':
56
+				$method = strtolower(self::wordShift($data));
57
+
58
+				if (!in_array($method, self::$methods)) {
59
+					throw new Exception('Unrecognized operation method \'' . $method . '\'');
60
+				}
61
+
62
+				if (isset($this->operations[$method])) {
63
+					$Operation = $this->operations[$method];
64
+				} else {
65
+					$summary = $data;
66
+					$Operation = new Operation($this, $summary, $this->tag);
67
+					$this->operations[$method] = $Operation;
68
+				}
69
+
70
+				return $Operation;
71
+
72
+			case 'description':
73
+				if ($this->tag) {
74
+					return $this->tag->handleCommand($command, $data);
75
+				}
76
+				break;
77
+		}
78
+
79
+		return parent::handleCommand($command, $data);
80
+	}
81
+
82
+	public function toArray()
83
+	{
84
+		$methods = self::$methods;
85
+		uksort($this->operations, function ($a, $b) use ($methods) {
86
+			return array_search($a, $methods) - array_search($b, $methods);
87
+		});
88
+
89
+		return self::arrayFilterNull(array_merge(
90
+			self::objectsToArray($this->operations)
91
+			, parent::toArray()));
92
+	}
93
+
94
+	public function __toString()
95
+	{
96
+		end($this->operations);
97
+		return __CLASS__ . ' ' . key($this->operations);
98
+	}
99
+
100
+	/**
101
+	 * Check if an operation with the given id is registered to this Path.
102
+	 *
103
+	 * @param string $operationId
104
+	 * @return boolean
105
+	 */
106
+	public function hasOperationId($operationId)
107
+	{
108
+		foreach ($this->operations as $operation) {
109
+			if ($operation->getId() === $operationId) {
110
+				return true;
111
+			}
112
+		}
113
+
114
+		return false;
115
+	}
116 116
 
117 117
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -82,7 +82,7 @@
 block discarded – undo
82 82
     public function toArray()
83 83
     {
84 84
         $methods = self::$methods;
85
-        uksort($this->operations, function ($a, $b) use ($methods) {
85
+        uksort($this->operations, function($a, $b) use ($methods) {
86 86
             return array_search($a, $methods) - array_search($b, $methods);
87 87
         });
88 88
 
Please login to merge, or discard this patch.