Completed
Push — master ( fcb010...ba73f2 )
by Martijn
19s
created
SwaggerGen/Swagger/Type/Property.php 1 patch
Indentation   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -16,82 +16,82 @@
 block discarded – undo
16 16
 class Property extends AbstractObject
17 17
 {
18 18
 
19
-    /**
20
-     * Description of this property
21
-     * @var string
22
-     */
23
-    private $description;
19
+	/**
20
+	 * Description of this property
21
+	 * @var string
22
+	 */
23
+	private $description;
24 24
 
25
-    /**
26
-     * Whether property is read only
27
-     * @var bool
28
-     */
29
-    private $readOnly;
25
+	/**
26
+	 * Whether property is read only
27
+	 * @var bool
28
+	 */
29
+	private $readOnly;
30 30
 
31
-    /**
32
-     * Type definition of this property
33
-     * @var AbstractType
34
-     */
35
-    private $Type;
31
+	/**
32
+	 * Type definition of this property
33
+	 * @var AbstractType
34
+	 */
35
+	private $Type;
36 36
 
37
-    /**
38
-     * Create a new property
39
-     * @param AbstractObject $parent
40
-     * @param string $definition Either a built-in type or a definition name
41
-     * @param string $description description of the property
42
-     * @param bool $readOnly Whether the property is read only
43
-     * @throws Exception
44
-     */
45
-    public function __construct(AbstractObject $parent, $definition, $description = null, $readOnly = null)
46
-    {
47
-        parent::__construct($parent);
48
-        $this->Type = AbstractType::typeFactory($this, $definition, "Not a property: '%s'");
49
-        $this->description = $description;
50
-        $this->readOnly = $readOnly;
51
-    }
37
+	/**
38
+	 * Create a new property
39
+	 * @param AbstractObject $parent
40
+	 * @param string $definition Either a built-in type or a definition name
41
+	 * @param string $description description of the property
42
+	 * @param bool $readOnly Whether the property is read only
43
+	 * @throws Exception
44
+	 */
45
+	public function __construct(AbstractObject $parent, $definition, $description = null, $readOnly = null)
46
+	{
47
+		parent::__construct($parent);
48
+		$this->Type = AbstractType::typeFactory($this, $definition, "Not a property: '%s'");
49
+		$this->description = $description;
50
+		$this->readOnly = $readOnly;
51
+	}
52 52
 
53
-    /**
54
-     * @param string $command The comment command
55
-     * @param string $data Any data added after the command
56
-     * @return self|boolean
57
-     * @throws Exception
58
-     */
59
-    public function handleCommand($command, $data = null)
60
-    {
61
-        // Pass through to Type
62
-        if ($this->Type && $this->Type->handleCommand($command, $data)) {
63
-            return $this;
64
-        }
53
+	/**
54
+	 * @param string $command The comment command
55
+	 * @param string $data Any data added after the command
56
+	 * @return self|boolean
57
+	 * @throws Exception
58
+	 */
59
+	public function handleCommand($command, $data = null)
60
+	{
61
+		// Pass through to Type
62
+		if ($this->Type && $this->Type->handleCommand($command, $data)) {
63
+			return $this;
64
+		}
65 65
 
66
-        return parent::handleCommand($command, $data);
67
-    }
66
+		return parent::handleCommand($command, $data);
67
+	}
68 68
 
69
-    public function toArray(): array
70
-    {
71
-        // Reference + readonly/description result in allOf construct
72
-        // as it's semantically the same and that's what swagger tools
73
-        // like swagger-ui can understand
74
-        $requiresWrap =
75
-            $this->Type instanceof ReferenceObjectType
76
-            && (!empty($this->description) || !is_null($this->readOnly));
69
+	public function toArray(): array
70
+	{
71
+		// Reference + readonly/description result in allOf construct
72
+		// as it's semantically the same and that's what swagger tools
73
+		// like swagger-ui can understand
74
+		$requiresWrap =
75
+			$this->Type instanceof ReferenceObjectType
76
+			&& (!empty($this->description) || !is_null($this->readOnly));
77 77
 
78
-        $valueType = $this->Type->toArray();
78
+		$valueType = $this->Type->toArray();
79 79
 
80
-        if ($requiresWrap) {
81
-            $valueType = array(
82
-                'allOf' => array($valueType),
83
-            );
84
-        }
80
+		if ($requiresWrap) {
81
+			$valueType = array(
82
+				'allOf' => array($valueType),
83
+			);
84
+		}
85 85
 
86
-        return self::arrayFilterNull(array_merge($valueType, array(
87
-            'description' => empty($this->description) ? null : $this->description,
88
-            'readOnly' => $this->readOnly
89
-        ), parent::toArray()));
90
-    }
86
+		return self::arrayFilterNull(array_merge($valueType, array(
87
+			'description' => empty($this->description) ? null : $this->description,
88
+			'readOnly' => $this->readOnly
89
+		), parent::toArray()));
90
+	}
91 91
 
92
-    public function __toString()
93
-    {
94
-        return __CLASS__;
95
-    }
92
+	public function __toString()
93
+	{
94
+		return __CLASS__;
95
+	}
96 96
 
97 97
 }
