Completed
Push — master ( 2f1531...a6cc58 )
by Martijn
17s
created
SwaggerGen/Swagger/Type/AbstractType.php 3 patches
Indentation   +188 added lines, -188 removed lines patch added patch discarded remove patch
@@ -16,193 +16,193 @@
 block discarded – undo
16 16
 abstract class AbstractType extends AbstractObject
17 17
 {
18 18
 
19
-    const REGEX_START = '/^';
20
-    const REGEX_FORMAT = '([a-z][a-z0-9]*)';
21
-    const REGEX_CONTENT = '(?:\((.*)\))?';
22
-    const REGEX_RANGE = '(?:([[<])(\\d*),(\\d*)([\\]>]))?';
23
-    const REGEX_DEFAULT = '(?:=(.+))?';
24
-    const REGEX_END = '$/i';
25
-
26
-    private static $classTypes = array(
27
-        'integer' => 'Integer',
28
-        'int' => 'Integer',
29
-        'int32' => 'Integer',
30
-        'int64' => 'Integer',
31
-        'long' => 'Integer',
32
-        'float' => 'Number',
33
-        'double' => 'Number',
34
-        'string' => 'String',
35
-        'uuid' => 'StringUuid',
36
-        'byte' => 'String',
37
-        'binary' => 'String',
38
-        'password' => 'String',
39
-        'enum' => 'String',
40
-        'boolean' => 'Boolean',
41
-        'bool' => 'Boolean',
42
-        'array' => 'Array',
43
-        'csv' => 'Array',
44
-        'ssv' => 'Array',
45
-        'tsv' => 'Array',
46
-        'pipes' => 'Array',
47
-        'date' => 'Date',
48
-        'datetime' => 'Date',
49
-        'date-time' => 'Date',
50
-        'object' => 'Object',
51
-        'refobject' => 'ReferenceObject',
52
-        'allof' => 'AllOf',
53
-    );
54
-
55
-    private $example = null;
56
-
57
-    /**
58
-     * Swap values of two variables.
59
-     * Used for sorting.
60
-     * @param mixed $a
61
-     * @param mixed $b
62
-     */
63
-    protected static function swap(&$a, &$b)
64
-    {
65
-        $tmp = $a;
66
-        $a = $b;
67
-        $b = $tmp;
68
-    }
69
-
70
-    /**
71
-     * @param string $list
72
-     * @return array
73
-     */
74
-    protected static function parseList($list)
75
-    {
76
-        $ret = array();
77
-        while ($item = self::parseListItem($list)) {
78
-            $ret[] = $item;
79
-        }
80
-        return $ret;
81
-    }
82
-
83
-    /**
84
-     * Extract an item from a comma-separated list of items.
85
-     *
86
-     * i.e. `a(x(x,x)),b(x)` returns `a(x(x,x))` and changes `$list` into `b(x)`.
87
-     * Note: brace nesting is not checked, e.g. `a{b(})` is a valid list item.
88
-     *
89
-     * @param string $list the list to parse
90
-     * @return string the extracted item
91
-     */
92
-    protected static function parseListItem(&$list)
93
-    {
94
-        $item = '';
95
-
96
-        $depth = 0;
97
-        $index = 0;
98
-        while ($index < strlen($list)) {
99
-            $c = $list[$index++];
100
-
101
-            if (strpos('{([<', $c) !== false) {
102
-                ++$depth;
103
-            } elseif (strpos('})]>', $c) !== false) {
104
-                --$depth;
105
-            } elseif ($c === ',' && $depth === 0) {
106
-                break;
107
-            }
108
-
109
-            $item .= $c;
110
-        }
111
-        $list = substr($list, $index);
112
-
113
-        return $item;
114
-    }
115
-
116
-    /**
117
-     * @param AbstractObject $parent
118
-     * @param $definition
119
-     * @constructor
120
-     */
121
-    public function __construct(AbstractObject $parent, $definition)
122
-    {
123
-        parent::__construct($parent);
124
-
125
-        $this->parseDefinition($definition);
126
-    }
127
-
128
-    abstract protected function parseDefinition($definition);
129
-
130
-    /**
131
-     * Overwrites default AbstractObject parser, since Types should not handle
132
-     * extensions themselves.
133
-     *
134
-     * @param string $command
135
-     * @param string $data
136
-     * @return AbstractType|boolean
137
-     * @throws Exception
138
-     */
139
-    public function handleCommand($command, $data = null)
140
-    {
141
-        if (strtolower($command) === 'example') {
142
-            if ($data === '') {
143
-                throw new Exception("Missing content for type example");
144
-            }
145
-            $json = preg_replace_callback('/([^{}:,]+)/', function ($match) {
146
-                json_decode($match[1]);
147
-                return json_last_error() === JSON_ERROR_NONE ? $match[1] : json_encode($match[1]);
148
-            }, trim($data));
149
-            $this->example = json_decode($json, true);
150
-
151
-            // In case input contains special chars, the above preg_replace would fail
152
-            //   Input could be a well-formed json already though
153
-            if ($this->example === null) {
154
-                $this->example = json_decode($data, true);
155
-            }
156
-            // If all fails, use input as-is
157
-            if ($this->example === null) {
158
-                $this->example = $data;
159
-            }
160
-
161
-            return $this;
162
-        }
163
-
164
-        return false;
165
-    }
166
-
167
-    public function toArray()
168
-    {
169
-        return self::arrayFilterNull(array_merge(array(
170
-            'example' => $this->example,
171
-        ), parent::toArray()));
172
-    }
173
-
174
-    /**
175
-     * @param AbstractObject $parent
176
-     * @param string $definition
177
-     * @param string $error
178
-     * @return self
179
-     * @throws Exception
180
-     */
181
-    public static function typeFactory($parent, $definition, $error = "Unparseable schema type definition: '%s'")
182
-    {
183
-        // Parse regex
184
-        $match = array();
185
-        if (preg_match('/^([a-z]+)/i', $definition, $match) === 1) {
186
-            $format = strtolower($match[1]);
187
-        } elseif (preg_match('/^(\[)(?:.*?)\]$/i', $definition, $match) === 1) {
188
-            $format = 'array';
189
-        } elseif (preg_match('/^(\{)(?:.*?)\}$/i', $definition, $match) === 1) {
190
-            $format = 'object';
191
-        } else {
192
-            throw new Exception(sprintf($error, $definition));
193
-        }
194
-
195
-        // Internal type if type known and not overwritten by definition
196
-        if ($parent->getTypeRegistry()->has($format)) {
197
-            $class = $parent->getTypeRegistry()->get($format);
198
-            return new $class($parent, $definition);
199
-        } elseif (isset(self::$classTypes[$format])) {
200
-            $type = self::$classTypes[$format];
201
-            $class = "\\SwaggerGen\\Swagger\\Type\\{$type}Type";
202
-            return new $class($parent, $definition);
203
-        } else {
204
-            return new ReferenceObjectType($parent, $definition);
205
-        }
206
-    }
19
+	const REGEX_START = '/^';
20
+	const REGEX_FORMAT = '([a-z][a-z0-9]*)';
21
+	const REGEX_CONTENT = '(?:\((.*)\))?';
22
+	const REGEX_RANGE = '(?:([[<])(\\d*),(\\d*)([\\]>]))?';
23
+	const REGEX_DEFAULT = '(?:=(.+))?';
24
+	const REGEX_END = '$/i';
25
+
26
+	private static $classTypes = array(
27
+		'integer' => 'Integer',
28
+		'int' => 'Integer',
29
+		'int32' => 'Integer',
30
+		'int64' => 'Integer',
31
+		'long' => 'Integer',
32
+		'float' => 'Number',
33
+		'double' => 'Number',
34
+		'string' => 'String',
35
+		'uuid' => 'StringUuid',
36
+		'byte' => 'String',
37
+		'binary' => 'String',
38
+		'password' => 'String',
39
+		'enum' => 'String',
40
+		'boolean' => 'Boolean',
41
+		'bool' => 'Boolean',
42
+		'array' => 'Array',
43
+		'csv' => 'Array',
44
+		'ssv' => 'Array',
45
+		'tsv' => 'Array',
46
+		'pipes' => 'Array',
47
+		'date' => 'Date',
48
+		'datetime' => 'Date',
49
+		'date-time' => 'Date',
50
+		'object' => 'Object',
51
+		'refobject' => 'ReferenceObject',
52
+		'allof' => 'AllOf',
53
+	);
54
+
55
+	private $example = null;
56
+
57
+	/**
58
+	 * Swap values of two variables.
59
+	 * Used for sorting.
60
+	 * @param mixed $a
61
+	 * @param mixed $b
62
+	 */
63
+	protected static function swap(&$a, &$b)
64
+	{
65
+		$tmp = $a;
66
+		$a = $b;
67
+		$b = $tmp;
68
+	}
69
+
70
+	/**
71
+	 * @param string $list
72
+	 * @return array
73
+	 */
74
+	protected static function parseList($list)
75
+	{
76
+		$ret = array();
77
+		while ($item = self::parseListItem($list)) {
78
+			$ret[] = $item;
79
+		}
80
+		return $ret;
81
+	}
82
+
83
+	/**
84
+	 * Extract an item from a comma-separated list of items.
85
+	 *
86
+	 * i.e. `a(x(x,x)),b(x)` returns `a(x(x,x))` and changes `$list` into `b(x)`.
87
+	 * Note: brace nesting is not checked, e.g. `a{b(})` is a valid list item.
88
+	 *
89
+	 * @param string $list the list to parse
90
+	 * @return string the extracted item
91
+	 */
92
+	protected static function parseListItem(&$list)
93
+	{
94
+		$item = '';
95
+
96
+		$depth = 0;
97
+		$index = 0;
98
+		while ($index < strlen($list)) {
99
+			$c = $list[$index++];
100
+
101
+			if (strpos('{([<', $c) !== false) {
102
+				++$depth;
103
+			} elseif (strpos('})]>', $c) !== false) {
104
+				--$depth;
105
+			} elseif ($c === ',' && $depth === 0) {
106
+				break;
107
+			}
108
+
109
+			$item .= $c;
110
+		}
111
+		$list = substr($list, $index);
112
+
113
+		return $item;
114
+	}
115
+
116
+	/**
117
+	 * @param AbstractObject $parent
118
+	 * @param $definition
119
+	 * @constructor
120
+	 */
121
+	public function __construct(AbstractObject $parent, $definition)
122
+	{
123
+		parent::__construct($parent);
124
+
125
+		$this->parseDefinition($definition);
126
+	}
127
+
128
+	abstract protected function parseDefinition($definition);
129
+
130
+	/**
131
+	 * Overwrites default AbstractObject parser, since Types should not handle
132
+	 * extensions themselves.
133
+	 *
134
+	 * @param string $command
135
+	 * @param string $data
136
+	 * @return AbstractType|boolean
137
+	 * @throws Exception
138
+	 */
139
+	public function handleCommand($command, $data = null)
140
+	{
141
+		if (strtolower($command) === 'example') {
142
+			if ($data === '') {
143
+				throw new Exception("Missing content for type example");
144
+			}
145
+			$json = preg_replace_callback('/([^{}:,]+)/', function ($match) {
146
+				json_decode($match[1]);
147
+				return json_last_error() === JSON_ERROR_NONE ? $match[1] : json_encode($match[1]);
148
+			}, trim($data));
149
+			$this->example = json_decode($json, true);
150
+
151
+			// In case input contains special chars, the above preg_replace would fail
152
+			//   Input could be a well-formed json already though
153
+			if ($this->example === null) {
154
+				$this->example = json_decode($data, true);
155
+			}
156
+			// If all fails, use input as-is
157
+			if ($this->example === null) {
158
+				$this->example = $data;
159
+			}
160
+
161
+			return $this;
162
+		}
163
+
164
+		return false;
165
+	}
166
+
167
+	public function toArray()
168
+	{
169
+		return self::arrayFilterNull(array_merge(array(
170
+			'example' => $this->example,
171
+		), parent::toArray()));
172
+	}
173
+
174
+	/**
175
+	 * @param AbstractObject $parent
176
+	 * @param string $definition
177
+	 * @param string $error
178
+	 * @return self
179
+	 * @throws Exception
180
+	 */
181
+	public static function typeFactory($parent, $definition, $error = "Unparseable schema type definition: '%s'")
182
+	{
183
+		// Parse regex
184
+		$match = array();
185
+		if (preg_match('/^([a-z]+)/i', $definition, $match) === 1) {
186
+			$format = strtolower($match[1]);
187
+		} elseif (preg_match('/^(\[)(?:.*?)\]$/i', $definition, $match) === 1) {
188
+			$format = 'array';
189
+		} elseif (preg_match('/^(\{)(?:.*?)\}$/i', $definition, $match) === 1) {
190
+			$format = 'object';
191
+		} else {
192
+			throw new Exception(sprintf($error, $definition));
193
+		}
194
+
195
+		// Internal type if type known and not overwritten by definition
196
+		if ($parent->getTypeRegistry()->has($format)) {
197
+			$class = $parent->getTypeRegistry()->get($format);
198
+			return new $class($parent, $definition);
199
+		} elseif (isset(self::$classTypes[$format])) {
200
+			$type = self::$classTypes[$format];
201
+			$class = "\\SwaggerGen\\Swagger\\Type\\{$type}Type";
202
+			return new $class($parent, $definition);
203
+		} else {
204
+			return new ReferenceObjectType($parent, $definition);
205
+		}
206
+	}
207 207
 
208 208
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -142,7 +142,7 @@
 block discarded – undo
142 142
             if ($data === '') {
143 143
                 throw new Exception("Missing content for type example");
144 144
             }
145
-            $json = preg_replace_callback('/([^{}:,]+)/', function ($match) {
145
+            $json = preg_replace_callback('/([^{}:,]+)/', function($match) {
146 146
                 json_decode($match[1]);
147 147
                 return json_last_error() === JSON_ERROR_NONE ? $match[1] : json_encode($match[1]);
148 148
             }, trim($data));
Please login to merge, or discard this patch.
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -198,7 +198,7 @@
 block discarded – undo
198 198
             return new $class($parent, $definition);
199 199
         } elseif (isset(self::$classTypes[$format])) {
200 200
             $type = self::$classTypes[$format];
201
-            $class = "\\SwaggerGen\\Swagger\\Type\\{$type}Type";
201
+            $class = "\\SwaggerGen\\Swagger\\Type\\{$type}type";
202 202
             return new $class($parent, $definition);
203 203
         } else {
204 204
             return new ReferenceObjectType($parent, $definition);
Please login to merge, or discard this patch.
SwaggerGen/Swagger/Type/Custom/MacType.php 1 patch
Indentation   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -17,77 +17,77 @@
 block discarded – undo
17 17
 class MacType extends StringType implements ICustomType
18 18
 {
19 19
 
20
-    const PATTERN = '^([0-9A-F]){2}(:[0-9A-F]{2}){5}$';
21
-
22
-    /**
23
-     * List of formats recognized by this class
24
-     * @var string[]
25
-     */
26
-    private static $formats = array('mac');
27
-
28
-    /**
29
-     * Construct and set up the regular expression for this type
30
-     *
31
-     * @param AbstractObject $parent
32
-     * @param string $definition
33
-     */
34
-    public function __construct(AbstractObject $parent, $definition)
35
-    {
36
-        $this->pattern = self::PATTERN;
37
-
38
-        parent::__construct($parent, $definition);
39
-    }
40
-
41
-    /**
42
-     * Parse a type definition string, assuming it belongs to this type
43
-     *
44
-     * @param string $definition
45
-     * @throws Exception
46
-     */
47
-    protected function parseDefinition($definition)
48
-    {
49
-        $definition = self::trim($definition);
50
-
51
-        $match = array();
52
-        if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_DEFAULT . self::REGEX_END, $definition, $match) !== 1) {
53
-            throw new Exception("Unparseable MAC definition: '{$definition}'");
54
-        }
55
-
56
-        if (!in_array(strtolower($match[1]), self::$formats)) {
57
-            throw new Exception("Not a MAC: '{$definition}'");
58
-        }
59
-
60
-        $this->default = isset($match[2]) && $match[2] !== '' ? $this->validateDefault($match[2]) : null;
61
-    }
62
-
63
-    /**
64
-     * Check (and optionally reformat) a default value
65
-     *
66
-     * @param string $value
67
-     * @return string
68
-     * @throws Exception
69
-     */
70
-    protected function validateDefault($value)
71
-    {
72
-        if (empty($value)) {
73
-            throw new Exception("Empty MAC default");
74
-        }
75
-
76
-        if (preg_match('/^([0-9A-F]){2}(:[0-9A-F]{2}){5}$/', $value) !== 1) {
77
-            throw new Exception("Invalid MAC default value: '{$value}'");
78
-        }
79
-
80
-        return $value;
81
-    }
82
-
83
-    public static function getFormats()
84
-    {
85
-        return self::$formats;
86
-    }
87
-
88
-    public static function setFormats(array $formats)
89
-    {
90
-        self::$formats = $formats;
91
-    }
20
+	const PATTERN = '^([0-9A-F]){2}(:[0-9A-F]{2}){5}$';
21
+
22
+	/**
23
+	 * List of formats recognized by this class
24
+	 * @var string[]
25
+	 */
26
+	private static $formats = array('mac');
27
+
28
+	/**
29
+	 * Construct and set up the regular expression for this type
30
+	 *
31
+	 * @param AbstractObject $parent
32
+	 * @param string $definition
33
+	 */
34
+	public function __construct(AbstractObject $parent, $definition)
35
+	{
36
+		$this->pattern = self::PATTERN;
37
+
38
+		parent::__construct($parent, $definition);
39
+	}
40
+
41
+	/**
42
+	 * Parse a type definition string, assuming it belongs to this type
43
+	 *
44
+	 * @param string $definition
45
+	 * @throws Exception
46
+	 */
47
+	protected function parseDefinition($definition)
48
+	{
49
+		$definition = self::trim($definition);
50
+
51
+		$match = array();
52
+		if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_DEFAULT . self::REGEX_END, $definition, $match) !== 1) {
53
+			throw new Exception("Unparseable MAC definition: '{$definition}'");
54
+		}
55
+
56
+		if (!in_array(strtolower($match[1]), self::$formats)) {
57
+			throw new Exception("Not a MAC: '{$definition}'");
58
+		}
59
+
60
+		$this->default = isset($match[2]) && $match[2] !== '' ? $this->validateDefault($match[2]) : null;
61
+	}
62
+
63
+	/**
64
+	 * Check (and optionally reformat) a default value
65
+	 *
66
+	 * @param string $value
67
+	 * @return string
68
+	 * @throws Exception
69
+	 */
70
+	protected function validateDefault($value)
71
+	{
72
+		if (empty($value)) {
73
+			throw new Exception("Empty MAC default");
74
+		}
75
+
76
+		if (preg_match('/^([0-9A-F]){2}(:[0-9A-F]{2}){5}$/', $value) !== 1) {
77
+			throw new Exception("Invalid MAC default value: '{$value}'");
78
+		}
79
+
80
+		return $value;
81
+	}
82
+
83
+	public static function getFormats()
84
+	{
85
+		return self::$formats;
86
+	}
87
+
88
+	public static function setFormats(array $formats)
89
+	{
90
+		self::$formats = $formats;
91
+	}
92 92
 
93 93
 }
Please login to merge, or discard this patch.
SwaggerGen/Swagger/Type/Custom/ICustomType.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -13,16 +13,16 @@
 block discarded – undo
13 13
 interface ICustomType
14 14
 {
15 15
 
16
-    /**
17
-     * Return a list of formats recognized by this type
18
-     * @return string[]
19
-     */
20
-    public static function getFormats();
16
+	/**
17
+	 * Return a list of formats recognized by this type
18
+	 * @return string[]
19
+	 */
20
+	public static function getFormats();
21 21
 
22
-    /**
23
-     * Overwrite format names recognized by this type
24
-     * @param string[] $formats
25
-     */
26
-    public static function setFormats(array $formats);
22
+	/**
23
+	 * Overwrite format names recognized by this type
24
+	 * @param string[] $formats
25
+	 */
26
+	public static function setFormats(array $formats);
27 27
 
28 28
 }
Please login to merge, or discard this patch.
SwaggerGen/Swagger/Type/Custom/EmailType.php 1 patch
Indentation   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -17,77 +17,77 @@
 block discarded – undo
17 17
 class EmailType extends StringType implements ICustomType
18 18
 {
19 19
 
20
-    const PATTERN = '\A[a-z0-9!#$%&\'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&\'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\z';
21
-
22
-    /**
23
-     * List of formats recognized by this class
24
-     * @var string[]
25
-     */
26
-    private static $formats = array('email');
27
-
28
-    /**
29
-     * Construct and set up the regular expression for this type
30
-     *
31
-     * @param AbstractObject $parent
32
-     * @param string $definition
33
-     */
34
-    public function __construct(AbstractObject $parent, $definition)
35
-    {
36
-        $this->pattern = self::PATTERN;
37
-
38
-        parent::__construct($parent, $definition);
39
-    }
40
-
41
-    /**
42
-     * Parse a type definition string, assuming it belongs to this type
43
-     *
44
-     * @param string $definition
45
-     * @throws Exception
46
-     */
47
-    protected function parseDefinition($definition)
48
-    {
49
-        $definition = self::trim($definition);
50
-
51
-        $match = array();
52
-        if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_DEFAULT . self::REGEX_END, $definition, $match) !== 1) {
53
-            throw new Exception("Unparseable email definition: '{$definition}'");
54
-        }
55
-
56
-        if (!in_array(strtolower($match[1]), self::$formats)) {
57
-            throw new Exception("Not an email: '{$definition}'");
58
-        }
59
-
60
-        $this->default = isset($match[2]) && $match[2] !== '' ? $this->validateDefault($match[2]) : null;
61
-    }
62
-
63
-    /**
64
-     * Check (and optionally reformat) a default value
65
-     *
66
-     * @param string $value
67
-     * @return string
68
-     * @throws Exception
69
-     */
70
-    protected function validateDefault($value)
71
-    {
72
-        if (empty($value)) {
73
-            throw new Exception("Empty email default");
74
-        }
75
-
76
-        if (filter_var($value, FILTER_VALIDATE_EMAIL) === false) {
77
-            throw new Exception("Invalid email default value: '{$value}'");
78
-        }
79
-
80
-        return $value;
81
-    }
82
-
83
-    public static function getFormats()
84
-    {
85
-        return self::$formats;
86
-    }
87
-
88
-    public static function setFormats(array $formats)
89
-    {
90
-        self::$formats = $formats;
91
-    }
20
+	const PATTERN = '\A[a-z0-9!#$%&\'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&\'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\z';
21
+
22
+	/**
23
+	 * List of formats recognized by this class
24
+	 * @var string[]
25
+	 */
26
+	private static $formats = array('email');
27
+
28
+	/**
29
+	 * Construct and set up the regular expression for this type
30
+	 *
31
+	 * @param AbstractObject $parent
32
+	 * @param string $definition
33
+	 */
34
+	public function __construct(AbstractObject $parent, $definition)
35
+	{
36
+		$this->pattern = self::PATTERN;
37
+
38
+		parent::__construct($parent, $definition);
39
+	}
40
+
41
+	/**
42
+	 * Parse a type definition string, assuming it belongs to this type
43
+	 *
44
+	 * @param string $definition
45
+	 * @throws Exception
46
+	 */
47
+	protected function parseDefinition($definition)
48
+	{
49
+		$definition = self::trim($definition);
50
+
51
+		$match = array();
52
+		if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_DEFAULT . self::REGEX_END, $definition, $match) !== 1) {
53
+			throw new Exception("Unparseable email definition: '{$definition}'");
54
+		}
55
+
56
+		if (!in_array(strtolower($match[1]), self::$formats)) {
57
+			throw new Exception("Not an email: '{$definition}'");
58
+		}
59
+
60
+		$this->default = isset($match[2]) && $match[2] !== '' ? $this->validateDefault($match[2]) : null;
61
+	}
62
+
63
+	/**
64
+	 * Check (and optionally reformat) a default value
65
+	 *
66
+	 * @param string $value
67
+	 * @return string
68
+	 * @throws Exception
69
+	 */
70
+	protected function validateDefault($value)
71
+	{
72
+		if (empty($value)) {
73
+			throw new Exception("Empty email default");
74
+		}
75
+
76
+		if (filter_var($value, FILTER_VALIDATE_EMAIL) === false) {
77
+			throw new Exception("Invalid email default value: '{$value}'");
78
+		}
79
+
80
+		return $value;
81
+	}
82
+
83
+	public static function getFormats()
84
+	{
85
+		return self::$formats;
86
+	}
87
+
88
+	public static function setFormats(array $formats)
89
+	{
90
+		self::$formats = $formats;
91
+	}
92 92
 