Please login to merge, or discard this patch.
SwaggerGen/Swagger/Type/StringType.php 3 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -156,8 +156,8 @@
 block discarded – undo
156 156
             'format' => empty($this->format) ? null : $this->format,
157 157
             'pattern' => $this->pattern,
158 158
             'default' => $this->default,
159
-            'minLength' => $this->minLength ? (int)$this->minLength : null,
160
-            'maxLength' => $this->maxLength ? (int)$this->maxLength : null,
159
+            'minLength' => $this->minLength ? (int) $this->minLength : null,
160
+            'maxLength' => $this->maxLength ? (int) $this->maxLength : null,
161 161
             'enum' => $this->enum,
162 162
         ), parent::toArray()));
163 163
     }
Please login to merge, or discard this patch.
Upper-Lower-Casing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
             } else {
178 178
                 $type = $this->enum ? 'enum' : 'string';
179 179
             }
180
-            throw new Exception("Empty {$type} default");
180
+            throw new Exception("empty {$type} default");
181 181
         }
182 182
 
183 183
         if (!empty($this->enum) && !in_array($value, $this->enum)) {
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
             } else {
191 191
                 $type = $this->enum ? 'enum' : 'string';
192 192
             }
193
-            throw new Exception("Default {$type} length beyond maximum: '{$value}'");
193
+            throw new Exception("default {$type} length beyond maximum: '{$value}'");
194 194
         }
195 195
 
196 196
         if ($this->minLength !== null && mb_strlen($value) < $this->minLength) {
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
             } else {
200 200
                 $type = $this->enum ? 'enum' : 'string';
201 201
             }
202
-            throw new Exception("Default {$type} length beyond minimum: '{$value}'");
202
+            throw new Exception("default {$type} length beyond minimum: '{$value}'");
203 203
         }
204 204
 
205 205
         return $value;
Please login to merge, or discard this patch.
Indentation   +194 added lines, -194 removed lines patch added patch discarded remove patch
@@ -15,199 +15,199 @@
 block discarded – undo
15 15
 class StringType extends AbstractType