93 93
 }
Please login to merge, or discard this patch.
SwaggerGen/Swagger/Type/Custom/Ipv4Type.php 1 patch
Indentation   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -17,77 +17,77 @@
 block discarded – undo
17 17
 class Ipv4Type extends StringType implements ICustomType
18 18
 {
19 19
 
20
-    const PATTERN = '^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\\.|$)){4}$';
21
-
22
-    /**
23
-     * List of formats recognized by this class
24
-     * @var string[]
25
-     */
26
-    private static $formats = array('ipv4');
27
-
28
-    /**
29
-     * Construct and set up the regular expression for this type
30
-     *
31
-     * @param AbstractObject $parent
32
-     * @param string $definition
33
-     */
34
-    public function __construct(AbstractObject $parent, $definition)
35
-    {
36
-        $this->pattern = self::PATTERN;
37
-
38
-        parent::__construct($parent, $definition);
39
-    }
40
-
41
-    /**
42
-     * Parse a type definition string, assuming it belongs to this type
43
-     *
44
-     * @param string $definition
45
-     * @throws Exception
46
-     */
47
-    protected function parseDefinition($definition)
48
-    {
49
-        $definition = self::trim($definition);
50
-
51
-        $match = array();
52
-        if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_DEFAULT . self::REGEX_END, $definition, $match) !== 1) {
53
-            throw new Exception("Unparseable IPv4 definition: '{$definition}'");
54
-        }
55
-
56
-        if (!in_array(strtolower($match[1]), self::$formats)) {
57
-            throw new Exception("Not an IPv4: '{$definition}'");
58
-        }
59
-
60
-        $this->default = isset($match[2]) && $match[2] !== '' ? $this->validateDefault($match[2]) : null;
61
-    }
62
-
63
-    /**
64
-     * Check (and optionally reformat) a default value
65
-     *
66
-     * @param string $value
67
-     * @return string
68
-     * @throws Exception
69
-     */
70
-    protected function validateDefault($value)
71
-    {
72
-        if (empty($value)) {
73
-            throw new Exception("Empty IPv4 default");
74
-        }
75
-
76
-        if (filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === false) {
77
-            throw new Exception("Invalid IPv4 default value: '{$value}'");
78
-        }
79
-
80
-        return $value;
81
-    }
82
-
83
-    public static function getFormats()
84
-    {
85
-        return self::$formats;
86
-    }
87
-
88
-    public static function setFormats(array $formats)
89
-    {
90
-        self::$formats = $formats;
91
-    }
20
+	const PATTERN = '^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\\.|$)){4}$';
21
+
22
+	/**
23
+	 * List of formats recognized by this class
24
+	 * @var string[]
25
+	 */
26
+	private static $formats = array('ipv4');
27
+
28
+	/**
29
+	 * Construct and set up the regular expression for this type
30
+	 *
31
+	 * @param AbstractObject $parent
32
+	 * @param string $definition
33
+	 */
34
+	public function __construct(AbstractObject $parent, $definition)
35
+	{
36
+		$this->pattern = self::PATTERN;
37
+
38
+		parent::__construct($parent, $definition);
39
+	}
40
+
41
+	/**
42
+	 * Parse a type definition string, assuming it belongs to this type
43
+	 *
44
+	 * @param string $definition
45
+	 * @throws Exception
46
+	 */
47
+	protected function parseDefinition($definition)
48
+	{
49
+		$definition = self::trim($definition);
50
+
51
+		$match = array();
52
+		if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_DEFAULT . self::REGEX_END, $definition, $match) !== 1) {
53
+			throw new Exception("Unparseable IPv4 definition: '{$definition}'");
54
+		}
55
+
56
+		if (!in_array(strtolower($match[1]), self::$formats)) {
57
+			throw new Exception("Not an IPv4: '{$definition}'");
58
+		}
59
+
60
+		$this->default = isset($match[2]) && $match[2] !== '' ? $this->validateDefault($match[2]) : null;
61
+	}
62
+
63
+	/**
64
+	 * Check (and optionally reformat) a default value
65
+	 *
66
+	 * @param string $value
67
+	 * @return string
68
+	 * @throws Exception
69
+	 */
70
+	protected function validateDefault($value)
71
+	{
72
+		if (empty($value)) {
73
+			throw new Exception("Empty IPv4 default");
74
+		}
75
+
76
+		if (filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === false) {
77
+			throw new Exception("Invalid IPv4 default value: '{$value}'");
78
+		}
79
+
80
+		return $value;
81
+	}
82
+
83
+	public static function getFormats()
84
+	{
85
+		return self::$formats;
86
+	}
87
+
88
+	public static function setFormats(array $formats)
89
+	{
90
+		self::$formats = $formats;
91
+	}
92 92
 
93 93
 }
Please login to merge, or discard this patch.
SwaggerGen/Swagger/Type/Custom/Ipv6Type.php 1 patch
Indentation   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -17,77 +17,77 @@
 block discarded – undo
17 17
 class Ipv6Type extends StringType implements ICustomType
18 18
 {
19 19
 
20
-    const PATTERN = '(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))';
21
-
22
-    /**
23
-     * List of formats recognized by this class
24
-     * @var string[]
25
-     */
26
-    private static $formats = array('ipv6');
27
-
28
-    /**
29
-     * Construct and set up the regular expression for this type
30
-     *
31
-     * @param AbstractObject $parent
32
-     * @param string $definition
33
-     */
34
-    public function __construct(AbstractObject $parent, $definition)
35
-    {
36
-        $this->pattern = self::PATTERN;
37
-
38
-        parent::__construct($parent, $definition);
39
-    }
40
-
41
-    /**
42
-     * Parse a type definition string, assuming it belongs to this type
43
-     *
44
-     * @param string $definition
45
-     * @throws Exception
46
-     */
47
-    protected function parseDefinition($definition)
48
-    {
49
-        $definition = self::trim($definition);
50
-
51
-        $match = array();
52
-        if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_DEFAULT . self::REGEX_END, $definition, $match) !== 1) {
53
-            throw new Exception("Unparseable IPv6 definition: '{$definition}'");
54
-        }
55
-
56
-        if (!in_array(strtolower($match[1]), self::$formats)) {
57
-            throw new Exception("Not an IPv6: '{$definition}'");
58
-        }
59
-
60
-        $this->default = isset($match[2]) && $match[2] !== '' ? $this->validateDefault($match[2]) : null;
61
-    }
62
-
63
-    /**
64
-     * Check (and optionally reformat) a default value
65
-     *
66
-     * @param string $value
67
-     * @return string
68
-     * @throws Exception
69
-     */
70
-    protected function validateDefault($value)
71
-    {
72
-        if (empty($value)) {
73
-            throw new Exception("Empty IPv6 default");
74
-        }
75
-
76
-        if (filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === false) {
77
-            throw new Exception("Invalid IPv6 default value: '{$value}'");
78
-        }
79
-
80
-        return $value;
81
-    }
82
-
83
-    public static function getFormats()
84
-    {
85
-        return self::$formats;
86
-    }
87
-
88
-    public static function setFormats(array $formats)
89
-    {
90
-        self::$formats = $formats;
91
-    }
20
+	const PATTERN = '(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))';
21
+
22
+	/**
23
+	 * List of formats recognized by this class
24
+	 * @var string[]
25
+	 */
26
+	private static $formats = array('ipv6');
27
+
28
+	/**
29
+	 * Construct and set up the regular expression for this type
30
+	 *
31
+	 * @param AbstractObject $parent
32
+	 * @param string $definition
33
+	 */
34
+	public function __construct(AbstractObject $parent, $definition)
35
+	{
36
+		$this->pattern = self::PATTERN;
37
+
38
+		parent::__construct($parent, $definition);
39
+	}
40
+
41
+	/**
42
+	 * Parse a type definition string, assuming it belongs to this type
43
+	 *
44
+	 * @param string $definition
45
+	 * @throws Exception
46
+	 */
47
+	protected function parseDefinition($definition)
48
+	{
49
+		$definition = self::trim($definition);
50
+
51
+		$match = array();
52
+		if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_DEFAULT . self::REGEX_END, $definition, $match) !== 1) {
53
+			throw new Exception("Unparseable IPv6 definition: '{$definition}'");
54
+		}
55
+
56
+		if (!in_array(strtolower($match[1]), self::$formats)) {
57
+			throw new Exception("Not an IPv6: '{$definition}'");
58
+		}
59
+
60
+		$this->default = isset($match[2]) && $match[2] !== '' ? $this->validateDefault($match[2]) : null;
61
+	}
62
+
63
+	/**
64
+	 * Check (and optionally reformat) a default value
65
+	 *
66
+	 * @param string $value
67
+	 * @return string
68
+	 * @throws Exception
69
+	 */
70
+	protected function validateDefault($value)
71
+	{
72
+		if (empty($value)) {
73
+			throw new Exception("Empty IPv6 default");
74
+		}
75
+
76
+		if (filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === false) {
77
+			throw new Exception("Invalid IPv6 default value: '{$value}'");
78
+		}
79
+
80
+		return $value;
81
+	}
82
+
83
+	public static function getFormats()
84
+	{
85
+		return self::$formats;
86
+	}
87
+
88
+	public static function setFormats(array $formats)
89
+	{
90
+		self::$formats = $formats;
91
+	}
92 92
 
93 93
 }
Please login to merge, or discard this patch.
SwaggerGen/Swagger/Type/ArrayType.php 1 patch
Indentation   +176 added lines, -176 removed lines patch added patch discarded remove patch
@@ -16,181 +16,181 @@
 block discarded – undo
16 16
 class ArrayType extends AbstractType