16 16
 {
17 17
 
18
-    private static $formats = array(
19
-        'string' => '',
20
-        'byte' => 'byte',
21
-        'binary' => 'binary',
22
-        'password' => 'password',
23
-        'enum' => '',
24
-    );
25
-
26
-    /**
27
-     * Name of the type
28
-     * @var string
29
-     */
30
-    protected $format = '';
31
-    protected $pattern = null;
32
-    protected $default = null;
33
-    protected $maxLength = null;
34
-    protected $minLength = null;
35
-    protected $enum = [];
36
-
37
-    /**
38
-     * @param string $command The comment command
39
-     * @param string $data Any data added after the command
40
-     * @return AbstractType|boolean
41
-     * @throws Exception
42
-     * @throws Exception
43
-     * @throws Exception
44
-     */
45
-    public function handleCommand($command, $data = null)
46
-    {
47
-        switch (strtolower($command)) {
48
-            case 'default':
49
-                $this->default = $this->validateDefault($data);
50
-                return $this;
51
-
52
-            case 'pattern':
53
-                $this->pattern = $data;
54
-                return $this;
55
-
56
-            case 'enum':
57
-                if ($this->minLength !== null || $this->maxLength !== null) {
58
-                    throw new Exception("Enumeration not allowed in ranged string: '{$data}'");
59
-                }
60
-                $words = self::wordSplit($data);
61
-                $this->enum = is_array($this->enum) ? array_merge($this->enum, $words) : $words;
62
-                return $this;
63
-        }
64
-
65
-        return parent::handleCommand($command, $data);
66
-    }
67
-
68
-    /**
69
-     * Validate a default string value, depending on subtype
70
-     *
71
-     * @param string $value the value to validate
72
-     * @return string the value after validation (might become trimmed)
73
-     * @throws Exception
74
-     */
75
-    protected function validateDefault($value)
76
-    {
77
-        if (empty($value)) {
78
-            if ($this->format) {
79
-                $type = $this->format;
80
-            } else {
81
-                $type = $this->enum ? 'enum' : 'string';
82
-            }
83
-            throw new Exception("Empty {$type} default");
84
-        }
85
-
86
-        if (!empty($this->enum) && !in_array($value, $this->enum)) {
87
-            throw new Exception("Invalid enum default: '{$value}'");
88
-        }
89
-
90
-        if ($this->maxLength !== null && mb_strlen($value) > $this->maxLength) {
91
-            if ($this->format) {
92
-                $type = $this->format;
93
-            } else {
94
-                $type = $this->enum ? 'enum' : 'string';
95
-            }
96
-            throw new Exception("Default {$type} length beyond maximum: '{$value}'");
97
-        }
98
-
99
-        if ($this->minLength !== null && mb_strlen($value) < $this->minLength) {
100
-            if ($this->format) {
101
-                $type = $this->format;
102
-            } else {
103
-                $type = $this->enum ? 'enum' : 'string';
104
-            }
105
-            throw new Exception("Default {$type} length beyond minimum: '{$value}'");
106
-        }
107
-
108
-        return $value;
109
-    }
110
-
111
-    public function toArray(): array
112
-    {
113
-        return self::arrayFilterNull(array_merge(array(
114
-            'type' => 'string',
115
-            'format' => empty($this->format) ? null : $this->format,
116
-            'pattern' => $this->pattern,
117
-            'default' => $this->default,
118
-            'minLength' => $this->minLength ? (int)$this->minLength : null,
119
-            'maxLength' => $this->maxLength ? (int)$this->maxLength : null,
120
-            'enum' => $this->enum,
121
-        ), parent::toArray()));
122
-    }
123
-
124
-    public function __toString()
125
-    {
126
-        return __CLASS__;
127
-    }
128
-
129
-    /**
130
-     * @throws Exception
131
-     */
132
-    protected function parseDefinition($definition)
133
-    {
134
-        $definition = self::trim($definition);
135
-
136
-        $match = [];
137
-        if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_CONTENT . self::REGEX_RANGE . self::REGEX_DEFAULT . self::REGEX_END, $definition, $match) !== 1) {
138
-            throw new Exception("Unparseable string definition: '{$definition}'");
139
-        }
140
-
141
-        $this->parseFormat($definition, $match);
142
-        $this->parseContent($definition, $match);
143
-        $this->parseRange($definition, $match);
144
-        $this->parseDefault($definition, $match);
145
-    }
146
-
147
-    /**
148
-     * @param string $definition
149
-     * @param string[] $match
150
-     * @throws Exception
151
-     */
152
-    private function parseFormat($definition, $match)
153
-    {
154
-        $type = strtolower($match[1]);
155
-        if (!isset(self::$formats[$type])) {
156
-            throw new Exception("Not a string: '{$definition}'");
157
-        }
158
-        $this->format = self::$formats[$type];
159
-    }
160
-
161
-    /**
162
-     * @param string $definition
163
-     * @param string[] $match
164
-     */
165
-    private function parseContent($definition, $match)
166
-    {
167
-        if (strtolower($match[1]) === 'enum') {
168
-            $this->enum = explode(',', $match[2]);
169
-        } else {
170
-            $this->pattern = empty($match[2]) ? null : $match[2];
171
-        }
172
-    }
173
-
174
-    /**
175
-     * @param string $definition
176
-     * @param string[] $match
177
-     * @throws Exception
178
-     * @throws Exception
179
-     */
180
-    private function parseRange($definition, $match)
181
-    {
182
-
183
-        if (!empty($match[3])) {
184
-            if ($match[1] === 'enum') {
185
-                throw new Exception("Range not allowed in enumeration definition: '{$definition}'");
186
-            }
187
-            if ($match[4] === '' && $match[5] === '') {
188
-                throw new Exception("Empty string range: '{$definition}'");
189
-            }
190
-            $exclusiveMinimum = $match[3] == '<';
191
-            $this->minLength = $match[4] === '' ? null : $match[4];
192
-            $this->maxLength = $match[5] === '' ? null : $match[5];
193
-            $exclusiveMaximum = isset($match[6]) ? ($match[6] == '>') : null;
194
-            if ($this->minLength !== null && $this->maxLength !== null && $this->minLength > $this->maxLength) {
195
-                self::swap($this->minLength, $this->maxLength);
196
-                self::swap($exclusiveMinimum, $exclusiveMaximum);
197
-            }
198
-            $this->minLength = $this->minLength === null ? null : max(0, $exclusiveMinimum ? $this->minLength + 1 : $this->minLength);
199
-            $this->maxLength = $this->maxLength === null ? null : max(0, $exclusiveMaximum ? $this->maxLength - 1 : $this->maxLength);
200
-        }
201
-    }
202
-
203
-    /**
204
-     * @param string $definition
205
-     * @param string[] $match
206
-     * @throws Exception
207
-     */
208
-    private function parseDefault($definition, $match)
209
-    {
210
-        $this->default = isset($match[7]) && $match[7] !== '' ? $this->validateDefault($match[7]) : null;
211
-    }
18
+	private static $formats = array(
19
+		'string' => '',
20
+		'byte' => 'byte',
21
+		'binary' => 'binary',
22
+		'password' => 'password',
23
+		'enum' => '',
24
+	);
25
+
26
+	/**
27
+	 * Name of the type
28
+	 * @var string
29
+	 */
30
+	protected $format = '';
31
+	protected $pattern = null;
32
+	protected $default = null;
33
+	protected $maxLength = null;
34
+	protected $minLength = null;
35
+	protected $enum = [];
36
+
37
+	/**
38
+	 * @param string $command The comment command
39
+	 * @param string $data Any data added after the command
40
+	 * @return AbstractType|boolean
41
+	 * @throws Exception
42
+	 * @throws Exception
43
+	 * @throws Exception
44
+	 */
45
+	public function handleCommand($command, $data = null)
46
+	{
47
+		switch (strtolower($command)) {
48
+			case 'default':
49
+				$this->default = $this->validateDefault($data);
50
+				return $this;
51
+
52
+			case 'pattern':
53
+				$this->pattern = $data;
54
+				return $this;
55
+
56
+			case 'enum':
57
+				if ($this->minLength !== null || $this->maxLength !== null) {
58
+					throw new Exception("Enumeration not allowed in ranged string: '{$data}'");
59
+				}
60
+				$words = self::wordSplit($data);
61
+				$this->enum = is_array($this->enum) ? array_merge($this->enum, $words) : $words;
62
+				return $this;
63
+		}
64
+
65
+		return parent::handleCommand($command, $data);
66
+	}
67
+
68
+	/**
69
+	 * Validate a default string value, depending on subtype
70
+	 *
71
+	 * @param string $value the value to validate
72
+	 * @return string the value after validation (might become trimmed)
73
+	 * @throws Exception
74
+	 */
75
+	protected function validateDefault($value)
76
+	{
77
+		if (empty($value)) {
78
+			if ($this->format) {
79
+				$type = $this->format;
80
+			} else {
81
+				$type = $this->enum ? 'enum' : 'string';
82
+			}
83
+			throw new Exception("Empty {$type} default");
84
+		}
85
+
86
+		if (!empty($this->enum) && !in_array($value, $this->enum)) {
87
+			throw new Exception("Invalid enum default: '{$value}'");
88
+		}
89
+
90
+		if ($this->maxLength !== null && mb_strlen($value) > $this->maxLength) {
91
+			if ($this->format) {
92
+				$type = $this->format;
93
+			} else {
94
+				$type = $this->enum ? 'enum' : 'string';
95
+			}
96
+			throw new Exception("Default {$type} length beyond maximum: '{$value}'");
97
+		}
98
+
99
+		if ($this->minLength !== null && mb_strlen($value) < $this->minLength) {
100
+			if ($this->format) {
101
+				$type = $this->format;
102
+			} else {
103
+				$type = $this->enum ? 'enum' : 'string';
104
+			}
105
+			throw new Exception("Default {$type} length beyond minimum: '{$value}'");
106
+		}
107
+
108
+		return $value;
109
+	}
110
+
111
+	public function toArray(): array
112
+	{
113
+		return self::arrayFilterNull(array_merge(array(
114
+			'type' => 'string',
115
+			'format' => empty($this->format) ? null : $this->format,
116
+			'pattern' => $this->pattern,
117
+			'default' => $this->default,
118
+			'minLength' => $this->minLength ? (int)$this->minLength : null,
119
+			'maxLength' => $this->maxLength ? (int)$this->maxLength : null,
120
+			'enum' => $this->enum,
121
+		), parent::toArray()));
122
+	}
123
+
124
+	public function __toString()
125
+	{
126
+		return __CLASS__;
127
+	}
128
+
129
+	/**
130
+	 * @throws Exception
131
+	 */
132
+	protected function parseDefinition($definition)
133
+	{
134
+		$definition = self::trim($definition);
135
+
136
+		$match = [];
137
+		if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_CONTENT . self::REGEX_RANGE . self::REGEX_DEFAULT . self::REGEX_END, $definition, $match) !== 1) {
138
+			throw new Exception("Unparseable string definition: '{$definition}'");
139
+		}
140
+
141
+		$this->parseFormat($definition, $match);
142
+		$this->parseContent($definition, $match);
143
+		$this->parseRange($definition, $match);
144
+		$this->parseDefault($definition, $match);
145
+	}
146
+
147
+	/**
148
+	 * @param string $definition
149
+	 * @param string[] $match
150
+	 * @throws Exception
151
+	 */
152
+	private function parseFormat($definition, $match)
153
+	{
154
+		$type = strtolower($match[1]);
155
+		if (!isset(self::$formats[$type])) {
156
+			throw new Exception("Not a string: '{$definition}'");
157
+		}
158
+		$this->format = self::$formats[$type];
159
+	}
160
+
161
+	/**
162
+	 * @param string $definition
163
+	 * @param string[] $match
164
+	 */
165
+	private function parseContent($definition, $match)
166
+	{
167
+		if (strtolower($match[1]) === 'enum') {
168
+			$this->enum = explode(',', $match[2]);
169
+		} else {
170
+			$this->pattern = empty($match[2]) ? null : $match[2];
171
+		}
172
+	}
173
+
174
+	/**
175
+	 * @param string $definition
176
+	 * @param string[] $match
177
+	 * @throws Exception
178
+	 * @throws Exception
179
+	 */
180
+	private function parseRange($definition, $match)
181
+	{
182
+
183
+		if (!empty($match[3])) {
184
+			if ($match[1] === 'enum') {
185
+				throw new Exception("Range not allowed in enumeration definition: '{$definition}'");
186
+			}
187
+			if ($match[4] === '' && $match[5] === '') {
188
+				throw new Exception("Empty string range: '{$definition}'");
189
+			}
190
+			$exclusiveMinimum = $match[3] == '<';
191
+			$this->minLength = $match[4] === '' ? null : $match[4];
192
+			$this->maxLength = $match[5] === '' ? null : $match[5];
193
+			$exclusiveMaximum = isset($match[6]) ? ($match[6] == '>') : null;
194
+			if ($this->minLength !== null && $this->maxLength !== null && $this->minLength > $this->maxLength) {
195
+				self::swap($this->minLength, $this->maxLength);
196
+				self::swap($exclusiveMinimum, $exclusiveMaximum);
197
+			}
198
+			$this->minLength = $this->minLength === null ? null : max(0, $exclusiveMinimum ? $this->minLength + 1 : $this->minLength);
199
+			$this->maxLength = $this->maxLength === null ? null : max(0, $exclusiveMaximum ? $this->maxLength - 1 : $this->maxLength);
200
+		}
201
+	}
202
+
203
+	/**
204
+	 * @param string $definition
205
+	 * @param string[] $match
206
+	 * @throws Exception
207
+	 */
208
+	private function parseDefault($definition, $match)
209
+	{
210
+		$this->default = isset($match[7]) && $match[7] !== '' ? $this->validateDefault($match[7]) : null;
211
+	}
212 212
 