17 17
 {
18 18
 
19
-    const REGEX_ARRAY_CONTENT = '(?:(\[)(.*)\])?';
20
-
21
-    private static $collectionFormats = array(
22
-        'array' => 'csv',
23
-        'csv' => 'csv',
24
-        'ssv' => 'ssv',
25
-        'tsv' => 'tsv',
26
-        'pipes' => 'pipes',
27
-        'multi' => 'multi',
28
-    );
29
-
30
-    /**
31
-     * @var AbstractType
32
-     */
33
-    private $Items = null;
34
-    private $minItems = null;
35
-    private $maxItems = null;
36
-    private $collectionFormat = null;
37
-
38
-    /**
39
-     * @throws Exception
40
-     */
41
-    protected function parseDefinition($definition)
42
-    {
43
-        $definition = self::trim($definition);
44
-        $match = array();
45
-        if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_CONTENT . self::REGEX_RANGE . self::REGEX_END, $definition, $match) === 1) {
46
-            $match[1] = strtolower($match[1]);
47
-        } elseif (preg_match(self::REGEX_START . self::REGEX_ARRAY_CONTENT . self::REGEX_RANGE . self::REGEX_END, $definition, $match) === 1) {
48
-            $match[1] = 'array';
49
-        } else {
50
-            throw new Exception('Unparseable array definition: \'' . $definition . '\'');
51
-        }
52
-
53
-        $this->parseFormat($definition, $match);
54
-        $this->parseItems($definition, $match);
55
-        $this->parseRange($definition, $match);
56
-    }
57
-
58
-    /**
59
-     * @param string $definition
60
-     * @param string[] $match
61
-     * @throws Exception
62
-     * @throws Exception
63
-     */
64
-    private function parseFormat($definition, $match)
65
-    {
66
-        $type = strtolower($match[1]);
67
-        if (!isset(self::$collectionFormats[$type])) {
68
-            throw new Exception("Not an array: '{$definition}'");
69
-        }
70
-
71
-        if ($type === 'multi') {
72
-            $parent = $this->getParent();
73
-            if (!($parent instanceof Parameter) || !$parent->isMulti()) {
74
-                throw new Exception("Multi array only allowed on query or form parameter: '{$definition}'");
75
-            }
76
-        }
77
-
78
-        $this->collectionFormat = self::$collectionFormats[$type];
79
-    }
80
-
81
-    /**
82
-     * @param string $definition
83
-     * @param string[] $match
84
-     * @throws Exception
85
-     */
86
-    private function parseItems($definition, $match)
87
-    {
88
-        if (!empty($match[2])) {
89
-            $this->Items = $this->validateItems($match[2]);
90
-        }
91
-    }
92
-
93
-    /**
94
-     * @param string $definition
95
-     * @param string[] $match
96
-     * @throws Exception
97
-     */
98
-    private function parseRange($definition, $match)
99
-    {
100
-        if (!empty($match[3])) {
101
-            if ($match[4] === '' && $match[5] === '') {
102
-                throw new Exception("Empty array range: '{$definition}'");
103
-            }
104
-
105
-            $exclusiveMinimum = $match[3] == '<';
106
-            $this->minItems = $match[4] === '' ? null : intval($match[4]);
107
-            $this->maxItems = $match[5] === '' ? null : intval($match[5]);
108
-            $exclusiveMaximum = isset($match[6]) ? ($match[6] == '>') : null;
109
-            if ($this->minItems && $this->maxItems && $this->minItems > $this->maxItems) {
110
-                self::swap($this->minItems, $this->maxItems);
111
-                self::swap($exclusiveMinimum, $exclusiveMaximum);
112
-            }
113
-            $this->minItems = $this->minItems === null ? null : max(0, $exclusiveMinimum ? $this->minItems + 1 : $this->minItems);
114
-            $this->maxItems = $this->maxItems === null ? null : max(0, $exclusiveMaximum ? $this->maxItems - 1 : $this->maxItems);
115
-        }
116
-    }
117
-
118
-    /**
119
-     * @param string $command The comment command
120
-     * @param string $data Any data added after the command
121
-     * @return AbstractType|boolean
122
-     * @throws Exception
123
-     * @throws Exception
124
-     * @throws Exception
125
-     * @throws Exception
126
-     * @throws Exception
127
-     * @throws Exception
128
-     * @throws Exception
129
-     */
130
-    public function handleCommand($command, $data = null)
131
-    {
132
-        if ($this->Items) {
133
-            $return = $this->Items->handleCommand($command, $data);
134
-            if ($return) {
135
-                return $return;
136
-            }
137
-        }
138
-
139
-        switch (strtolower($command)) {
140
-            case 'min':
141
-                $this->minItems = intval($data);
142
-                if ($this->minItems < 0) {
143
-                    throw new Exception("Minimum less than zero: '{$data}'");
144
-                }
145
-                if ($this->maxItems !== null && $this->minItems > $this->maxItems) {
146
-                    throw new Exception("Minimum greater than maximum: '{$data}'");
147
-                }
148
-                return $this;
149
-
150
-            case 'max':
151
-                $this->maxItems = intval($data);
152
-                if ($this->minItems !== null && $this->minItems > $this->maxItems) {
153
-                    throw new Exception("Maximum less than minimum: '{$data}'");
154
-                }
155
-                if ($this->maxItems < 0) {
156
-                    throw new Exception("Maximum less than zero: '{$data}'");
157
-                }
158
-                return $this;
159
-
160
-            case 'items':
161
-                $this->Items = $this->validateItems($data);
162
-                return $this->Items;
163
-        }
164
-
165
-        return parent::handleCommand($command, $data);
166
-    }
167
-
168
-    public function toArray()
169
-    {
170
-        return self::arrayFilterNull(array_merge(array(
171
-            'type' => 'array',
172
-            'items' => empty($this->Items) ? null : $this->Items->toArray(),
173
-            'collectionFormat' => $this->collectionFormat == 'csv' ? null : $this->collectionFormat,
174
-            'minItems' => $this->minItems,
175
-            'maxItems' => $this->maxItems,
176
-        ), parent::toArray()));
177
-    }
178
-
179
-    /**
180
-     * @throws Exception
181
-     */
182
-    private function validateItems($items)
183
-    {
184
-        if (empty($items)) {
185
-            throw new Exception("Empty items definition: '{$items}'");
186
-        }
187
-
188
-        return self::typeFactory($this, $items, "Unparseable items definition: '%s'");
189
-    }
190
-
191
-    public function __toString()
192
-    {
193
-        return __CLASS__;
194
-    }
19
+	const REGEX_ARRAY_CONTENT = '(?:(\[)(.*)\])?';
20
+
21
+	private static $collectionFormats = array(
22
+		'array' => 'csv',
23
+		'csv' => 'csv',
24
+		'ssv' => 'ssv',
25
+		'tsv' => 'tsv',
26
+		'pipes' => 'pipes',
27
+		'multi' => 'multi',
28
+	);
29
+
30
+	/**
31
+	 * @var AbstractType
32
+	 */
33
+	private $Items = null;
34
+	private $minItems = null;
35
+	private $maxItems = null;
36
+	private $collectionFormat = null;
37
+
38
+	/**
39
+	 * @throws Exception
40
+	 */
41
+	protected function parseDefinition($definition)
42
+	{
43
+		$definition = self::trim($definition);
44
+		$match = array();
45
+		if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_CONTENT . self::REGEX_RANGE . self::REGEX_END, $definition, $match) === 1) {
46
+			$match[1] = strtolower($match[1]);
47
+		} elseif (preg_match(self::REGEX_START . self::REGEX_ARRAY_CONTENT . self::REGEX_RANGE . self::REGEX_END, $definition, $match) === 1) {
48
+			$match[1] = 'array';
49
+		} else {
50
+			throw new Exception('Unparseable array definition: \'' . $definition . '\'');
51
+		}
52
+
53
+		$this->parseFormat($definition, $match);
54
+		$this->parseItems($definition, $match);
55
+		$this->parseRange($definition, $match);
56
+	}
57
+
58
+	/**
59
+	 * @param string $definition
60
+	 * @param string[] $match
61
+	 * @throws Exception
62
+	 * @throws Exception
63
+	 */
64
+	private function parseFormat($definition, $match)
65
+	{
66
+		$type = strtolower($match[1]);
67
+		if (!isset(self::$collectionFormats[$type])) {
68
+			throw new Exception("Not an array: '{$definition}'");
69
+		}
70
+
71
+		if ($type === 'multi') {
72
+			$parent = $this->getParent();
73
+			if (!($parent instanceof Parameter) || !$parent->isMulti()) {
74
+				throw new Exception("Multi array only allowed on query or form parameter: '{$definition}'");
75
+			}
76
+		}
77
+
78
+		$this->collectionFormat = self::$collectionFormats[$type];
79
+	}
80
+
81
+	/**
82
+	 * @param string $definition
83
+	 * @param string[] $match
84
+	 * @throws Exception
85
+	 */
86
+	private function parseItems($definition, $match)
87
+	{
88
+		if (!empty($match[2])) {
89
+			$this->Items = $this->validateItems($match[2]);
90
+		}
91
+	}
92
+
93
+	/**
94
+	 * @param string $definition
95
+	 * @param string[] $match
96
+	 * @throws Exception
97
+	 */
98
+	private function parseRange($definition, $match)
99
+	{
100
+		if (!empty($match[3])) {
101
+			if ($match[4] === '' && $match[5] === '') {
102
+				throw new Exception("Empty array range: '{$definition}'");
103
+			}
104
+
105
+			$exclusiveMinimum = $match[3] == '<';
106
+			$this->minItems = $match[4] === '' ? null : intval($match[4]);
107
+			$this->maxItems = $match[5] === '' ? null : intval($match[5]);
108
+			$exclusiveMaximum = isset($match[6]) ? ($match[6] == '>') : null;
109
+			if ($this->minItems && $this->maxItems && $this->minItems > $this->maxItems) {
110
+				self::swap($this->minItems, $this->maxItems);
111
+				self::swap($exclusiveMinimum, $exclusiveMaximum);
112
+			}
113
+			$this->minItems = $this->minItems === null ? null : max(0, $exclusiveMinimum ? $this->minItems + 1 : $this->minItems);
114
+			$this->maxItems = $this->maxItems === null ? null : max(0, $exclusiveMaximum ? $this->maxItems - 1 : $this->maxItems);
115
+		}
116
+	}
117
+
118
+	/**
119
+	 * @param string $command The comment command
120
+	 * @param string $data Any data added after the command
121
+	 * @return AbstractType|boolean
122
+	 * @throws Exception
123
+	 * @throws Exception
124
+	 * @throws Exception
125
+	 * @throws Exception
126
+	 * @throws Exception
127
+	 * @throws Exception
128
+	 * @throws Exception
129
+	 */
130
+	public function handleCommand($command, $data = null)
131
+	{
132
+		if ($this->Items) {
133
+			$return = $this->Items->handleCommand($command, $data);
134
+			if ($return) {
135
+				return $return;
136
+			}
137
+		}
138
+
139
+		switch (strtolower($command)) {
140
+			case 'min':
141
+				$this->minItems = intval($data);
142
+				if ($this->minItems < 0) {
143
+					throw new Exception("Minimum less than zero: '{$data}'");
144
+				}
145
+				if ($this->maxItems !== null && $this->minItems > $this->maxItems) {
146
+					throw new Exception("Minimum greater than maximum: '{$data}'");
147
+				}
148
+				return $this;
149
+
150
+			case 'max':
151
+				$this->maxItems = intval($data);
152
+				if ($this->minItems !== null && $this->minItems > $this->maxItems) {
153
+					throw new Exception("Maximum less than minimum: '{$data}'");
154
+				}
155
+				if ($this->maxItems < 0) {
156
+					throw new Exception("Maximum less than zero: '{$data}'");
157
+				}
158
+				return $this;
159
+
160
+			case 'items':
161
+				$this->Items = $this->validateItems($data);
162
+				return $this->Items;
163
+		}
164
+
165
+		return parent::handleCommand($command, $data);
166
+	}
167
+
168
+	public function toArray()
169
+	{
170
+		return self::arrayFilterNull(array_merge(array(
171
+			'type' => 'array',
172
+			'items' => empty($this->Items) ? null : $this->Items->toArray(),
173
+			'collectionFormat' => $this->collectionFormat == 'csv' ? null : $this->collectionFormat,
174
+			'minItems' => $this->minItems,
175
+			'maxItems' => $this->maxItems,
176
+		), parent::toArray()));
177
+	}
178
+
179
+	/**
180
+	 * @throws Exception
181
+	 */
182
+	private function validateItems($items)
183
+	{
184
+		if (empty($items)) {
185
+			throw new Exception("Empty items definition: '{$items}'");
186
+		}
187
+
188
+		return self::typeFactory($this, $items, "Unparseable items definition: '%s'");
189
+	}
190
+
191
+	public function __toString()
192
+	{
193
+		return __CLASS__;
194
+	}
195 195
 
196 196
 }
Please login to merge, or discard this patch.
SwaggerGen/Swagger/Type/AbstractRegexType.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -16,61 +16,61 @@
 block discarded – undo
16 16
 class AbstractRegexType extends StringType
17 17
 {
18 18
 
19
-    const REGEX_DEFAULT_START = '(?:=(';
20
-    const REGEX_DEFAULT_END = '))?';
19
+	const REGEX_DEFAULT_START = '(?:=(';
20
+	const REGEX_DEFAULT_END = '))?';
21 21
 
22
-    /**
23
-     * The raw regular expression to use.
24
-     * Exclude start (`^`) and end (`$`) anchors.
25
-     * @var string
26
-     */
27
-    private $regex;
22
+	/**
23
+	 * The raw regular expression to use.
24
+	 * Exclude start (`^`) and end (`$`) anchors.
25
+	 * @var string
26
+	 */
27
+	private $regex;
28 28
 
29
-    /**
30
-     * Construct and set up the regular expression for this type
31
-     *
32
-     * @param AbstractObject $parent
33
-     * @param string $definition
34
-     * @param string $format Name of the string format
35
-     * @param string $regex Regular expression to use as the format and for default validation
36
-     */
37
-    public function __construct(AbstractObject $parent, $definition, $format, $regex)
38
-    {
39
-        $this->format = $format;
40
-        $this->regex = $regex;
29
+	/**
30
+	 * Construct and set up the regular expression for this type
31
+	 *
32
+	 * @param AbstractObject $parent
33
+	 * @param string $definition
34
+	 * @param string $format Name of the string format
35
+	 * @param string $regex Regular expression to use as the format and for default validation
36
+	 */
37
+	public function __construct(AbstractObject $parent, $definition, $format, $regex)
38
+	{
39
+		$this->format = $format;
40
+		$this->regex = $regex;
41 41
 
42
-        parent::__construct($parent, $definition);
43
-    }
42
+		parent::__construct($parent, $definition);
43
+	}
44 44
 
45
-    /**
46
-     * @throws Exception
47
-     */
48
-    protected function parseDefinition($definition)
49
-    {
50
-        $definition = self::trim($definition);
45
+	/**
46
+	 * @throws Exception
47
+	 */
48
+	protected function parseDefinition($definition)
49
+	{
50
+		$definition = self::trim($definition);
51 51
 
52
-        $match = array();
53
-        if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_DEFAULT_START . $this->regex . self::REGEX_DEFAULT_END . self::REGEX_END, $definition, $match) !== 1) {
54
-            throw new Exception('Unparseable ' . $this->format . ' definition: \'' . $definition . '\'');
55
-        }
52
+		$match = array();
53
+		if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_DEFAULT_START . $this->regex . self::REGEX_DEFAULT_END . self::REGEX_END, $definition, $match) !== 1) {
54
+			throw new Exception('Unparseable ' . $this->format . ' definition: \'' . $definition . '\'');
55
+		}
56 56
 
57
-        if (strtolower($match[1] !== $this->format)) {
58
-            throw new Exception('Not a ' . $this->format . ': \'' . $definition . '\'');
59
-        }
57
+		if (strtolower($match[1] !== $this->format)) {
58
+			throw new Exception('Not a ' . $this->format . ': \'' . $definition . '\'');
59
+		}
60 60
 
61
-        $this->pattern = '^' . $this->regex . '$';
62
-        $this->default = isset($match[2]) && $match[2] !== '' ? $this->validateDefault($match[2]) : null;
63
-    }
61
+		$this->pattern = '^' . $this->regex . '$';
62
+		$this->default = isset($match[2]) && $match[2] !== '' ? $this->validateDefault($match[2]) : null;
63
+	}
64 64
 
65
-    protected function validateDefault($value)
66
-    {
67
-        $value = parent::validateDefault($value);
65
+	protected function validateDefault($value)
66
+	{
67
+		$value = parent::validateDefault($value);
68 68
 
69
-        if (preg_match('/' . $this->pattern . '/', $value) !== 1) {
70
-            throw new Exception('Invalid ' . $this->format . ' default value');
71
-        }
69
+		if (preg_match('/' . $this->pattern . '/', $value) !== 1) {
70
+			throw new Exception('Invalid ' . $this->format . ' default value');
71
+		}
72 72
 
73
-        return $value;
74
-    }
73
+		return $value;
74
+	}
75 75
 
76 76
 }
Please login to merge, or discard this patch.
SwaggerGen/Swagger/Type/ObjectType.php 1 patch
Indentation   +250 added lines, -250 removed lines patch added patch discarded remove patch
@@ -15,281 +15,281 @@
 block discarded – undo
15 15
 class ObjectType extends AbstractType
16 16
 {
17 17
 
18
-    const REGEX_OBJECT_CONTENT = '(?:(\{)(.*)\})?';
19
-    const REGEX_PROP_START = '/^';
20
-    const REGEX_PROP_NAME = '([^?!:]+)';
21
-    const REGEX_PROP_REQUIRED = '([\?!])?';
22
-    const REGEX_PROP_ASSIGN = ':';
23
-    const REGEX_PROP_DEFINITION = '(.+)';
24
-    const REGEX_PROP_ADDITIONAL = '\.\.\.(!|.+)?';
25
-    const REGEX_PROP_END = '$/';
18
+	const REGEX_OBJECT_CONTENT = '(?:(\{)(.*)\})?';
19
+	const REGEX_PROP_START = '/^';
20
+	const REGEX_PROP_NAME = '([^?!:]+)';
21
+	const REGEX_PROP_REQUIRED = '([\?!])?';
22
+	const REGEX_PROP_ASSIGN = ':';
23
+	const REGEX_PROP_DEFINITION = '(.+)';
24
+	const REGEX_PROP_ADDITIONAL = '\.\.\.(!|.+)?';
25
+	const REGEX_PROP_END = '$/';
26 26
 
27
-    private $minProperties = null;
28
-    private $maxProperties = null;
29
-    private $discriminator = null;
30
-    private $additionalProperties = null;
31
-    private $required = array();
27
+	private $minProperties = null;
28
+	private $maxProperties = null;
29
+	private $discriminator = null;
30
+	private $additionalProperties = null;
31
+	private $required = array();
32 32
 
33
-    /**
34
-     * @var Property[]
35
-     */
36
-    private $properties = array();
33
+	/**
34
+	 * @var Property[]
35
+	 */
36
+	private $properties = array();
37 37
 
38
-    /**
39
-     * @var Property
40
-     */
41
-    private $mostRecentProperty = null;
38
+	/**
39
+	 * @var Property
40
+	 */
41
+	private $mostRecentProperty = null;
42 42
 
43
-    /**
44
-     * @throws Exception
45
-     */
46
-    protected function parseDefinition($definition)
47
-    {
48
-        $definition = self::trim($definition);
43
+	/**
44
+	 * @throws Exception
45
+	 */
46
+	protected function parseDefinition($definition)
47
+	{
48
+		$definition = self::trim($definition);
49 49
 
50
-        $match = array();
51
-        if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_CONTENT . self::REGEX_RANGE . self::REGEX_END, $definition, $match) === 1) {
52
-            $match[1] = strtolower($match[1]);
53
-        } elseif (preg_match(self::REGEX_START . self::REGEX_OBJECT_CONTENT . self::REGEX_RANGE . self::REGEX_END, $definition, $match) === 1) {
54
-            $match[1] = 'object';
55
-        } else {
56
-            throw new Exception('Unparseable object definition: \'' . $definition . '\'');
57
-        }
50
+		$match = array();
51
+		if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_CONTENT . self::REGEX_RANGE . self::REGEX_END, $definition, $match) === 1) {
52
+			$match[1] = strtolower($match[1]);
53
+		} elseif (preg_match(self::REGEX_START . self::REGEX_OBJECT_CONTENT . self::REGEX_RANGE . self::REGEX_END, $definition, $match) === 1) {
54
+			$match[1] = 'object';
55
+		} else {
56
+			throw new Exception('Unparseable object definition: \'' . $definition . '\'');
57
+		}
58 58
 