213 213
 }
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(): array
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(): array
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/Schema.php 1 patch
Indentation   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -17,88 +17,88 @@
 block discarded – undo
17 17
 class Schema extends AbstractDocumentableObject implements IDefinition
18 18
 {
19 19
 
20
-    /**
21
-     * @var string
22
-     */
23
-    private $description;
24
-
25
-    /**
26
-     * @var string
27
-     */
28
-    private $title = null;
29
-
30
-    /**
31
-     * @var bool
32
-     */
33
-    private $readOnly = null;
34
-
35
-    /**
36
-     * @var AbstractType
37
-     */
38
-    private $type;
39
-
40
-    /**
41
-     * @param string $description
42
-     * @throws Exception
43
-     */
44
-    public function __construct(AbstractObject $parent, $definition = 'object', $description = null)
45
-    {
46
-        parent::__construct($parent);
47
-
48
-        // Check if definition set
49
-        if ($this->getSwagger()->hasDefinition($definition)) {
50
-            $this->type = new Type\ReferenceObjectType($this, $definition);
51
-        } else {
52
-            $this->type = Type\AbstractType::typeFactory($this, $definition);
53
-        }
54
-
55
-        $this->description = $description;
56
-    }
57
-
58
-    /**
59
-     * @param string $command
60
-     * @param string $data
61
-     * @return AbstractObject|boolean
62
-     * @throws Exception
63
-     */
64
-    public function handleCommand($command, $data = null)
65
-    {
66
-        // Pass through to Type
67
-        if ($this->type && $this->type->handleCommand($command, $data)) {
68
-            return $this;
69
-        }
70
-
71
-        // handle all the rest manually
72
-        switch (strtolower($command)) {
73
-            case 'description':
74
-                $this->description = $data;
75
-                return $this;
76
-
77
-            case 'title':
78
-                $this->title = $data;
79
-                return $this;
80
-        }
81
-
82
-        return parent::handleCommand($command, $data);
83
-    }
84
-
85
-    public function toArray(): array
86
-    {
87
-        return self::arrayFilterNull(array_merge($this->type->toArray(), array(
88
-            'title' => empty($this->title) ? null : $this->title,
89
-            'description' => empty($this->description) ? null : $this->description,
90
-            'readOnly' => $this->readOnly
91
-        ), parent::toArray()));
92
-    }
93
-
94
-    public function __toString()
95
-    {
96
-        return __CLASS__;
97
-    }
98
-
99
-    public function setReadOnly()
100
-    {
101
-        $this->readOnly = true;
102
-    }
20
+	/**
21
+	 * @var string
22
+	 */
23
+	private $description;
24
+
25
+	/**
26
+	 * @var string
27
+	 */
28
+	private $title = null;
29
+
30
+	/**
31
+	 * @var bool
32
+	 */
33
+	private $readOnly = null;
34
+
35
+	/**
36
+	 * @var AbstractType
37
+	 */
38
+	private $type;
39
+
40
+	/**
41
+	 * @param string $description
42
+	 * @throws Exception
43
+	 */
44
+	public function __construct(AbstractObject $parent, $definition = 'object', $description = null)
45
+	{
46
+		parent::__construct($parent);
47
+
48
+		// Check if definition set
49
+		if ($this->getSwagger()->hasDefinition($definition)) {
50
+			$this->type = new Type\ReferenceObjectType($this, $definition);
51
+		} else {
52
+			$this->type = Type\AbstractType::typeFactory($this, $definition);
53
+		}
54
+
55
+		$this->description = $description;
56
+	}
57
+
58
+	/**
59
+	 * @param string $command
60
+	 * @param string $data
61
+	 * @return AbstractObject|boolean
62
+	 * @throws Exception
63
+	 */
64
+	public function handleCommand($command, $data = null)
65
+	{
66
+		// Pass through to Type
67
+		if ($this->type && $this->type->handleCommand($command, $data)) {
68
+			return $this;
69
+		}
70
+
71
+		// handle all the rest manually
72
+		switch (strtolower($command)) {
73
+			case 'description':
74
+				$this->description = $data;
75
+				return $this;
76
+
77
+			case 'title':
78
+				$this->title = $data;
79
+				return $this;
80
+		}
81
+
82
+		return parent::handleCommand($command, $data);
83
+	}
84
+
85
+	public function toArray(): array
86
+	{
87
+		return self::arrayFilterNull(array_merge($this->type->toArray(), array(
88
+			'title' => empty($this->title) ? null : $this->title,
89
+			'description' => empty($this->description) ? null : $this->description,
90
+			'readOnly' => $this->readOnly
91
+		), parent::toArray()));
92
+	}
93
+
94
+	public function __toString()
95
+	{
96
+		return __CLASS__;
97
+	}
98
+
99
+	public function setReadOnly()
100
+	{
101
+		$this->readOnly = true;
102
+	}
103 103
 
104 104
 }