59
-        $this->parseFormat($definition, $match);
60
-        $this->parseProperties($definition, $match);
61
-        $this->parseRange($definition, $match);
62
-    }
59
+		$this->parseFormat($definition, $match);
60
+		$this->parseProperties($definition, $match);
61
+		$this->parseRange($definition, $match);
62
+	}
63 63
 
64
-    /**
65
-     * @param string $definition
66
-     * @param string[] $match
67
-     * @throws Exception
68
-     */
69
-    private function parseFormat($definition, $match)
70
-    {
71
-        if (strtolower($match[1]) !== 'object') {
72
-            throw new Exception("Not an object: '{$definition}'");
73
-        }
74
-    }
64
+	/**
65
+	 * @param string $definition
66
+	 * @param string[] $match
67
+	 * @throws Exception
68
+	 */
69
+	private function parseFormat($definition, $match)
70
+	{
71
+		if (strtolower($match[1]) !== 'object') {
72
+			throw new Exception("Not an object: '{$definition}'");
73
+		}
74
+	}
75 75
 
76
-    /**
77
-     * @param AbstractType|bool $type
78
-     * @return void
79
-     * @throws Exception
80
-     */
81
-    private function setAdditionalProperties($type)
82
-    {
83
-        if ($this->additionalProperties !== null) {
84
-            throw new Exception('Additional properties may only be set once');
85
-        }
86
-        $this->additionalProperties = $type;
87
-    }
76
+	/**
77
+	 * @param AbstractType|bool $type
78
+	 * @return void
79
+	 * @throws Exception
80
+	 */
81
+	private function setAdditionalProperties($type)
82
+	{
83
+		if ($this->additionalProperties !== null) {
84
+			throw new Exception('Additional properties may only be set once');
85
+		}
86
+		$this->additionalProperties = $type;
87
+	}
88 88
 
89
-    /**
90
-     * @param string $definition
91
-     * @param string[] $match
92
-     * @throws Exception
93
-     * @throws Exception
94
-     * @throws Exception
95
-     * @throws Exception
96
-     * @throws Exception
97
-     * @throws Exception
98
-     */
99
-    private function parseProperties($definition, $match)
100
-    {
101
-        if (empty($match[2])) {
102
-            return;
103
-        }
89
+	/**
90
+	 * @param string $definition
91
+	 * @param string[] $match
92
+	 * @throws Exception
93
+	 * @throws Exception
94
+	 * @throws Exception
95
+	 * @throws Exception
96
+	 * @throws Exception
97
+	 * @throws Exception
98
+	 */
99
+	private function parseProperties($definition, $match)
100
+	{
101
+		if (empty($match[2])) {
102
+			return;
103
+		}
104 104
 
105
-        while (($property = self::parseListItem($match[2])) !== '') {
106
-            $prop_match = array();
107
-            if (preg_match(self::REGEX_PROP_START . self::REGEX_PROP_ADDITIONAL . self::REGEX_PROP_END, $property, $prop_match) === 1) {
108
-                if (empty($prop_match[1])) {
109
-                    $this->setAdditionalProperties(true);
110
-                } else if ($prop_match[1] === '!') {
111
-                    $this->setAdditionalProperties(false);
112
-                } else {
113
-                    $this->setAdditionalProperties(self::typeFactory($this, $prop_match[1], "Unparseable additional properties definition: '...%s'"));
114
-                }
115
-                continue;
116
-            }
117
-            if (preg_match(self::REGEX_PROP_START . self::REGEX_PROP_NAME . self::REGEX_PROP_REQUIRED . self::REGEX_PROP_ASSIGN . self::REGEX_PROP_DEFINITION . self::REGEX_PROP_END, $property, $prop_match) !== 1) {
118
-                throw new Exception("Unparseable property definition: '{$property}'");
119
-            }
120
-            $this->properties[$prop_match[1]] = new Property($this, $prop_match[3]);
121
-            if ($prop_match[2] !== '!' && $prop_match[2] !== '?') {
122
-                $this->required[$prop_match[1]] = true;
123
-            }
124
-        }
105
+		while (($property = self::parseListItem($match[2])) !== '') {
106
+			$prop_match = array();
107
+			if (preg_match(self::REGEX_PROP_START . self::REGEX_PROP_ADDITIONAL . self::REGEX_PROP_END, $property, $prop_match) === 1) {
108
+				if (empty($prop_match[1])) {
109
+					$this->setAdditionalProperties(true);
110
+				} else if ($prop_match[1] === '!') {
111
+					$this->setAdditionalProperties(false);
112
+				} else {
113
+					$this->setAdditionalProperties(self::typeFactory($this, $prop_match[1], "Unparseable additional properties definition: '...%s'"));
114
+				}
115
+				continue;
116
+			}
117
+			if (preg_match(self::REGEX_PROP_START . self::REGEX_PROP_NAME . self::REGEX_PROP_REQUIRED . self::REGEX_PROP_ASSIGN . self::REGEX_PROP_DEFINITION . self::REGEX_PROP_END, $property, $prop_match) !== 1) {
118
+				throw new Exception("Unparseable property definition: '{$property}'");
119
+			}
120
+			$this->properties[$prop_match[1]] = new Property($this, $prop_match[3]);
121
+			if ($prop_match[2] !== '!' && $prop_match[2] !== '?') {
122
+				$this->required[$prop_match[1]] = true;
123
+			}
124
+		}
125 125
 
126
-    }
126
+	}
127 127
 
128
-    /**
129
-     * @param string $definition
130
-     * @param string[] $match
131
-     * @throws Exception
132
-     */
133
-    private function parseRange($definition, $match)
134
-    {
135
-        if (!empty($match[3])) {
136
-            if ($match[4] === '' && $match[5] === '') {
137
-                throw new Exception("Empty object range: '{$definition}'");
138
-            }
128
+	/**
129
+	 * @param string $definition
130
+	 * @param string[] $match
131
+	 * @throws Exception
132
+	 */
133
+	private function parseRange($definition, $match)
134
+	{
135
+		if (!empty($match[3])) {
136
+			if ($match[4] === '' && $match[5] === '') {
137
+				throw new Exception("Empty object range: '{$definition}'");
138
+			}
139 139
 
140
-            $exclusiveMinimum = $match[3] == '<';
141
-            $this->minProperties = $match[4] === '' ? null : intval($match[4]);
142
-            $this->maxProperties = $match[5] === '' ? null : intval($match[5]);
143
-            $exclusiveMaximum = isset($match[6]) ? ($match[6] == '>') : null;
144
-            if ($this->minProperties && $this->maxProperties && $this->minProperties > $this->maxProperties) {
145
-                self::swap($this->minProperties, $this->maxProperties);
146
-                self::swap($exclusiveMinimum, $exclusiveMaximum);
147
-            }
148
-            $this->minProperties = $this->minProperties === null ? null : max(0, $exclusiveMinimum ? $this->minProperties + 1 : $this->minProperties);
149
-            $this->maxProperties = $this->maxProperties === null ? null : max(0, $exclusiveMaximum ? $this->maxProperties - 1 : $this->maxProperties);
150
-        }
151
-    }
140
+			$exclusiveMinimum = $match[3] == '<';
141
+			$this->minProperties = $match[4] === '' ? null : intval($match[4]);
142
+			$this->maxProperties = $match[5] === '' ? null : intval($match[5]);
143
+			$exclusiveMaximum = isset($match[6]) ? ($match[6] == '>') : null;
144
+			if ($this->minProperties && $this->maxProperties && $this->minProperties > $this->maxProperties) {
145
+				self::swap($this->minProperties, $this->maxProperties);
146
+				self::swap($exclusiveMinimum, $exclusiveMaximum);
147
+			}
148
+			$this->minProperties = $this->minProperties === null ? null : max(0, $exclusiveMinimum ? $this->minProperties + 1 : $this->minProperties);
149
+			$this->maxProperties = $this->maxProperties === null ? null : max(0, $exclusiveMaximum ? $this->maxProperties - 1 : $this->maxProperties);
150
+		}
151
+	}
152 152
 
153
-    /**
154
-     * @param string|false $discriminator
155
-     * @throws Exception
156
-     * @throws Exception
157
-     */
158
-    private function setDiscriminator($discriminator)
159
-    {
160
-        if (!empty($this->discriminator)) {
161
-            throw new Exception("Discriminator may only be set once, "
162
-                . "trying to change it "
163
-                . "from '{$this->discriminator}' "
164
-                . "to '{$discriminator}'");
165
-        }
166
-        if (isset($this->properties[$discriminator]) && empty($this->required[$discriminator])) {
167
-            throw new Exception("Discriminator must be a required property, "
168
-                . "property '{$discriminator}' is not required");
169
-        }
170
-        $this->discriminator = $discriminator;
171
-    }
153
+	/**
154
+	 * @param string|false $discriminator
155
+	 * @throws Exception
156
+	 * @throws Exception
157
+	 */
158
+	private function setDiscriminator($discriminator)
159
+	{
160
+		if (!empty($this->discriminator)) {
161
+			throw new Exception("Discriminator may only be set once, "
162
+				. "trying to change it "
163
+				. "from '{$this->discriminator}' "
164
+				. "to '{$discriminator}'");
165
+		}
166
+		if (isset($this->properties[$discriminator]) && empty($this->required[$discriminator])) {
167
+			throw new Exception("Discriminator must be a required property, "
168
+				. "property '{$discriminator}' is not required");
169
+		}
170
+		$this->discriminator = $discriminator;
171
+	}
172 172
 
173
-    /**
174
-     * @param string $command The comment command
175
-     * @param string $data Any data added after the command
176
-     * @return AbstractType|boolean
177
-     * @throws Exception
178
-     * @throws Exception
179
-     * @throws Exception
180
-     * @throws Exception
181
-     * @throws Exception
182
-     * @throws Exception
183
-     * @throws Exception
184
-     * @throws Exception
185
-     * @throws Exception
186
-     * @throws Exception
187
-     * @throws Exception
188
-     * @throws Exception
189
-     */
190
-    public function handleCommand($command, $data = null)
191
-    {
192
-        switch (strtolower($command)) {
193
-            // type name description...
194
-            case 'additionalproperties':
195
-                $value = self::wordShift($data);
196
-                if (is_bool($value)) {
197
-                    $type = $value;
198
-                } else if ($value === 'false') {
199
-                    $type = false;
200
-                } else if ($value === 'true') {
201
-                    $type = true;
202
-                } else {
203
-                    $type = self::typeFactory($this, $value, "Unparseable additional properties definition: '%s'");
204
-                }
205
-                $this->setAdditionalProperties($type);
206
-                return $this;
207
-            case 'discriminator':
208
-                $discriminator = self::wordShift($data);
209
-                $this->setDiscriminator($discriminator);
210
-                return $this;
211
-            case 'property':
212
-            case 'property?':
213
-            case 'property!':
214
-                $definition = self::wordShift($data);
215
-                if (empty($definition)) {
216
-                    throw new Exception("Missing property definition");
217
-                }
173
+	/**
174
+	 * @param string $command The comment command
175
+	 * @param string $data Any data added after the command
176
+	 * @return AbstractType|boolean
177
+	 * @throws Exception
178
+	 * @throws Exception
179
+	 * @throws Exception
180
+	 * @throws Exception
181
+	 * @throws Exception
182
+	 * @throws Exception
183
+	 * @throws Exception
184
+	 * @throws Exception
185
+	 * @throws Exception
186
+	 * @throws Exception
187
+	 * @throws Exception
188
+	 * @throws Exception
189
+	 */
190
+	public function handleCommand($command, $data = null)
191
+	{
192
+		switch (strtolower($command)) {
193
+			// type name description...
194
+			case 'additionalproperties':
195
+				$value = self::wordShift($data);
196
+				if (is_bool($value)) {
197
+					$type = $value;
198
+				} else if ($value === 'false') {
199
+					$type = false;
200
+				} else if ($value === 'true') {
201
+					$type = true;
202
+				} else {
203
+					$type = self::typeFactory($this, $value, "Unparseable additional properties definition: '%s'");
204
+				}
205
+				$this->setAdditionalProperties($type);
206
+				return $this;
207
+			case 'discriminator':
208
+				$discriminator = self::wordShift($data);
209
+				$this->setDiscriminator($discriminator);
210
+				return $this;
211
+			case 'property':
212
+			case 'property?':
213
+			case 'property!':
214
+				$definition = self::wordShift($data);
215
+				if (empty($definition)) {
216
+					throw new Exception("Missing property definition");
217
+				}
218 218
 
219
-                $name = self::wordShift($data);
220
-                if (empty($name)) {
221
-                    throw new Exception("Missing property name: '{$definition}'");
222
-                }
219
+				$name = self::wordShift($data);
220
+				if (empty($name)) {
221
+					throw new Exception("Missing property name: '{$definition}'");
222
+				}
223 223
 
224
-                $readOnly = null;
225
-                $required = false;
226
-                $propertySuffix = substr($command, -1);
227
-                if ($propertySuffix === '!') {
228
-                    $readOnly = true;
229
-                } else if ($propertySuffix !== '?') {
230
-                    $required = true;
231
-                }
224
+				$readOnly = null;
225
+				$required = false;
226
+				$propertySuffix = substr($command, -1);
227
+				if ($propertySuffix === '!') {
228
+					$readOnly = true;
229
+				} else if ($propertySuffix !== '?') {
230
+					$required = true;
231
+				}
232 232
 
233
-                if (($name === $this->discriminator) && !$required) {
234
-                    throw new Exception("Discriminator must be a required property, "
235
-                        . "property '{$name}' is not required");
236
-                }
233
+				if (($name === $this->discriminator) && !$required) {
234
+					throw new Exception("Discriminator must be a required property, "
235
+						. "property '{$name}' is not required");
236
+				}
237 237
 
238
-                unset($this->required[$name]);
239
-                if ($required) {
240
-                    $this->required[$name] = true;
241
-                }
238
+				unset($this->required[$name]);
239
+				if ($required) {
240
+					$this->required[$name] = true;
241
+				}
242 242
 
243
-                $this->mostRecentProperty = new Property($this, $definition, $data, $readOnly);
244
-                $this->properties[$name] = $this->mostRecentProperty;
245
-                return $this;
243
+				$this->mostRecentProperty = new Property($this, $definition, $data, $readOnly);
244
+				$this->properties[$name] = $this->mostRecentProperty;
245
+				return $this;
246 246
 
247
-            case 'min':
248
-                $this->minProperties = intval($data);
249
-                if ($this->minProperties < 0) {
250
-                    throw new Exception("Minimum less than zero: '{$data}'");
251
-                }
252
-                if ($this->maxProperties !== null && $this->minProperties > $this->maxProperties) {
253
-                    throw new Exception("Minimum greater than maximum: '{$data}'");
254
-                }
255
-                $this->minProperties = intval($data);
256
-                return $this;
247
+			case 'min':
248
+				$this->minProperties = intval($data);
249
+				if ($this->minProperties < 0) {
250
+					throw new Exception("Minimum less than zero: '{$data}'");
251
+				}
252
+				if ($this->maxProperties !== null && $this->minProperties > $this->maxProperties) {
253
+					throw new Exception("Minimum greater than maximum: '{$data}'");
254
+				}
255
+				$this->minProperties = intval($data);
256
+				return $this;
257 257
 
258
-            case 'max':
259
-                $this->maxProperties = intval($data);
260
-                if ($this->minProperties !== null && $this->minProperties > $this->maxProperties) {
261
-                    throw new Exception("Maximum less than minimum: '{$data}'");
262
-                }
263
-                if ($this->maxProperties < 0) {
264
-                    throw new Exception("Maximum less than zero: '{$data}'");
265
-                }
266
-                return $this;
267
-        }
258
+			case 'max':
259
+				$this->maxProperties = intval($data);
260
+				if ($this->minProperties !== null && $this->minProperties > $this->maxProperties) {
261
+					throw new Exception("Maximum less than minimum: '{$data}'");
262
+				}
263
+				if ($this->maxProperties < 0) {
264
+					throw new Exception("Maximum less than zero: '{$data}'");
265
+				}
266
+				return $this;
267
+		}
268 268
 
269
-        // Pass through to most recent Property
270
-        if ($this->mostRecentProperty && $this->mostRecentProperty->handleCommand($command, $data)) {
271
-            return $this;
272
-        }
269
+		// Pass through to most recent Property
270
+		if ($this->mostRecentProperty && $this->mostRecentProperty->handleCommand($command, $data)) {
271
+			return $this;
272
+		}
273 273
 
274
-        return parent::handleCommand($command, $data);
275
-    }
274
+		return parent::handleCommand($command, $data);
275
+	}
276 276
 
277
-    public function toArray()
278
-    {
279
-        return self::arrayFilterNull(array_merge(array(
280
-            'type' => 'object',
281
-            'required' => array_keys($this->required),
282
-            'properties' => self::objectsToArray($this->properties),
283
-            'minProperties' => $this->minProperties,
284
-            'maxProperties' => $this->maxProperties,
285
-            'discriminator' => $this->discriminator,
286
-            'additionalProperties' => $this->additionalProperties instanceof AbstractType ? $this->additionalProperties->toArray() : $this->additionalProperties,
287
-        ), parent::toArray()));
288
-    }
277
+	public function toArray()
278
+	{
279
+		return self::arrayFilterNull(array_merge(array(
280
+			'type' => 'object',
281
+			'required' => array_keys($this->required),
282
+			'properties' => self::objectsToArray($this->properties),
283
+			'minProperties' => $this->minProperties,
284
+			'maxProperties' => $this->maxProperties,
285
+			'discriminator' => $this->discriminator,
286
+			'additionalProperties' => $this->additionalProperties instanceof AbstractType ? $this->additionalProperties->toArray() : $this->additionalProperties,
287
+		), parent::toArray()));
288
+	}
289 289
 
290
-    public function __toString()
291
-    {
292
-        return __CLASS__;
293
-    }
290
+	public function __toString()
291
+	{
292
+		return __CLASS__;
293
+	}
294 294
 
295 295
 }
Please login to merge, or discard this patch.