Please login to merge, or discard this patch.
SwaggerGen/Swagger/Response.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
         static $lookup = null;
97 97
 
98 98
         if (is_numeric($search)) {
99
-            return (int)$search;
99
+            return (int) $search;
100 100
         }
101 101
 
102 102
         // build static lookup table
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
                 if ($data === '') {
164 164
                     throw new Exception('Missing content for example `' . $name . '`');
165 165
                 }
166
-                $json = preg_replace_callback('/([^{}:]+)/', static function ($match) {
166
+                $json = preg_replace_callback('/([^{}:]+)/', static 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.
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 = [];
87
-
88
-    /**
89
-     * JSON examples
90
-     * @var array
91
-     */
92
-    private $examples = [];
93
-
94
-    /**
95
-     * @throws Exception
96
-     */
97
-    public function __construct(AbstractObject $parent, $code, $definition = null, $description = null)
98
-    {
99
-        parent::__construct($parent);
100
-
101
-        if ($definition) {
102
-            $this->schema = new Schema($this, $definition);
103
-        }
104
-
105
-        if (!empty($description)) {
106
-            $this->description = $description;
107
-        } elseif (isset(self::$httpCodes[$code])) {
108
-            $this->description = self::$httpCodes[$code];
109
-        }
110
-    }
111
-
112
-    public static function getCode($search)
113
-    {
114
-        static $lookup = null;
115
-
116
-        if (is_numeric($search)) {
117
-            return (int)$search;
118
-        }
119
-
120
-        // build static lookup table
121
-        if (!$lookup) {
122
-            $lookup = [];
123
-            foreach (self::$httpCodes as $code => $text) {
124
-                $lookup[preg_replace('/[^a-z]+/', '', strtolower($text))] = $code;
125
-            }
126
-        }
127
-
128
-        $search = preg_replace('/[^a-z]+/', '', strtolower($search));
129
-        return $lookup[$search] ?? null;
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('/([^{}:]+)/', static 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(): array
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 = [];
87
+
88
+	/**
89
+	 * JSON examples
90
+	 * @var array
91
+	 */
92
+	private $examples = [];
93
+
94
+	/**
95
+	 * @throws Exception
96
+	 */
97
+	public function __construct(AbstractObject $parent, $code, $definition = null, $description = null)
98
+	{
99
+		parent::__construct($parent);
100
+
101
+		if ($definition) {
102
+			$this->schema = new Schema($this, $definition);
103
+		}
104
+
105
+		if (!empty($description)) {
106
+			$this->description = $description;
107
+		} elseif (isset(self::$httpCodes[$code])) {
108
+			$this->description = self::$httpCodes[$code];
109
+		}
110
+	}
111
+
112
+	public static function getCode($search)
113
+	{
114
+		static $lookup = null;
115
+
116
+		if (is_numeric($search)) {
117
+			return (int)$search;
118
+		}
119
+
120
+		// build static lookup table
121
+		if (!$lookup) {
122
+			$lookup = [];
123
+			foreach (self::$httpCodes as $code => $text) {
124
+				$lookup[preg_replace('/[^a-z]+/', '', strtolower($text))] = $code;
125
+			}
126
+		}
127
+
128
+		$search = preg_replace('/[^a-z]+/', '', strtolower($search));
129
+		return $lookup[$search] ?? null;
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('/([^{}:]+)/', static 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(): array
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.
SwaggerGen/Swagger/Header.php 1 patch
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -15,50 +15,50 @@
 block discarded – undo
15 15
 class Header extends AbstractObject
16 16
 {
17 17
 
18
-    private $type;
19
-    private $description;
18
+	private $type;
19
+	private $description;
20 20
 
21
-    /**
22
-     * @throws Exception
23
-     */
24
-    public function __construct(AbstractObject $parent, $type, $description = null)
25
-    {
26
-        parent::__construct($parent);
21
+	/**
22
+	 * @throws Exception
23
+	 */
24
+	public function __construct(AbstractObject $parent, $type, $description = null)
25
+	{
26
+		parent::__construct($parent);
27 27
 
28
-        $this->type = strtolower($type);
29
-        if (!in_array($this->type, array('string', 'number', 'integer', 'boolean', 'array'))) {
30
-            throw new Exception('Header type not valid: \'' . $type . '\'');
31
-        }
28
+		$this->type = strtolower($type);
29
+		if (!in_array($this->type, array('string', 'number', 'integer', 'boolean', 'array'))) {
30
+			throw new Exception('Header type not valid: \'' . $type . '\'');
31
+		}
32 32
 
33
-        $this->description = $description;
34
-    }
33
+		$this->description = $description;
34
+	}
35 35
 
36
-    /**
37
-     * @param string $command
38
-     * @param string $data
39
-     * @return AbstractObject|boolean
40
-     */
41
-    public function handleCommand($command, $data = null)
42
-    {
43
-        if (strtolower($command) === 'description') {
44
-            $this->description = $data;
45
-            return $this;
46
-        }
36
+	/**
37
+	 * @param string $command
38
+	 * @param string $data
39
+	 * @return AbstractObject|boolean
40
+	 */
41
+	public function handleCommand($command, $data = null)
42
+	{
43
+		if (strtolower($command) === 'description') {
44
+			$this->description = $data;
45
+			return $this;
46
+		}
47 47
 
48
-        return parent::handleCommand($command, $data);
49
-    }
48
+		return parent::handleCommand($command, $data);
49
+	}
50 50
 
51
-    public function toArray(): array
52
-    {
53
-        return self::arrayFilterNull(array_merge(array(
54
-            'type' => $this->type,
55
-            'description' => empty($this->description) ? null : $this->description,
56
-        ), parent::toArray()));
57
-    }
51
+	public function toArray(): array
52
+	{
53
+		return self::arrayFilterNull(array_merge(array(
54
+			'type' => $this->type,
55
+			'description' => empty($this->description) ? null : $this->description,
56
+		), parent::toArray()));
57
+	}
58 58
 
59
-    public function __toString()
60
-    {
61
-        return __CLASS__ . ' ' . $this->type;
62
-    }
59
+	public function __toString()
60
+	{
61
+		return __CLASS__ . ' ' . $this->type;
62
+	}
63 63
 
64 64
 }
Please login to merge, or discard this patch.
SwaggerGen/Swagger/Path.php 2 patches
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(): array
83 83
     {
84 84
         $methods = self::$methods;
85
-        uksort($this->operations, static function ($a, $b) use ($methods) {
85
+        uksort($this->operations, static 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.
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 = [];
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(): array
83
-    {
84
-        $methods = self::$methods;
85
-        uksort($this->operations, static 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 = [];
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(): array
83
+	{
84
+		$methods = self::$methods;
85
+		uksort($this->operations, static 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.
SwaggerGen/Swagger/AbstractDocumentableObject.php 1 patch
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -14,38 +14,38 @@
 block discarded – undo
14 14
 abstract class AbstractDocumentableObject extends AbstractObject
15 15
 {
16 16
 
17
-    /**
18
-     * External documentation
19
-     * @var ExternalDocumentation
20
-     */
21
-    private $externalDocs = null;
17
+	/**
18
+	 * External documentation
19
+	 * @var ExternalDocumentation
20
+	 */
21
+	private $externalDocs = null;
22 22
 
23
-    /**
24
-     * @param string $command
25
-     * @param string $data
26
-     * @return AbstractObject|boolean
27
-     */
28
-    public function handleCommand($command, $data = null)
29
-    {
30
-        switch (strtolower($command)) {
31
-            case 'doc':
32
-            case 'docs':
33
-                $url = self::wordShift($data);
34
-                $this->externalDocs = new ExternalDocumentation($this, $url, $data);
35
-                return $this->externalDocs;
36
-        }
23
+	/**
24
+	 * @param string $command
25
+	 * @param string $data
26
+	 * @return AbstractObject|boolean
27
+	 */
28
+	public function handleCommand($command, $data = null)
29
+	{
30
+		switch (strtolower($command)) {
31
+			case 'doc':
32
+			case 'docs':
33
+				$url = self::wordShift($data);
34
+				$this->externalDocs = new ExternalDocumentation($this, $url, $data);
35
+				return $this->externalDocs;
36
+		}
37 37
 
38
-        return parent::handleCommand($command, $data);
39
-    }
38
+		return parent::handleCommand($command, $data);
39
+	}
40 40
 
41
-    /**
42
-     * @return array
43
-     */
44
-    public function toArray(): array
45
-    {
46
-        return self::arrayFilterNull(array_merge(array(
47
-            'externalDocs' => $this->externalDocs ? $this->externalDocs->toArray() : null,
48
-        ), parent::toArray()));
49
-    }
41
+	/**
42
+	 * @return array
43
+	 */
44
+	public function toArray(): array
45
+	{
46
+		return self::arrayFilterNull(array_merge(array(
47
+			'externalDocs' => $this->externalDocs ? $this->externalDocs->toArray() : null,
48
+		), parent::toArray()));
49
+	}
50 50
 
51 51
 }
Please login to merge, or discard this patch.
SwaggerGen/Swagger/ResponseReference.php 1 patch
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -13,25 +13,25 @@
 block discarded – undo
13 13
 class ResponseReference extends AbstractObject
14 14
 {
15 15
 
16
-    private $reference;
17
-
18
-    public function __construct(AbstractObject $parent, $reference)
19
-    {
20
-        parent::__construct($parent);
21
-
22
-        $this->reference = $reference;
23
-    }
24
-
25
-    public function toArray(): array
26
-    {
27
-        return self::arrayFilterNull(array(
28
-            '$ref' => '#/responses/' . $this->reference,
29
-        ));
30
-    }
31
-
32
-    public function __toString()
33
-    {
34
-        return __CLASS__ . ' `' . $this->reference . '`';
35
-    }
16
+	private $reference;
17
+
18
+	public function __construct(AbstractObject $parent, $reference)
19
+	{
20
+		parent::__construct($parent);
21
+
22
+		$this->reference = $reference;
23
+	}
24
+
25
+	public function toArray(): array
26
+	{
27
+		return self::arrayFilterNull(array(
28
+			'$ref' => '#/responses/' . $this->reference,
29
+		));
30
+	}
31
+
32
+	public function __toString()
33
+	{
34
+		return __CLASS__ . ' `' . $this->reference . '`';
35
+	}
36 36
 
37 37
 }
Please login to merge, or discard this patch.