Completed
Push — master ( fcb010...ba73f2 )
by Martijn
19s
created
SwaggerGen/Parser/Php/Entity/ParserClass.php 1 patch
Indentation   +115 added lines, -115 removed lines patch added patch discarded remove patch
@@ -15,120 +15,120 @@
 block discarded – undo
15 15
 class ParserClass extends AbstractEntity
16 16
 {
17 17
 
18
-    /**
19
-     * @var string
20
-     */
21
-    public $name = null;
22
-
23
-    /**
24
-     * @var ParserFunction[]
25
-     */
26
-    public $Methods = [];
27
-
28
-    /**
29
-     * @var string
30
-     */
31
-    public $extends = null;
32
-
33
-    /**
34
-     * @var string[]
35
-     */
36
-    public $implements = [];
37
-    private $lastStatements = null;
38
-
39
-    public function __construct(Parser $Parser, &$tokens, $Statements)
40
-    {
41
-        if ($Statements) {
42
-            $this->Statements = array_merge($this->Statements, $Statements);
43
-        }
44
-
45
-        $depth = 0;
46
-
47
-        $mode = T_CLASS;
48
-
49
-        $token = current($tokens);
50
-        while ($token) {
51
-            switch ($token[0]) {
52
-                case T_STRING:
53
-                    switch ($mode) {
54
-                        case T_CLASS:
55
-                            $this->name = $token[1];
56
-                            $mode = null;
57
-                            break;
58
-
59
-                        case T_EXTENDS:
60
-                            $Parser->queueClass($token[1]);
61
-                            $this->extends = $token[1];
62
-                            $mode = null;
63
-                            break;
64
-
65
-                        case T_IMPLEMENTS:
66
-                            $Parser->queueClass($token[1]);
67
-                            $this->implements[] = $token[1];
68
-                            break;
69
-                    }
70
-                    break;
71
-
72
-                case '{':
73
-                case T_CURLY_OPEN:
74
-                case T_DOLLAR_OPEN_CURLY_BRACES:
75
-                case T_STRING_VARNAME:
76
-                    $mode = null;
77
-                    ++$depth;
78
-                    break;
79
-
80
-                case '}':
81
-                    --$depth;
82
-                    if ($depth == 0) {
83
-                        if ($this->lastStatements) {
84
-                            $this->Statements = array_merge($this->Statements, $this->lastStatements);
85
-                            $this->lastStatements = null;
86
-                        }
87
-                        return;
88
-                    }
89
-                    break;
90
-
91
-                case T_FUNCTION:
92
-                    $Method = new ParserFunction($Parser, $tokens, $this->lastStatements);
93
-                    $this->Methods[strtolower($Method->name)] = $Method;
94
-                    $this->lastStatements = null;
95
-                    break;
96
-
97
-                case T_EXTENDS:
98
-                    $mode = T_EXTENDS;
99
-                    break;
100
-
101
-                case T_IMPLEMENTS:
102
-                    $mode = T_IMPLEMENTS;
103
-                    break;
104
-
105
-                case T_COMMENT:
106
-                    if ($this->lastStatements) {
107
-                        $this->Statements = array_merge($this->Statements, $this->lastStatements);
108
-                        $this->lastStatements = null;
109
-                    }
110
-                    $Statements = $Parser->tokenToStatements($token);
111
-                    $Parser->queueClassesFromComments($Statements);
112
-                    $this->Statements = array_merge($this->Statements, $Statements);
113
-                    break;
114
-
115
-                case T_DOC_COMMENT:
116
-                    if ($this->lastStatements) {
117
-                        $this->Statements = array_merge($this->Statements, $this->lastStatements);
118
-                    }
119
-                    $Statements = $Parser->tokenToStatements($token);
120
-                    $Parser->queueClassesFromComments($Statements);
121
-                    $this->lastStatements = $Statements;
122
-                    break;
123
-            }
124
-
125
-            $token = next($tokens);
126
-        }
127
-
128
-        if ($this->lastStatements) {
129
-            $this->Statements = array_merge($this->Statements, $this->lastStatements);
130
-            $this->lastStatements = null;
131
-        }
132
-    }
18
+	/**
19
+	 * @var string
20
+	 */
21
+	public $name = null;
22
+
23
+	/**
24
+	 * @var ParserFunction[]
25
+	 */
26
+	public $Methods = [];
27
+
28
+	/**
29
+	 * @var string
30
+	 */
31
+	public $extends = null;
32
+
33
+	/**
34
+	 * @var string[]
35
+	 */
36
+	public $implements = [];
37
+	private $lastStatements = null;
38
+
39
+	public function __construct(Parser $Parser, &$tokens, $Statements)
40
+	{
41
+		if ($Statements) {
42
+			$this->Statements = array_merge($this->Statements, $Statements);
43
+		}
44
+
45
+		$depth = 0;
46
+
47
+		$mode = T_CLASS;
48
+
49
+		$token = current($tokens);
50
+		while ($token) {
51
+			switch ($token[0]) {
52
+				case T_STRING:
53
+					switch ($mode) {
54
+						case T_CLASS:
55
+							$this->name = $token[1];
56
+							$mode = null;
57
+							break;
58
+
59
+						case T_EXTENDS:
60
+							$Parser->queueClass($token[1]);
61
+							$this->extends = $token[1];
62
+							$mode = null;
63
+							break;
64
+
65
+						case T_IMPLEMENTS:
66
+							$Parser->queueClass($token[1]);
67
+							$this->implements[] = $token[1];
68
+							break;
69
+					}
70
+					break;
71
+
72
+				case '{':
73
+				case T_CURLY_OPEN:
74
+				case T_DOLLAR_OPEN_CURLY_BRACES:
75
+				case T_STRING_VARNAME:
76
+					$mode = null;
77
+					++$depth;
78
+					break;
79
+
80
+				case '}':
81
+					--$depth;
82
+					if ($depth == 0) {
83
+						if ($this->lastStatements) {
84
+							$this->Statements = array_merge($this->Statements, $this->lastStatements);
85
+							$this->lastStatements = null;
86
+						}
87
+						return;
88
+					}
89
+					break;
90
+
91
+				case T_FUNCTION:
92
+					$Method = new ParserFunction($Parser, $tokens, $this->lastStatements);
93
+					$this->Methods[strtolower($Method->name)] = $Method;
94
+					$this->lastStatements = null;
95
+					break;
96
+
97
+				case T_EXTENDS:
98
+					$mode = T_EXTENDS;
99
+					break;
100
+
101
+				case T_IMPLEMENTS:
102
+					$mode = T_IMPLEMENTS;
103
+					break;
104
+
105
+				case T_COMMENT:
106
+					if ($this->lastStatements) {
107
+						$this->Statements = array_merge($this->Statements, $this->lastStatements);
108
+						$this->lastStatements = null;
109
+					}
110
+					$Statements = $Parser->tokenToStatements($token);
111
+					$Parser->queueClassesFromComments($Statements);
112
+					$this->Statements = array_merge($this->Statements, $Statements);
113
+					break;
114
+
115
+				case T_DOC_COMMENT:
116
+					if ($this->lastStatements) {
117
+						$this->Statements = array_merge($this->Statements, $this->lastStatements);
118
+					}
119
+					$Statements = $Parser->tokenToStatements($token);
120
+					$Parser->queueClassesFromComments($Statements);
121
+					$this->lastStatements = $Statements;
122
+					break;
123
+			}
124
+
125
+			$token = next($tokens);
126
+		}
127
+
128
+		if ($this->lastStatements) {
129
+			$this->Statements = array_merge($this->Statements, $this->lastStatements);
130
+			$this->lastStatements = null;
131
+		}
132
+	}
133 133
 
134 134
 }
Please login to merge, or discard this patch.
SwaggerGen/Parser/Text/Preprocessor.php 1 patch
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -18,30 +18,30 @@
 block discarded – undo
18 18
 class Preprocessor extends AbstractPreprocessor
19 19
 {
20 20
 
21
-    protected function parseContent($content)
22
-    {
23
-        $pattern = '/\\s*([a-z]+)\\s*(.*)\\s*/';
24
-
25
-        $output = '';
26
-
27
-        foreach (preg_split('/(\\R)/m', $content, null, PREG_SPLIT_DELIM_CAPTURE) as $index => $line) {
28
-            if ($index % 2) {
29
-                $output .= $line;
30
-            } else {
31
-                $match = [];
32
-                if (preg_match($pattern, $line, $match) === 1) {
33
-                    if (!$this->handle($match[1], $match[2]) && $this->getState()) {
34
-                        $output .= $line;
35
-                    } else {
36
-                        $output .= '';
37
-                    }
38
-                } else {
39
-                    $output .= $line;
40
-                }
41
-            }
42
-        }
43
-
44
-        return $output;
45
-    }
21
+	protected function parseContent($content)
22
+	{
23
+		$pattern = '/\\s*([a-z]+)\\s*(.*)\\s*/';
24
+
25
+		$output = '';
26
+
27
+		foreach (preg_split('/(\\R)/m', $content, null, PREG_SPLIT_DELIM_CAPTURE) as $index => $line) {
28
+			if ($index % 2) {
29
+				$output .= $line;
30
+			} else {
31
+				$match = [];
32
+				if (preg_match($pattern, $line, $match) === 1) {
33
+					if (!$this->handle($match[1], $match[2]) && $this->getState()) {
34
+						$output .= $line;
35
+					} else {
36
+						$output .= '';
37
+					}
38
+				} else {
39
+					$output .= $line;
40
+				}
41
+			}
42
+		}
43
+
44
+		return $output;
45
+	}
46 46
 
47 47
 }
Please login to merge, or discard this patch.
SwaggerGen/Parser/IParser.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -13,5 +13,5 @@
 block discarded – undo
13 13
 interface IParser
14 14
 {
15 15
 
16
-    public function parse($file, array $dirs = []);
16
+	public function parse($file, array $dirs = []);
17 17
 }
Please login to merge, or discard this patch.
SwaggerGen/StatementException.php 1 patch
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -16,27 +16,27 @@
 block discarded – undo
16 16
 class StatementException extends Exception
17 17
 {
18 18
 
19
-    /**
20
-     * @var Statement
21
-     */
22
-    private $statement;
19
+	/**
20
+	 * @var Statement
21
+	 */
22
+	private $statement;
23 23
 
24
-    /**
25
-     *
26
-     * @param string $message
27
-     * @param int $code
28
-     * @param Throwable $previous
29
-     * @param Statement $statement
30
-     */
31
-    public function __construct($message = "", $code = 0, $previous = null, $statement = null)
32
-    {
33
-        $this->statement = $statement;
24
+	/**
25
+	 *
26
+	 * @param string $message
27
+	 * @param int $code
28
+	 * @param Throwable $previous
29
+	 * @param Statement $statement
30
+	 */
31
+	public function __construct($message = "", $code = 0, $previous = null, $statement = null)
32
+	{
33
+		$this->statement = $statement;
34 34
 
35
-        parent::__construct($message, $code, $previous);
36
-    }
35
+		parent::__construct($message, $code, $previous);
36
+	}
37 37
 
38
-    public function getStatement()
39
-    {
40
-        return $this->statement;
41
-    }
38
+	public function getStatement()
39
+	{
40
+		return $this->statement;
41
+	}
42 42
 }
Please login to merge, or discard this patch.
SwaggerGen/Swagger/SecurityScheme.php 1 patch
Indentation   +127 added lines, -127 removed lines patch added patch discarded remove patch
@@ -16,132 +16,132 @@
 block discarded – undo
16 16
 class SecurityScheme extends AbstractObject
17 17
 {
18 18
 
19
-    /**
20
-     * 'basic', 'apikey' or 'oauth2'
21
-     * @var string
22
-     */
23
-    private $type;
24
-
25
-    /**
26
-     * @var string
27
-     */
28
-    private $description;
29
-    private $name;
30
-    private $in;
31
-    private $flow;
32
-    private $authorizationUrl;
33
-    private $tokenUrl;
34
-
35
-    /**
36
-     * Map of scope-name => description
37
-     * @var []
38
-     */
39
-    private $scopes = [];
40
-
41
-    /**
42
-     * Create a new SecurityScheme object
43
-     * @param AbstractObject $parent
44
-     * @param string $type
45
-     * @param string $data
46
-     * @throws Exception
47
-     */
48
-    public function __construct(AbstractObject $parent, $type, $data = null)
49
-    {
50
-        parent::__construct($parent);
51
-
52
-        if (!in_array(strtolower($type), array('basic', 'apikey', 'oauth2'))) {
53
-            throw new Exception("Security scheme type must be either 'basic', 'apiKey' or 'oauth2', not '{$type}'");
54
-        }
55
-        $this->type = strtolower($type);
56
-
57
-        switch ($this->type) {
58
-            case 'basic':
59
-                $this->description = $data;
60
-                break;
61
-
62
-            case 'apikey':
63
-                $this->name = self::wordShift($data);
64
-
65
-                $in = strtolower(self::wordShift($data));
66
-                if (!in_array($in, array('query', 'header'))) {
67
-                    throw new Exception("ApiKey in must be either 'query' or 'header', not '{$in}'");
68
-                }
69
-                $this->in = $in;
70
-
71
-                $this->description = $data;
72
-                break;
73
-
74
-            case 'oauth2':
75
-                $flow = strtolower(self::wordShift($data));
76
-                if (!in_array($flow, array('implicit', 'password', 'application', 'accesscode'))) {
77
-                    throw new Exception("OAuth2 flow must be either 'implicit', 'password', 'application' or 'accesscode', not '{$flow}'");
78
-                }
79
-                $this->flow = $flow;
80
-
81
-                if (in_array($flow, array('implicit', 'accesscode'))) {
82
-                    $authUrl = self::wordShift($data);
83
-                    if (!filter_var($authUrl, FILTER_VALIDATE_URL)) {
84
-                        throw new Exception("OAuth2 authorization URL invalid: '{$authUrl}'");
85
-                    }
86
-                    $this->authorizationUrl = $authUrl;
87
-                }
88
-
89
-                if (in_array($flow, array('password', 'application', 'accesscode'))) {
90
-                    $tokenUrl = self::wordShift($data);
91
-                    if (!filter_var($tokenUrl, FILTER_VALIDATE_URL)) {
92
-                        throw new Exception("OAuth2 token URL invalid: '{$tokenUrl}'");
93
-                    }
94
-                    $this->tokenUrl = $tokenUrl;
95
-                }
96
-
97
-                $this->description = $data;
98
-                break;
99
-        }
100
-    }
101
-
102
-    /**
103
-     * @param string $command
104
-     * @param string $data
105
-     * @return AbstractObject|boolean
106
-     * @throws Exception
107
-     */
108
-    public function handleCommand($command, $data = null)
109
-    {
110
-        switch (strtolower($command)) {
111
-            case 'description':
112
-                $this->description = $data;
113
-                return $this;
114
-
115
-            case 'scope':
116
-                if ($this->type !== 'oauth2') {
117
-                    throw new Exception("Cannot set scope on type '{$this->type}'");
118
-                }
119
-
120
-                $name = self::wordShift($data);
121
-                $this->scopes[$name] = $data;
122
-                return $this;
123
-        }
124
-
125
-        return parent::handleCommand($command, $data);
126
-    }
127
-
128
-    public function toArray(): array
129
-    {
130
-        return self::arrayFilterNull(array_merge(array(
131
-            'type' => $this->type === 'apikey' ? 'apiKey' : $this->type,
132
-            'description' => empty($this->description) ? null : $this->description,
133
-            'name' => $this->name,
134
-            'in' => $this->in,
135
-            'flow' => $this->flow === 'accesscode' ? 'accessCode' : $this->flow,
136
-            'authorizationUrl' => $this->authorizationUrl,
137
-            'tokenUrl' => $this->tokenUrl,
138
-            'scopes' => $this->scopes,
139
-        ), parent::toArray()));
140
-    }
141
-
142
-    public function __toString()
143
-    {
144
-        return __CLASS__ . ' ' . $this->type;
145
-    }
19
+	/**
20
+	 * 'basic', 'apikey' or 'oauth2'
21
+	 * @var string
22
+	 */
23
+	private $type;
24
+
25
+	/**
26
+	 * @var string
27
+	 */
28
+	private $description;
29
+	private $name;
30
+	private $in;
31
+	private $flow;
32
+	private $authorizationUrl;
33
+	private $tokenUrl;
34
+
35
+	/**
36
+	 * Map of scope-name => description
37
+	 * @var []
38
+	 */
39
+	private $scopes = [];
40
+
41
+	/**
42
+	 * Create a new SecurityScheme object
43
+	 * @param AbstractObject $parent
44
+	 * @param string $type
45
+	 * @param string $data
46
+	 * @throws Exception
47
+	 */
48
+	public function __construct(AbstractObject $parent, $type, $data = null)
49
+	{
50
+		parent::__construct($parent);
51
+
52
+		if (!in_array(strtolower($type), array('basic', 'apikey', 'oauth2'))) {
53
+			throw new Exception("Security scheme type must be either 'basic', 'apiKey' or 'oauth2', not '{$type}'");
54
+		}
55
+		$this->type = strtolower($type);
56
+
57
+		switch ($this->type) {
58
+			case 'basic':
59
+				$this->description = $data;
60
+				break;
61
+
62
+			case 'apikey':
63
+				$this->name = self::wordShift($data);
64
+
65
+				$in = strtolower(self::wordShift($data));
66
+				if (!in_array($in, array('query', 'header'))) {
67
+					throw new Exception("ApiKey in must be either 'query' or 'header', not '{$in}'");
68
+				}
69
+				$this->in = $in;
70
+
71
+				$this->description = $data;
72
+				break;
73
+
74
+			case 'oauth2':
75
+				$flow = strtolower(self::wordShift($data));
76
+				if (!in_array($flow, array('implicit', 'password', 'application', 'accesscode'))) {
77
+					throw new Exception("OAuth2 flow must be either 'implicit', 'password', 'application' or 'accesscode', not '{$flow}'");
78
+				}
79
+				$this->flow = $flow;
80
+
81
+				if (in_array($flow, array('implicit', 'accesscode'))) {
82
+					$authUrl = self::wordShift($data);
83
+					if (!filter_var($authUrl, FILTER_VALIDATE_URL)) {
84
+						throw new Exception("OAuth2 authorization URL invalid: '{$authUrl}'");
85
+					}
86
+					$this->authorizationUrl = $authUrl;
87
+				}
88
+
89
+				if (in_array($flow, array('password', 'application', 'accesscode'))) {
90
+					$tokenUrl = self::wordShift($data);
91
+					if (!filter_var($tokenUrl, FILTER_VALIDATE_URL)) {
92
+						throw new Exception("OAuth2 token URL invalid: '{$tokenUrl}'");
93
+					}
94
+					$this->tokenUrl = $tokenUrl;
95
+				}
96
+
97
+				$this->description = $data;
98
+				break;
99
+		}
100
+	}
101
+
102
+	/**
103
+	 * @param string $command
104
+	 * @param string $data
105
+	 * @return AbstractObject|boolean
106
+	 * @throws Exception
107
+	 */
108
+	public function handleCommand($command, $data = null)
109
+	{
110
+		switch (strtolower($command)) {
111
+			case 'description':
112
+				$this->description = $data;
113
+				return $this;
114
+
115
+			case 'scope':
116
+				if ($this->type !== 'oauth2') {
117
+					throw new Exception("Cannot set scope on type '{$this->type}'");
118
+				}
119
+
120
+				$name = self::wordShift($data);
121
+				$this->scopes[$name] = $data;
122
+				return $this;
123
+		}
124
+
125
+		return parent::handleCommand($command, $data);
126
+	}
127
+
128
+	public function toArray(): array
129
+	{
130
+		return self::arrayFilterNull(array_merge(array(
131
+			'type' => $this->type === 'apikey' ? 'apiKey' : $this->type,
132
+			'description' => empty($this->description) ? null : $this->description,
133
+			'name' => $this->name,
134
+			'in' => $this->in,
135
+			'flow' => $this->flow === 'accesscode' ? 'accessCode' : $this->flow,
136
+			'authorizationUrl' => $this->authorizationUrl,
137
+			'tokenUrl' => $this->tokenUrl,
138
+			'scopes' => $this->scopes,
139
+		), parent::toArray()));
140
+	}
141
+
142
+	public function __toString()
143
+	{
144
+		return __CLASS__ . ' ' . $this->type;
145
+	}
146 146
 
147 147
 }
Please login to merge, or discard this patch.
SwaggerGen/Swagger/Operation.php 1 patch
Indentation   +225 added lines, -225 removed lines patch added patch discarded remove patch
@@ -16,230 +16,230 @@
 block discarded – undo
16 16
 class Operation extends AbstractDocumentableObject
17 17
 {
18 18
 
19
-    private $tags = [];
20
-    private $summary;
21
-    private $description;
22
-    private $consumes = [];
23
-    private $produces = [];
24
-
25
-    /**
26
-     * @var IParameter[]
27
-     */
28
-    private $parameters = [];
29
-    private $responses = [];
30
-    private $schemes = [];
31
-    private $deprecated = false;
32
-    private $security = [];
33
-
34
-    /**
35
-     * @var string
36
-     */
37
-    private $operationId = null;
38
-
39
-    /**
40
-     * @param string $summary
41
-     */
42
-    public function __construct(AbstractObject $parent, $summary = null, ?Tag $tag = null)
43
-    {
44
-        parent::__construct($parent);
45
-        $this->summary = $summary;
46
-        if ($tag) {
47
-            $this->tags[] = $tag->getName();
48
-        }
49
-    }
50
-
51
-    public function getConsumes(): array
52
-    {
53
-        return $this->consumes;
54
-    }
55
-
56
-    /**
57
-     * @param string $command
58
-     * @param string $data
59
-     * @return AbstractObject|boolean
60
-     * @throws Exception
61
-     * @throws Exception
62
-     * @throws Exception
63
-     * @throws Exception
64
-     * @throws Exception
65
-     * @throws Exception
66
-     * @throws Exception
67
-     */
68
-    public function handleCommand($command, $data = null)
69
-    {
70
-        switch (strtolower($command)) {
71
-            // string
72
-            case 'summary':
73
-            case 'description':
74
-                $this->$command = $data;
75
-                return $this;
76
-
77
-            // string[]
78
-            case 'tags':
79
-            case 'schemes':
80
-                $this->$command = array_merge($this->$command, self::wordSplit($data));
81
-                return $this;
82
-
83
-            // MIME[]
84
-            case 'consumes':
85
-            case 'produces':
86
-                $this->$command = array_merge($this->$command, self::translateMimeTypes(self::wordSplit($data)));
87
-                return $this;
88
-
89
-            // boolean
90
-            case 'deprecated':
91
-                $this->deprecated = true;
92
-                return $this;
93
-
94
-            case 'error':
95
-                $code = self::wordShift($data);
96
-                $reasoncode = Response::getCode($code);
97
-                if ($reasoncode === null) {
98
-                    throw new Exception("Invalid error code: '$code'");
99
-                }
100
-                $description = $data;
101
-                $Error = new Error($this, $reasoncode, $description);
102
-                $this->responses[$reasoncode] = $Error;
103
-                return $Error;
104
-
105
-            case 'errors':
106
-                foreach (self::wordSplit($data) as $code) {
107
-                    $reasoncode = Response::getCode($code);
108
-                    if ($reasoncode === null) {
109
-                        throw new Exception("Invalid error code: '$code'");
110
-                    }
111
-                    $this->responses[$reasoncode] = new Error($this, $reasoncode);
112
-                }
113
-                return $this;
114
-
115
-            case 'path':
116
-            case 'query':
117
-            case 'query?':
118
-            case 'header':
119
-            case 'header?':
120
-            case 'form':
121
-            case 'form?':
122
-                $in = rtrim($command, '?');
123
-                $parameter = new Parameter($this, $in, $data, substr($command, -1) !== '?');
124
-                $this->parameters[$parameter->getName()] = $parameter;
125
-                return $parameter;
126
-
127
-            case 'body':
128
-            case 'body?':
129
-                $parameter = new BodyParameter($this, $data, substr($command, -1) !== '?');
130
-                $this->parameters[$parameter->getName()] = $parameter;
131
-                return $parameter;
132
-
133
-            case 'param':
134
-            case 'parameter':
135
-                $parameter = new ParameterReference($this, $data);
136
-                $this->parameters[$parameter->getName()] = $parameter;
137
-                return $this;
138
-
139
-            case 'response':
140
-                $code = self::wordShift($data);
141
-                $reasoncode = Response::getCode($code);
142
-                if ($reasoncode === null) {
143
-                    $reference = $code;
144
-                    $code = self::wordShift($data);
145
-                    $reasoncode = Response::getCode($code);
146
-                    if ($reasoncode === null) {
147
-                        throw new Exception("Invalid response code: '$reference'");
148
-                    }
149
-                    $this->responses[$reasoncode] = new ResponseReference($this, $reference);
150
-                    return $this;
151
-                }
152
-
153
-                $definition = self::wordShift($data);
154
-                $description = $data;
155
-                $Response = new Response($this, $reasoncode, $definition, $description);
156
-                $this->responses[$reasoncode] = $Response;
157
-                return $Response;
158
-
159
-            case 'require':
160
-                $name = self::wordShift($data);
161
-                if (empty($name)) {
162
-                    throw new Exception('Empty security requirement name');
163
-                }
164
-                $scopes = self::wordSplit($data);
165
-                sort($scopes);
166
-                $this->security[] = array(
167
-                    $name => empty($scopes) ? [] : $scopes,
168
-                );
169
-                return $this;
170
-
171
-            case 'id':
172
-                $operationId = self::trim($data);
173
-                if ($this->getSwagger()->hasOperationId($operationId)) {
174
-                    throw new Exception("Duplicate operation id '{$operationId}'");
175
-                }
176
-                $this->operationId = $operationId;
177
-                return $this;
178
-        }
179
-
180
-        return parent::handleCommand($command, $data);
181
-    }
182
-
183
-    /**
184
-     * @throws Exception
185
-     */
186
-    public function toArray(): array
187
-    {
188
-        if (empty($this->responses)) {
189
-            throw new Exception('No response defined for operation');
190
-        }
191
-        ksort($this->responses);
192
-
193
-        $tags = array_unique($this->tags);
194
-        sort($tags);
195
-
196
-        $schemes = array_unique($this->schemes);
197
-        sort($schemes);
198
-
199
-        $consumes = array_unique($this->consumes);
200
-        sort($consumes);
201
-
202
-        $produces = array_unique($this->produces);
203
-        sort($produces);
204
-
205
-        foreach ($this->security as $security) {
206
-            foreach ($security as $name => $scope) {
207
-                if ($this->getSwagger()->getSecurity($name) === false) {
208
-                    throw new Exception("Required security scheme not defined: '{$name}'");
209
-                }
210
-            }
211
-        }
212
-
213
-        $parameters = $this->parameters ? array_values($this->parameters) : null;
214
-
215
-        return self::arrayFilterNull(array_merge(array(
216
-            'deprecated' => $this->deprecated ? true : null,
217
-            'tags' => $tags,
218
-            'summary' => empty($this->summary) ? null : $this->summary,
219
-            'description' => empty($this->description) ? null : $this->description,
220
-            'operationId' => $this->operationId,
221
-            'consumes' => $consumes,
222
-            'produces' => $produces,
223
-            'parameters' => $parameters ? self::objectsToArray($parameters) : null,
224
-            'schemes' => $schemes,
225
-            'responses' => $this->responses ? self::objectsToArray($this->responses) : null,
226
-            'security' => $this->security,
227
-        ), parent::toArray()));
228
-    }
229
-
230
-    /**
231
-     * Return the operation ID
232
-     *
233
-     * @return string
234
-     */
235
-    public function getId()
236
-    {
237
-        return $this->operationId;
238
-    }
239
-
240
-    public function __toString()
241
-    {
242
-        return __CLASS__ . ' ' . $this->summary;
243
-    }
19
+	private $tags = [];
20
+	private $summary;
21
+	private $description;
22
+	private $consumes = [];
23
+	private $produces = [];
24
+
25
+	/**
26
+	 * @var IParameter[]
27
+	 */
28
+	private $parameters = [];
29
+	private $responses = [];
30
+	private $schemes = [];
31
+	private $deprecated = false;
32
+	private $security = [];
33
+
34
+	/**
35
+	 * @var string
36
+	 */
37
+	private $operationId = null;
38
+
39
+	/**
40
+	 * @param string $summary
41
+	 */
42
+	public function __construct(AbstractObject $parent, $summary = null, ?Tag $tag = null)
43
+	{
44
+		parent::__construct($parent);
45
+		$this->summary = $summary;
46
+		if ($tag) {
47
+			$this->tags[] = $tag->getName();
48
+		}
49
+	}
50
+
51
+	public function getConsumes(): array
52
+	{
53
+		return $this->consumes;
54
+	}
55
+
56
+	/**
57
+	 * @param string $command
58
+	 * @param string $data
59
+	 * @return AbstractObject|boolean
60
+	 * @throws Exception
61
+	 * @throws Exception
62
+	 * @throws Exception
63
+	 * @throws Exception
64
+	 * @throws Exception
65
+	 * @throws Exception
66
+	 * @throws Exception
67
+	 */
68
+	public function handleCommand($command, $data = null)
69
+	{
70
+		switch (strtolower($command)) {
71
+			// string
72
+			case 'summary':
73
+			case 'description':
74
+				$this->$command = $data;
75
+				return $this;
76
+
77
+			// string[]
78
+			case 'tags':
79
+			case 'schemes':
80
+				$this->$command = array_merge($this->$command, self::wordSplit($data));
81
+				return $this;
82
+
83
+			// MIME[]
84
+			case 'consumes':
85
+			case 'produces':
86
+				$this->$command = array_merge($this->$command, self::translateMimeTypes(self::wordSplit($data)));
87
+				return $this;
88
+
89
+			// boolean
90
+			case 'deprecated':
91
+				$this->deprecated = true;
92
+				return $this;
93
+
94
+			case 'error':
95
+				$code = self::wordShift($data);
96
+				$reasoncode = Response::getCode($code);
97
+				if ($reasoncode === null) {
98
+					throw new Exception("Invalid error code: '$code'");
99
+				}
100
+				$description = $data;
101
+				$Error = new Error($this, $reasoncode, $description);
102
+				$this->responses[$reasoncode] = $Error;
103
+				return $Error;
104
+
105
+			case 'errors':
106
+				foreach (self::wordSplit($data) as $code) {
107
+					$reasoncode = Response::getCode($code);
108
+					if ($reasoncode === null) {
109
+						throw new Exception("Invalid error code: '$code'");
110
+					}
111
+					$this->responses[$reasoncode] = new Error($this, $reasoncode);
112
+				}
113
+				return $this;
114
+
115
+			case 'path':
116
+			case 'query':
117
+			case 'query?':
118
+			case 'header':
119
+			case 'header?':
120
+			case 'form':
121
+			case 'form?':
122
+				$in = rtrim($command, '?');
123
+				$parameter = new Parameter($this, $in, $data, substr($command, -1) !== '?');
124
+				$this->parameters[$parameter->getName()] = $parameter;
125
+				return $parameter;
126
+
127
+			case 'body':
128
+			case 'body?':
129
+				$parameter = new BodyParameter($this, $data, substr($command, -1) !== '?');
130
+				$this->parameters[$parameter->getName()] = $parameter;
131
+				return $parameter;
132
+
133
+			case 'param':
134
+			case 'parameter':
135
+				$parameter = new ParameterReference($this, $data);
136
+				$this->parameters[$parameter->getName()] = $parameter;
137
+				return $this;
138
+
139
+			case 'response':
140
+				$code = self::wordShift($data);
141
+				$reasoncode = Response::getCode($code);
142
+				if ($reasoncode === null) {
143
+					$reference = $code;
144
+					$code = self::wordShift($data);
145
+					$reasoncode = Response::getCode($code);
146
+					if ($reasoncode === null) {
147
+						throw new Exception("Invalid response code: '$reference'");
148
+					}
149
+					$this->responses[$reasoncode] = new ResponseReference($this, $reference);
150
+					return $this;
151
+				}
152
+
153
+				$definition = self::wordShift($data);
154
+				$description = $data;
155
+				$Response = new Response($this, $reasoncode, $definition, $description);
156
+				$this->responses[$reasoncode] = $Response;
157
+				return $Response;
158
+
159
+			case 'require':
160
+				$name = self::wordShift($data);
161
+				if (empty($name)) {
162
+					throw new Exception('Empty security requirement name');
163
+				}
164
+				$scopes = self::wordSplit($data);
165
+				sort($scopes);
166
+				$this->security[] = array(
167
+					$name => empty($scopes) ? [] : $scopes,
168
+				);
169
+				return $this;
170
+
171
+			case 'id':
172
+				$operationId = self::trim($data);
173
+				if ($this->getSwagger()->hasOperationId($operationId)) {
174
+					throw new Exception("Duplicate operation id '{$operationId}'");
175
+				}
176
+				$this->operationId = $operationId;
177
+				return $this;
178
+		}
179
+
180
+		return parent::handleCommand($command, $data);
181
+	}
182
+
183
+	/**
184
+	 * @throws Exception
185
+	 */
186
+	public function toArray(): array
187
+	{
188
+		if (empty($this->responses)) {
189
+			throw new Exception('No response defined for operation');
190
+		}
191
+		ksort($this->responses);
192
+
193
+		$tags = array_unique($this->tags);
194
+		sort($tags);
195
+
196
+		$schemes = array_unique($this->schemes);
197
+		sort($schemes);
198
+
199
+		$consumes = array_unique($this->consumes);
200
+		sort($consumes);
201
+
202
+		$produces = array_unique($this->produces);
203
+		sort($produces);
204
+
205
+		foreach ($this->security as $security) {
206
+			foreach ($security as $name => $scope) {
207
+				if ($this->getSwagger()->getSecurity($name) === false) {
208
+					throw new Exception("Required security scheme not defined: '{$name}'");
209
+				}
210
+			}
211
+		}
212
+
213
+		$parameters = $this->parameters ? array_values($this->parameters) : null;
214
+
215
+		return self::arrayFilterNull(array_merge(array(
216
+			'deprecated' => $this->deprecated ? true : null,
217
+			'tags' => $tags,
218
+			'summary' => empty($this->summary) ? null : $this->summary,
219
+			'description' => empty($this->description) ? null : $this->description,
220
+			'operationId' => $this->operationId,
221
+			'consumes' => $consumes,
222
+			'produces' => $produces,
223
+			'parameters' => $parameters ? self::objectsToArray($parameters) : null,
224
+			'schemes' => $schemes,
225
+			'responses' => $this->responses ? self::objectsToArray($this->responses) : null,
226
+			'security' => $this->security,
227
+		), parent::toArray()));
228
+	}
229
+
230
+	/**
231
+	 * Return the operation ID
232
+	 *
233
+	 * @return string
234
+	 */
235
+	public function getId()
236
+	{
237
+		return $this->operationId;
238
+	}
239
+
240
+	public function __toString()
241
+	{
242
+		return __CLASS__ . ' ' . $this->summary;
243
+	}
244 244
 
245 245
 }
Please login to merge, or discard this patch.
SwaggerGen/Swagger/Swagger.php 1 patch
Indentation   +374 added lines, -374 removed lines patch added patch discarded remove patch
@@ -16,379 +16,379 @@
 block discarded – undo
16 16
 class Swagger extends AbstractDocumentableObject
17 17
 {
18 18
 
19
-    private $swagger = '2.0';
20
-    private $host;
21
-    private $basePath;
22
-
23
-    /**
24
-     * @var TypeRegistry
25
-     */
26
-    private $typeRegistry;
27
-
28
-    /**
29
-     * @var Info $Info
30
-     */
31
-    private $info;
32
-    private $schemes = [];
33
-    private $consumes = [];
34
-    private $produces = [];
35
-
36
-    /**
37
-     * @var Path[] $Paths
38
-     */
39
-    private $paths = [];
40
-
41
-    /**
42
-     * @var Schema[] $definitions
43
-     */
44
-    private $definitions = [];
45
-
46
-    /**
47
-     * @var IParameter[] $parameters
48
-     */
49
-    private $parameters = [];
50
-
51
-    /**
52
-     * @var Response[] $responses
53
-     */
54
-    private $responses = [];
55
-
56
-    /**
57
-     * @var Tag[] $Tags
58
-     */
59
-    private $tags = [];
60
-
61
-    /**
62
-     * Default tag for new endpoints/operations. Set by the api command.
63
-     *
64
-     * @var Tag
65
-     */
66
-    private $defaultTag = null;
67
-    private $securityDefinitions = [];
68
-    private $security = [];
69
-
70
-    /**
71
-     * @param string $host
72
-     * @param string $basePath
73
-     * @param TypeRegistry $typeRegistry
74
-     */
75
-    public function __construct($host = null, $basePath = null, $typeRegistry = null)
76
-    {
77
-        parent::__construct();
78
-
79
-        $this->host = $host;
80
-        $this->basePath = $basePath;
81
-
82
-        $this->info = new Info($this);
83
-
84
-        $this->typeRegistry = $typeRegistry ?: new TypeRegistry;
85
-    }
86
-
87
-    /**
88
-     * Return all consumes
89
-     *
90
-     * @return array
91
-     * @todo Deprecate in favour of a getConsume($name);
92
-     */
93
-    public function getConsumes(): array
94
-    {
95
-        return $this->consumes;
96
-    }
97
-
98
-    /**
99
-     * Return the named security if it exists, otherwise return FALSE
100
-     *
101
-     * @param string $name
102
-     *
103
-     * @return boolean|SecurityScheme
104
-     */
105
-    public function getSecurity($name)
106
-    {
107
-        return $this->securityDefinitions[$name] ?? false;
108
-    }
109
-
110
-    /**
111
-     * @param string $command
112
-     * @param string $data
113
-     *
114
-     * @return AbstractObject|boolean
115
-     * @throws Exception
116
-     * @throws Exception
117
-     * @throws Exception
118
-     * @throws Exception
119
-     * @throws Exception
120
-     * @throws Exception
121
-     * @throws Exception
122
-     * @throws Exception
123
-     * @throws Exception
124
-     */
125
-    public function handleCommand($command, $data = null)
126
-    {
127
-        switch (strtolower($command)) {
128
-            // pass to Info
129
-            case 'title':
130
-            case 'description':
131
-            case 'version':
132
-            case 'terms': // alias
133
-            case 'tos': // alias
134
-            case 'termsofservice':
135
-            case 'contact':
136
-            case 'license':
137
-                return $this->info->handleCommand($command, $data);
138
-
139
-            // string[]
140
-            case 'scheme':
141
-            case 'schemes':
142
-                $this->schemes = array_unique(array_merge($this->schemes, self::wordSplit($data)));
143
-
144
-                return $this;
145
-
146
-            // MIME[]
147
-            case 'consume':
148
-            case 'consumes':
149
-                $this->consumes = array_merge($this->consumes, self::translateMimeTypes(self::wordSplit($data)));
150
-
151
-                return $this;
152
-
153
-            case 'produce':
154
-            case 'produces':
155
-                $this->produces = array_merge($this->produces, self::translateMimeTypes(self::wordSplit($data)));
156
-
157
-                return $this;
158
-
159
-            case 'model':
160
-            case 'model!':
161
-            case 'definition':
162
-            case 'definition!':
163
-                $name = self::wordShift($data);
164
-                if (empty($name)) {
165
-                    throw new Exception('Missing definition name');
166
-                }
167
-                $typeDef = self::wordShift($data);
168
-                if (empty($typeDef)) {
169
-                    $typeDef = 'object';
170
-                }
171
-
172
-                $definition = new Schema($this, $typeDef);
173
-                if (substr($command, -1) === '!') {
174
-                    $definition->setReadOnly();
175
-                }
176
-                $this->definitions[$name] = $definition;
177
-
178
-                return $definition;
179
-
180
-            case 'path':
181
-            case 'query':
182
-            case 'query?':
183
-            case 'header':
184
-            case 'header?':
185
-            case 'form':
186
-            case 'form?':
187
-                $in = rtrim($command, '?');
188
-                $Parameter = new Parameter($this, $in, $data, substr($command, -1) !== '?');
189
-                $this->parameters[$Parameter->getName()] = $Parameter;
190
-
191
-                return $Parameter;
192
-
193
-            case 'body':
194
-            case 'body?':
195
-                $Parameter = new BodyParameter($this, $data, substr($command, -1) !== '?');
196
-                $this->parameters[$Parameter->getName()] = $Parameter;
197
-
198
-                return $Parameter;
199
-
200
-            case 'response':
201
-                $name = self::wordShift($data);
202
-                $definition = self::wordShift($data);
203
-                $description = $data;
204
-                if (empty($description)) {
205
-                    throw new Exception('Response definition missing description');
206
-                }
207
-                $Response = new Response($this, $name, $definition === 'null' ? null : $definition, $description);
208
-                $this->responses[$name] = $Response;
209
-
210
-                return $Response;
211
-
212
-            case 'api': // alias
213
-            case 'tag':
214
-                $tagname = self::wordShift($data);
215
-                if (empty($tagname)) {
216
-                    throw new Exception('Missing tag name');
217
-                }
218
-
219
-                $Tag = null;
220
-                foreach ($this->tags as $T) {
221
-                    if ($T->getName() === $tagname) {
222
-                        $Tag = $T;
223
-                        break;
224
-                    }
225
-                }
226
-                if (!$Tag) {
227
-                    $Tag = new Tag($this, $tagname, $data);
228
-                    $this->tags[] = $Tag;
229
-                }
230
-
231
-                // backwards compatibility
232
-                if ($command === 'api') {
233
-                    $this->defaultTag = $Tag;
234
-                }
235
-
236
-                return $Tag;
237
-
238
-            case 'endpoint':
239
-                $path = self::wordShift($data);
240
-                if (false === $path) {
241
-                    $path = '/';
242
-                } else if ($path[0] !== '/') {
243
-                    $path = '/' . $path;
244
-                }
245
-
246
-                $Tag = null;
247
-                if (($tagname = self::wordShift($data)) !== false) {
248
-                    foreach ($this->tags as $T) {
249
-                        if (strtolower($T->getName()) === strtolower($tagname)) {
250
-                            $Tag = $T;
251
-                            break;
252
-                        }
253
-                    }
254
-                    if (!$Tag) {
255
-                        $Tag = new Tag($this, $tagname, $data);
256
-                        $this->tags[] = $Tag;
257
-                    }
258
-                }
259
-
260
-                if (!isset($this->paths[$path])) {
261
-                    $this->paths[$path] = new Path($this, $Tag ?: $this->defaultTag);
262
-                }
263
-
264
-                return $this->paths[$path];
265
-
266
-            case 'security':
267
-                $name = self::wordShift($data);
268
-                if (empty($name)) {
269
-                    throw new Exception('Missing security name');
270
-                }
271
-                $type = self::wordShift($data);
272
-                if (empty($type)) {
273
-                    throw new Exception('Missing security type');
274
-                }
275
-                $SecurityScheme = new SecurityScheme($this, $type, $data);
276
-                $this->securityDefinitions[$name] = $SecurityScheme;
277
-
278
-                return $SecurityScheme;
279
-
280
-            case 'require':
281
-                $name = self::wordShift($data);
282
-                if (empty($name)) {
283
-                    throw new Exception('Missing require name');
284
-                }
285
-                $scopes = self::wordSplit($data);
286
-                sort($scopes);
287
-                $this->security[] = [
288
-                    $name => empty($scopes) ? [] : $scopes,
289
-                ];
290
-
291
-                return $this;
292
-        }
293
-
294
-        return parent::handleCommand($command, $data);
295
-    }
296
-
297
-    /**
298
-     * @inheritDoc
299
-     * @throws Exception
300
-     * @throws Exception
301
-     */
302
-    public function toArray(): array
303
-    {
304
-        if (empty($this->paths)) {
305
-            throw new Exception('No path defined');
306
-        }
307
-
308
-        $schemes = array_unique($this->schemes);
309
-        sort($schemes);
310
-
311
-        $consumes = array_unique($this->consumes);
312
-        sort($consumes);
313
-
314
-        $produces = array_unique($this->produces);
315
-        sort($produces);
316
-
317
-        foreach ($this->security as $security) {
318
-            foreach ($security as $name => $scopes) {
319
-                if (!isset($this->securityDefinitions[$name])) {
320
-                    throw new Exception('Required security scheme not defined: \'' . $name . '\'');
321
-                }
322
-            }
323
-        }
324
-
325
-        return self::arrayFilterNull(array_merge([
326
-            'swagger' => $this->swagger,
327
-            'info' => $this->info->toArray(),
328
-            'host' => empty($this->host) ? null : $this->host,
329
-            'basePath' => empty($this->basePath) ? null : $this->basePath,
330
-            'consumes' => $consumes,
331
-            'produces' => $produces,
332
-            'schemes' => $schemes,
333
-            'paths' => self::objectsToArray($this->paths),
334
-            'definitions' => self::objectsToArray($this->definitions),
335
-            'parameters' => self::objectsToArray($this->parameters),
336
-            'responses' => self::objectsToArray($this->responses),
337
-            'securityDefinitions' => self::objectsToArray($this->securityDefinitions),
338
-            'security' => $this->security,
339
-            'tags' => self::objectsToArray($this->tags),
340
-        ], parent::toArray()));
341
-    }
342
-
343
-    public function __toString()
344
-    {
345
-        return __CLASS__;
346
-    }
347
-
348
-    /**
349
-     * Check if an operation with the given id exists.
350
-     *
351
-     * @param string $operationId
352
-     *
353
-     * @return boolean
354
-     */
355
-    public function hasOperationId($operationId)
356
-    {
357
-        foreach ($this->paths as $path) {
358
-            if ($path->hasOperationId($operationId)) {
359
-                return true;
360
-            }
361
-        }
362
-
363
-        return false;
364
-    }
365
-
366
-    /**
367
-     * Check if a definition with the given name exists
368
-     *
369
-     * @param string $name
370
-     *
371
-     * @return boolean
372
-     */
373
-    public function hasDefinition($name)
374
-    {
375
-        return isset($this->definitions[$name]);
376
-    }
377
-
378
-    /**
379
-     * @inheritDoc
380
-     */
381
-    protected function getSwagger(): Swagger
382
-    {
383
-        return $this;
384
-    }
385
-
386
-    /**
387
-     * @inheritDoc
388
-     */
389
-    protected function getTypeRegistry(): TypeRegistry
390
-    {
391
-        return $this->typeRegistry;
392
-    }
19
+	private $swagger = '2.0';
20
+	private $host;
21
+	private $basePath;
22
+
23
+	/**
24
+	 * @var TypeRegistry
25
+	 */
26
+	private $typeRegistry;
27
+
28
+	/**
29
+	 * @var Info $Info
30
+	 */
31
+	private $info;
32
+	private $schemes = [];
33
+	private $consumes = [];
34
+	private $produces = [];
35
+
36
+	/**
37
+	 * @var Path[] $Paths
38
+	 */
39
+	private $paths = [];
40
+
41
+	/**
42
+	 * @var Schema[] $definitions
43
+	 */
44
+	private $definitions = [];
45
+
46
+	/**
47
+	 * @var IParameter[] $parameters
48
+	 */
49
+	private $parameters = [];
50
+
51
+	/**
52
+	 * @var Response[] $responses
53
+	 */
54
+	private $responses = [];
55
+
56
+	/**
57
+	 * @var Tag[] $Tags
58
+	 */
59
+	private $tags = [];
60
+
61
+	/**
62
+	 * Default tag for new endpoints/operations. Set by the api command.
63
+	 *
64
+	 * @var Tag
65
+	 */
66
+	private $defaultTag = null;
67
+	private $securityDefinitions = [];
68
+	private $security = [];
69
+
70
+	/**
71
+	 * @param string $host
72
+	 * @param string $basePath
73
+	 * @param TypeRegistry $typeRegistry
74
+	 */
75
+	public function __construct($host = null, $basePath = null, $typeRegistry = null)
76
+	{
77
+		parent::__construct();
78
+
79
+		$this->host = $host;
80
+		$this->basePath = $basePath;
81
+
82
+		$this->info = new Info($this);
83
+
84
+		$this->typeRegistry = $typeRegistry ?: new TypeRegistry;
85
+	}
86
+
87
+	/**
88
+	 * Return all consumes
89
+	 *
90
+	 * @return array
91
+	 * @todo Deprecate in favour of a getConsume($name);
92
+	 */
93
+	public function getConsumes(): array
94
+	{
95
+		return $this->consumes;
96
+	}
97
+
98
+	/**
99
+	 * Return the named security if it exists, otherwise return FALSE
100
+	 *
101
+	 * @param string $name
102
+	 *
103
+	 * @return boolean|SecurityScheme
104
+	 */
105
+	public function getSecurity($name)
106
+	{
107
+		return $this->securityDefinitions[$name] ?? false;
108
+	}
109
+
110
+	/**
111
+	 * @param string $command
112
+	 * @param string $data
113
+	 *
114
+	 * @return AbstractObject|boolean
115
+	 * @throws Exception
116
+	 * @throws Exception
117
+	 * @throws Exception
118
+	 * @throws Exception
119
+	 * @throws Exception
120
+	 * @throws Exception
121
+	 * @throws Exception
122
+	 * @throws Exception
123
+	 * @throws Exception
124
+	 */
125
+	public function handleCommand($command, $data = null)
126
+	{
127
+		switch (strtolower($command)) {
128
+			// pass to Info
129
+			case 'title':
130
+			case 'description':
131
+			case 'version':
132
+			case 'terms': // alias
133
+			case 'tos': // alias
134
+			case 'termsofservice':
135
+			case 'contact':
136
+			case 'license':
137
+				return $this->info->handleCommand($command, $data);
138
+
139
+			// string[]
140
+			case 'scheme':
141
+			case 'schemes':
142
+				$this->schemes = array_unique(array_merge($this->schemes, self::wordSplit($data)));
143
+
144
+				return $this;
145
+
146
+			// MIME[]
147
+			case 'consume':
148
+			case 'consumes':
149
+				$this->consumes = array_merge($this->consumes, self::translateMimeTypes(self::wordSplit($data)));
150
+
151
+				return $this;
152
+
153
+			case 'produce':
154
+			case 'produces':
155
+				$this->produces = array_merge($this->produces, self::translateMimeTypes(self::wordSplit($data)));
156
+
157
+				return $this;
158
+
159
+			case 'model':
160
+			case 'model!':
161
+			case 'definition':
162
+			case 'definition!':
163
+				$name = self::wordShift($data);
164
+				if (empty($name)) {
165
+					throw new Exception('Missing definition name');
166
+				}
167
+				$typeDef = self::wordShift($data);
168
+				if (empty($typeDef)) {
169
+					$typeDef = 'object';
170
+				}
171
+
172
+				$definition = new Schema($this, $typeDef);
173
+				if (substr($command, -1) === '!') {
174
+					$definition->setReadOnly();
175
+				}
176
+				$this->definitions[$name] = $definition;
177
+
178
+				return $definition;
179
+
180
+			case 'path':
181
+			case 'query':
182
+			case 'query?':
183
+			case 'header':
184
+			case 'header?':
185
+			case 'form':
186
+			case 'form?':
187
+				$in = rtrim($command, '?');
188
+				$Parameter = new Parameter($this, $in, $data, substr($command, -1) !== '?');
189
+				$this->parameters[$Parameter->getName()] = $Parameter;
190
+
191
+				return $Parameter;
192
+
193
+			case 'body':
194
+			case 'body?':
195
+				$Parameter = new BodyParameter($this, $data, substr($command, -1) !== '?');
196
+				$this->parameters[$Parameter->getName()] = $Parameter;
197
+
198
+				return $Parameter;
199
+
200
+			case 'response':
201
+				$name = self::wordShift($data);
202
+				$definition = self::wordShift($data);
203
+				$description = $data;
204
+				if (empty($description)) {
205
+					throw new Exception('Response definition missing description');
206
+				}
207
+				$Response = new Response($this, $name, $definition === 'null' ? null : $definition, $description);
208
+				$this->responses[$name] = $Response;
209
+
210
+				return $Response;
211
+
212
+			case 'api': // alias
213
+			case 'tag':
214
+				$tagname = self::wordShift($data);
215
+				if (empty($tagname)) {
216
+					throw new Exception('Missing tag name');
217
+				}
218
+
219
+				$Tag = null;
220
+				foreach ($this->tags as $T) {
221
+					if ($T->getName() === $tagname) {
222
+						$Tag = $T;
223
+						break;
224
+					}
225
+				}
226
+				if (!$Tag) {
227
+					$Tag = new Tag($this, $tagname, $data);
228
+					$this->tags[] = $Tag;
229
+				}
230
+
231
+				// backwards compatibility
232
+				if ($command === 'api') {
233
+					$this->defaultTag = $Tag;
234
+				}
235
+
236
+				return $Tag;
237
+
238
+			case 'endpoint':
239
+				$path = self::wordShift($data);
240
+				if (false === $path) {
241
+					$path = '/';
242
+				} else if ($path[0] !== '/') {
243
+					$path = '/' . $path;
244
+				}
245
+
246
+				$Tag = null;
247
+				if (($tagname = self::wordShift($data)) !== false) {
248
+					foreach ($this->tags as $T) {
249
+						if (strtolower($T->getName()) === strtolower($tagname)) {
250
+							$Tag = $T;
251
+							break;
252
+						}
253
+					}
254
+					if (!$Tag) {
255
+						$Tag = new Tag($this, $tagname, $data);
256
+						$this->tags[] = $Tag;
257
+					}
258
+				}
259
+
260
+				if (!isset($this->paths[$path])) {
261
+					$this->paths[$path] = new Path($this, $Tag ?: $this->defaultTag);
262
+				}
263
+
264
+				return $this->paths[$path];
265
+
266
+			case 'security':
267
+				$name = self::wordShift($data);
268
+				if (empty($name)) {
269
+					throw new Exception('Missing security name');
270
+				}
271
+				$type = self::wordShift($data);
272
+				if (empty($type)) {
273
+					throw new Exception('Missing security type');
274
+				}
275
+				$SecurityScheme = new SecurityScheme($this, $type, $data);
276
+				$this->securityDefinitions[$name] = $SecurityScheme;
277
+
278
+				return $SecurityScheme;
279
+
280
+			case 'require':
281
+				$name = self::wordShift($data);
282
+				if (empty($name)) {
283
+					throw new Exception('Missing require name');
284
+				}
285
+				$scopes = self::wordSplit($data);
286
+				sort($scopes);
287
+				$this->security[] = [
288
+					$name => empty($scopes) ? [] : $scopes,
289
+				];
290
+
291
+				return $this;
292
+		}
293
+
294
+		return parent::handleCommand($command, $data);
295
+	}
296
+
297
+	/**
298
+	 * @inheritDoc
299
+	 * @throws Exception
300
+	 * @throws Exception
301
+	 */
302
+	public function toArray(): array
303
+	{
304
+		if (empty($this->paths)) {
305
+			throw new Exception('No path defined');
306
+		}
307
+
308
+		$schemes = array_unique($this->schemes);
309
+		sort($schemes);
310
+
311
+		$consumes = array_unique($this->consumes);
312
+		sort($consumes);
313
+
314
+		$produces = array_unique($this->produces);
315
+		sort($produces);
316
+
317
+		foreach ($this->security as $security) {
318
+			foreach ($security as $name => $scopes) {
319
+				if (!isset($this->securityDefinitions[$name])) {
320
+					throw new Exception('Required security scheme not defined: \'' . $name . '\'');
321
+				}
322
+			}
323
+		}
324
+
325
+		return self::arrayFilterNull(array_merge([
326
+			'swagger' => $this->swagger,
327
+			'info' => $this->info->toArray(),
328
+			'host' => empty($this->host) ? null : $this->host,
329
+			'basePath' => empty($this->basePath) ? null : $this->basePath,
330
+			'consumes' => $consumes,
331
+			'produces' => $produces,
332
+			'schemes' => $schemes,
333
+			'paths' => self::objectsToArray($this->paths),
334
+			'definitions' => self::objectsToArray($this->definitions),
335
+			'parameters' => self::objectsToArray($this->parameters),
336
+			'responses' => self::objectsToArray($this->responses),
337
+			'securityDefinitions' => self::objectsToArray($this->securityDefinitions),
338
+			'security' => $this->security,
339
+			'tags' => self::objectsToArray($this->tags),
340
+		], parent::toArray()));
341
+	}
342
+
343
+	public function __toString()
344
+	{
345
+		return __CLASS__;
346
+	}
347
+
348
+	/**
349
+	 * Check if an operation with the given id exists.
350
+	 *
351
+	 * @param string $operationId
352
+	 *
353
+	 * @return boolean
354
+	 */
355
+	public function hasOperationId($operationId)
356
+	{
357
+		foreach ($this->paths as $path) {
358
+			if ($path->hasOperationId($operationId)) {
359
+				return true;
360
+			}
361
+		}
362
+
363
+		return false;
364
+	}
365
+
366
+	/**
367
+	 * Check if a definition with the given name exists
368
+	 *
369
+	 * @param string $name
370
+	 *
371
+	 * @return boolean
372
+	 */
373
+	public function hasDefinition($name)
374
+	{
375
+		return isset($this->definitions[$name]);
376
+	}
377
+
378
+	/**
379
+	 * @inheritDoc
380
+	 */
381
+	protected function getSwagger(): Swagger
382
+	{
383
+		return $this;
384
+	}
385
+
386
+	/**
387
+	 * @inheritDoc
388
+	 */
389
+	protected function getTypeRegistry(): TypeRegistry
390
+	{
391
+		return $this->typeRegistry;
392
+	}
393 393
 
394 394
 }
Please login to merge, or discard this patch.
SwaggerGen/Swagger/Type/ReferenceObjectType.php 1 patch
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -15,48 +15,48 @@
 block discarded – undo
15 15
 class ReferenceObjectType extends AbstractType
16 16
 {
17 17
 
18
-    private $reference = null;
19
-
20
-    public function toArray(): array
21
-    {
22
-        return self::arrayFilterNull(array_merge(array(
23
-            '$ref' => '#/definitions/' . $this->reference,
24
-        ), parent::toArray()));
25
-    }
26
-
27
-    public function __toString()
28
-    {
29
-        return __CLASS__ . ' ' . $this->reference;
30
-    }
31
-
32
-    /**
33
-     * @throws Exception
34
-     */
35
-    protected function parseDefinition($definition)
36
-    {
37
-        $definition = self::trim($definition);
38
-
39
-        $match = [];
40
-        if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_CONTENT . self::REGEX_RANGE . self::REGEX_DEFAULT . self::REGEX_END, $definition, $match) !== 1) {
41
-            throw new Exception('Unparseable string definition: \'' . $definition . '\'');
42
-        }
43
-
44
-        $type = strtolower($match[1]);
45
-
46
-        $reference = null;
47
-        if ($type === 'refobject') {
48
-            if (isset($match[2])) {
49
-                $reference = $match[2];
50
-            }
51
-        } else {
52
-            $reference = $match[1];
53
-        }
54
-
55
-        if (empty($reference)) {
56
-            throw new Exception('Referenced object name missing: \'' . $definition . '\'');
57
-        }
58
-
59
-        $this->reference = $reference;
60
-    }
18
+	private $reference = null;
19
+
20
+	public function toArray(): array
21
+	{
22
+		return self::arrayFilterNull(array_merge(array(
23
+			'$ref' => '#/definitions/' . $this->reference,
24
+		), parent::toArray()));
25
+	}
26
+
27
+	public function __toString()
28
+	{
29
+		return __CLASS__ . ' ' . $this->reference;
30
+	}
31
+
32
+	/**
33
+	 * @throws Exception
34
+	 */
35
+	protected function parseDefinition($definition)
36
+	{
37
+		$definition = self::trim($definition);
38
+
39
+		$match = [];
40
+		if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_CONTENT . self::REGEX_RANGE . self::REGEX_DEFAULT . self::REGEX_END, $definition, $match) !== 1) {
41
+			throw new Exception('Unparseable string definition: \'' . $definition . '\'');
42
+		}
43
+
44
+		$type = strtolower($match[1]);
45
+
46
+		$reference = null;
47
+		if ($type === 'refobject') {
48
+			if (isset($match[2])) {
49
+				$reference = $match[2];
50
+			}
51
+		} else {
52
+			$reference = $match[1];
53
+		}
54
+
55
+		if (empty($reference)) {
56
+			throw new Exception('Referenced object name missing: \'' . $definition . '\'');
57
+		}
58
+
59
+		$this->reference = $reference;
60
+	}
61 61
 
62 62
 }
Please login to merge, or discard this patch.
SwaggerGen/Swagger/Type/ObjectType.php 2 patches
Indentation   +255 added lines, -255 removed lines patch added patch discarded remove patch
@@ -15,286 +15,286 @@
 block discarded – undo
15 15
 class ObjectType extends AbstractType
16 16
 {
17 17
 
18
-    /** @noinspection PhpRegExpUnsupportedModifierInspection */
19
-    const REGEX_OBJECT_CONTENT = '(?:(\{)(.*)\})?';
20
-    const REGEX_PROP_START = '/^';
21
-    const REGEX_PROP_NAME = '([^?!:]+)';
22
-    /** @noinspection PhpRegExpUnsupportedModifierInspection */
23
-    const REGEX_PROP_REQUIRED = '([\?!])?';
24
-    const REGEX_PROP_ASSIGN = ':';
25
-    const REGEX_PROP_DEFINITION = '(.+)';
26
-    /** @noinspection PhpRegExpUnsupportedModifierInspection
27
-     * @noinspection PhpRegExpInvalidDelimiterInspection
28
-     */
29
-    const REGEX_PROP_ADDITIONAL = '\.\.\.(!|.+)?';
30
-    const REGEX_PROP_END = '$/';
18
+	/** @noinspection PhpRegExpUnsupportedModifierInspection */
19
+	const REGEX_OBJECT_CONTENT = '(?:(\{)(.*)\})?';
20
+	const REGEX_PROP_START = '/^';
21
+	const REGEX_PROP_NAME = '([^?!:]+)';
22
+	/** @noinspection PhpRegExpUnsupportedModifierInspection */
23
+	const REGEX_PROP_REQUIRED = '([\?!])?';
24
+	const REGEX_PROP_ASSIGN = ':';
25
+	const REGEX_PROP_DEFINITION = '(.+)';
26
+	/** @noinspection PhpRegExpUnsupportedModifierInspection
27
+	 * @noinspection PhpRegExpInvalidDelimiterInspection
28
+	 */
29
+	const REGEX_PROP_ADDITIONAL = '\.\.\.(!|.+)?';
30
+	const REGEX_PROP_END = '$/';
31 31
 
32
-    private $minProperties = null;
33
-    private $maxProperties = null;
34
-    private $discriminator = null;
35
-    private $additionalProperties = null;
36
-    private $required = [];
32
+	private $minProperties = null;
33
+	private $maxProperties = null;
34
+	private $discriminator = null;
35
+	private $additionalProperties = null;
36
+	private $required = [];
37 37
 
38
-    /**
39
-     * @var Property[]
40
-     */
41
-    private $properties = [];
38
+	/**
39
+	 * @var Property[]
40
+	 */
41
+	private $properties = [];
42 42
 
43
-    /**
44
-     * @var Property
45
-     */
46
-    private $mostRecentProperty = null;
43
+	/**
44
+	 * @var Property
45
+	 */
46
+	private $mostRecentProperty = null;
47 47
 
48
-    /**
49
-     * @param string $command The comment command
50
-     * @param string $data Any data added after the command
51
-     * @return AbstractType|boolean
52
-     * @throws Exception
53
-     * @throws Exception
54
-     * @throws Exception
55
-     * @throws Exception
56
-     * @throws Exception
57
-     * @throws Exception
58
-     * @throws Exception
59
-     * @throws Exception
60
-     * @throws Exception
61
-     * @throws Exception
62
-     * @throws Exception
63
-     * @throws Exception
64
-     */
65
-    public function handleCommand($command, $data = null)
66
-    {
67
-        switch (strtolower($command)) {
68
-            // type name description...
69
-            case 'additionalproperties':
70
-                $value = self::wordShift($data);
71
-                if (is_bool($value)) {
72
-                    $type = $value;
73
-                } else if ($value === 'false') {
74
-                    $type = false;
75
-                } else if ($value === 'true') {
76
-                    $type = true;
77
-                } else {
78
-                    $type = self::typeFactory($this, $value, "Unparseable additional properties definition: '%s'");
79
-                }
80
-                $this->setAdditionalProperties($type);
81
-                return $this;
82
-            case 'discriminator':
83
-                $discriminator = self::wordShift($data);
84
-                $this->setDiscriminator($discriminator);
85
-                return $this;
86
-            case 'property':
87
-            case 'property?':
88
-            case 'property!':
89
-                $definition = self::wordShift($data);
90
-                if (empty($definition)) {
91
-                    throw new Exception("Missing property definition");
92
-                }
48
+	/**
49
+	 * @param string $command The comment command
50
+	 * @param string $data Any data added after the command
51
+	 * @return AbstractType|boolean
52
+	 * @throws Exception
53
+	 * @throws Exception
54
+	 * @throws Exception
55
+	 * @throws Exception
56
+	 * @throws Exception
57
+	 * @throws Exception
58
+	 * @throws Exception
59
+	 * @throws Exception
60
+	 * @throws Exception
61
+	 * @throws Exception
62
+	 * @throws Exception
63
+	 * @throws Exception
64
+	 */
65
+	public function handleCommand($command, $data = null)
66
+	{
67
+		switch (strtolower($command)) {
68
+			// type name description...
69
+			case 'additionalproperties':
70
+				$value = self::wordShift($data);
71
+				if (is_bool($value)) {
72
+					$type = $value;
73
+				} else if ($value === 'false') {
74
+					$type = false;
75
+				} else if ($value === 'true') {
76
+					$type = true;
77
+				} else {
78
+					$type = self::typeFactory($this, $value, "Unparseable additional properties definition: '%s'");
79
+				}
80
+				$this->setAdditionalProperties($type);
81
+				return $this;
82
+			case 'discriminator':
83
+				$discriminator = self::wordShift($data);
84
+				$this->setDiscriminator($discriminator);
85
+				return $this;
86
+			case 'property':
87
+			case 'property?':
88
+			case 'property!':
89
+				$definition = self::wordShift($data);
90
+				if (empty($definition)) {
91
+					throw new Exception("Missing property definition");
92
+				}
93 93
 
94
-                $name = self::wordShift($data);
95
-                if (empty($name)) {
96
-                    throw new Exception("Missing property name: '{$definition}'");
97
-                }
94
+				$name = self::wordShift($data);
95
+				if (empty($name)) {
96
+					throw new Exception("Missing property name: '{$definition}'");
97
+				}
98 98
 
99
-                $readOnly = null;
100
-                $required = false;
101
-                $propertySuffix = substr($command, -1);
102
-                if ($propertySuffix === '!') {
103
-                    $readOnly = true;
104
-                } else if ($propertySuffix !== '?') {
105
-                    $required = true;
106
-                }
99
+				$readOnly = null;
100
+				$required = false;
101
+				$propertySuffix = substr($command, -1);
102
+				if ($propertySuffix === '!') {
103
+					$readOnly = true;
104
+				} else if ($propertySuffix !== '?') {
105
+					$required = true;
106
+				}
107 107
 
108
-                if (($name === $this->discriminator) && !$required) {
109
-                    throw new Exception("Discriminator must be a required property, "
110
-                        . "property '{$name}' is not required");
111
-                }
108
+				if (($name === $this->discriminator) && !$required) {
109
+					throw new Exception("Discriminator must be a required property, "
110
+						. "property '{$name}' is not required");
111
+				}
112 112
 
113
-                unset($this->required[$name]);
114
-                if ($required) {
115
-                    $this->required[$name] = true;
116
-                }
113
+				unset($this->required[$name]);
114
+				if ($required) {
115
+					$this->required[$name] = true;
116
+				}
117 117
 
118
-                $this->mostRecentProperty = new Property($this, $definition, $data, $readOnly);
119
-                $this->properties[$name] = $this->mostRecentProperty;
120
-                return $this;
118
+				$this->mostRecentProperty = new Property($this, $definition, $data, $readOnly);
119
+				$this->properties[$name] = $this->mostRecentProperty;
120
+				return $this;
121 121
 
122
-            case 'min':
123
-                $this->minProperties = (int)$data;
124
-                if ($this->minProperties < 0) {
125
-                    throw new Exception("Minimum less than zero: '{$data}'");
126
-                }
127
-                if ($this->maxProperties !== null && $this->minProperties > $this->maxProperties) {
128
-                    throw new Exception("Minimum greater than maximum: '{$data}'");
129
-                }
130
-                $this->minProperties = (int)$data;
131
-                return $this;
122
+			case 'min':
123
+				$this->minProperties = (int)$data;
124
+				if ($this->minProperties < 0) {
125
+					throw new Exception("Minimum less than zero: '{$data}'");
126
+				}
127
+				if ($this->maxProperties !== null && $this->minProperties > $this->maxProperties) {
128
+					throw new Exception("Minimum greater than maximum: '{$data}'");
129
+				}
130
+				$this->minProperties = (int)$data;
131
+				return $this;
132 132
 
133
-            case 'max':
134
-                $this->maxProperties = (int)$data;
135
-                if ($this->minProperties !== null && $this->minProperties > $this->maxProperties) {
136
-                    throw new Exception("Maximum less than minimum: '{$data}'");
137
-                }
138
-                if ($this->maxProperties < 0) {
139
-                    throw new Exception("Maximum less than zero: '{$data}'");
140
-                }
141
-                return $this;
142
-        }
133
+			case 'max':
134
+				$this->maxProperties = (int)$data;
135
+				if ($this->minProperties !== null && $this->minProperties > $this->maxProperties) {
136
+					throw new Exception("Maximum less than minimum: '{$data}'");
137
+				}
138
+				if ($this->maxProperties < 0) {
139
+					throw new Exception("Maximum less than zero: '{$data}'");
140
+				}
141
+				return $this;
142
+		}
143 143
 
144
-        // Pass through to most recent Property
145
-        if ($this->mostRecentProperty && $this->mostRecentProperty->handleCommand($command, $data)) {
146
-            return $this;
147
-        }
144
+		// Pass through to most recent Property
145
+		if ($this->mostRecentProperty && $this->mostRecentProperty->handleCommand($command, $data)) {
146
+			return $this;
147
+		}
148 148
 
149
-        return parent::handleCommand($command, $data);
150
-    }
149
+		return parent::handleCommand($command, $data);
150
+	}
151 151
 
152
-    /**
153
-     * @param AbstractType|bool $type
154
-     * @return void
155
-     * @throws Exception
156
-     */
157
-    private function setAdditionalProperties($type)
158
-    {
159
-        if ($this->additionalProperties !== null) {
160
-            throw new Exception('Additional properties may only be set once');
161
-        }
162
-        $this->additionalProperties = $type;
163
-    }
152
+	/**
153
+	 * @param AbstractType|bool $type
154
+	 * @return void
155
+	 * @throws Exception
156
+	 */
157
+	private function setAdditionalProperties($type)
158
+	{
159
+		if ($this->additionalProperties !== null) {
160
+			throw new Exception('Additional properties may only be set once');
161
+		}
162
+		$this->additionalProperties = $type;
163
+	}
164 164
 
165
-    /**
166
-     * @param string|false $discriminator
167
-     * @throws Exception
168
-     * @throws Exception
169
-     */
170
-    private function setDiscriminator($discriminator)
171
-    {
172
-        if (!empty($this->discriminator)) {
173
-            throw new Exception("Discriminator may only be set once, "
174
-                . "trying to change it "
175
-                . "from '{$this->discriminator}' "
176
-                . "to '{$discriminator}'");
177
-        }
178
-        if (isset($this->properties[$discriminator]) && empty($this->required[$discriminator])) {
179
-            throw new Exception("Discriminator must be a required property, "
180
-                . "property '{$discriminator}' is not required");
181
-        }
182
-        $this->discriminator = $discriminator;
183
-    }
165
+	/**
166
+	 * @param string|false $discriminator
167
+	 * @throws Exception
168
+	 * @throws Exception
169
+	 */
170
+	private function setDiscriminator($discriminator)
171
+	{
172
+		if (!empty($this->discriminator)) {
173
+			throw new Exception("Discriminator may only be set once, "
174
+				. "trying to change it "
175
+				. "from '{$this->discriminator}' "
176
+				. "to '{$discriminator}'");
177
+		}
178
+		if (isset($this->properties[$discriminator]) && empty($this->required[$discriminator])) {
179
+			throw new Exception("Discriminator must be a required property, "
180
+				. "property '{$discriminator}' is not required");
181
+		}
182
+		$this->discriminator = $discriminator;
183
+	}
184 184
 
185
-    public function toArray(): array
186
-    {
187
-        return self::arrayFilterNull(array_merge(array(
188
-            'type' => 'object',
189
-            'required' => array_keys($this->required),
190
-            'properties' => self::objectsToArray($this->properties),
191
-            'minProperties' => $this->minProperties,
192
-            'maxProperties' => $this->maxProperties,
193
-            'discriminator' => $this->discriminator,
194
-            'additionalProperties' => $this->additionalProperties instanceof AbstractType ? $this->additionalProperties->toArray() : $this->additionalProperties,
195
-        ), parent::toArray()));
196
-    }
185
+	public function toArray(): array
186
+	{
187
+		return self::arrayFilterNull(array_merge(array(
188
+			'type' => 'object',
189
+			'required' => array_keys($this->required),
190
+			'properties' => self::objectsToArray($this->properties),
191
+			'minProperties' => $this->minProperties,
192
+			'maxProperties' => $this->maxProperties,
193
+			'discriminator' => $this->discriminator,
194
+			'additionalProperties' => $this->additionalProperties instanceof AbstractType ? $this->additionalProperties->toArray() : $this->additionalProperties,
195
+		), parent::toArray()));
196
+	}
197 197
 
198
-    public function __toString()
199
-    {
200
-        return __CLASS__;
201
-    }
198
+	public function __toString()
199
+	{
200
+		return __CLASS__;
201
+	}
202 202
 
203
-    /**
204
-     * @throws Exception
205
-     */
206
-    protected function parseDefinition($definition)
207
-    {
208
-        $definition = self::trim($definition);
203
+	/**
204
+	 * @throws Exception
205
+	 */
206
+	protected function parseDefinition($definition)
207
+	{
208
+		$definition = self::trim($definition);
209 209
 
210
-        $match = [];
211
-        if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_CONTENT . self::REGEX_RANGE . self::REGEX_END, $definition, $match) === 1) {
212
-            $match[1] = strtolower($match[1]);
213
-        } elseif (preg_match(self::REGEX_START . self::REGEX_OBJECT_CONTENT . self::REGEX_RANGE . self::REGEX_END, $definition, $match) === 1) {
214
-            $match[1] = 'object';
215
-        } else {
216
-            throw new Exception('Unparseable object definition: \'' . $definition . '\'');
217
-        }
210
+		$match = [];
211
+		if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_CONTENT . self::REGEX_RANGE . self::REGEX_END, $definition, $match) === 1) {
212
+			$match[1] = strtolower($match[1]);
213
+		} elseif (preg_match(self::REGEX_START . self::REGEX_OBJECT_CONTENT . self::REGEX_RANGE . self::REGEX_END, $definition, $match) === 1) {
214
+			$match[1] = 'object';
215
+		} else {
216
+			throw new Exception('Unparseable object definition: \'' . $definition . '\'');
217
+		}
218 218
 
219
-        $this->parseFormat($definition, $match);
220
-        $this->parseProperties($definition, $match);
221
-        $this->parseRange($definition, $match);
222
-    }
219
+		$this->parseFormat($definition, $match);
220
+		$this->parseProperties($definition, $match);
221
+		$this->parseRange($definition, $match);
222
+	}
223 223
 
224
-    /**
225
-     * @param string $definition
226
-     * @param string[] $match
227
-     * @throws Exception
228
-     */
229
-    private function parseFormat($definition, $match)
230
-    {
231
-        if (strtolower($match[1]) !== 'object') {
232
-            throw new Exception("Not an object: '{$definition}'");
233
-        }
234
-    }
224
+	/**
225
+	 * @param string $definition
226
+	 * @param string[] $match
227
+	 * @throws Exception
228
+	 */
229
+	private function parseFormat($definition, $match)
230
+	{
231
+		if (strtolower($match[1]) !== 'object') {
232
+			throw new Exception("Not an object: '{$definition}'");
233
+		}
234
+	}
235 235
 
236
-    /**
237
-     * @param string $definition
238
-     * @param string[] $match
239
-     * @throws Exception
240
-     * @throws Exception
241
-     * @throws Exception
242
-     * @throws Exception
243
-     * @throws Exception
244
-     * @throws Exception
245
-     */
246
-    private function parseProperties($definition, $match)
247
-    {
248
-        if (empty($match[2])) {
249
-            return;
250
-        }
236
+	/**
237
+	 * @param string $definition
238
+	 * @param string[] $match
239
+	 * @throws Exception
240
+	 * @throws Exception
241
+	 * @throws Exception
242
+	 * @throws Exception
243
+	 * @throws Exception
244
+	 * @throws Exception
245
+	 */
246
+	private function parseProperties($definition, $match)
247
+	{
248
+		if (empty($match[2])) {
249
+			return;
250
+		}
251 251
 
252
-        while (($property = self::parseListItem($match[2])) !== '') {
253
-            $prop_match = [];
254
-            if (preg_match(self::REGEX_PROP_START . self::REGEX_PROP_ADDITIONAL . self::REGEX_PROP_END, $property, $prop_match) === 1) {
255
-                if (empty($prop_match[1])) {
256
-                    $this->setAdditionalProperties(true);
257
-                } else if ($prop_match[1] === '!') {
258
-                    $this->setAdditionalProperties(false);
259
-                } else {
260
-                    $this->setAdditionalProperties(self::typeFactory($this, $prop_match[1], "Unparseable additional properties definition: '...%s'"));
261
-                }
262
-                continue;
263
-            }
264
-            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) {
265
-                throw new Exception("Unparseable property definition: '{$property}'");
266
-            }
267
-            $this->properties[$prop_match[1]] = new Property($this, $prop_match[3]);
268
-            if ($prop_match[2] !== '!' && $prop_match[2] !== '?') {
269
-                $this->required[$prop_match[1]] = true;
270
-            }
271
-        }
252
+		while (($property = self::parseListItem($match[2])) !== '') {
253
+			$prop_match = [];
254
+			if (preg_match(self::REGEX_PROP_START . self::REGEX_PROP_ADDITIONAL . self::REGEX_PROP_END, $property, $prop_match) === 1) {
255
+				if (empty($prop_match[1])) {
256
+					$this->setAdditionalProperties(true);
257
+				} else if ($prop_match[1] === '!') {
258
+					$this->setAdditionalProperties(false);
259
+				} else {
260
+					$this->setAdditionalProperties(self::typeFactory($this, $prop_match[1], "Unparseable additional properties definition: '...%s'"));
261
+				}
262
+				continue;
263
+			}
264
+			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) {
265
+				throw new Exception("Unparseable property definition: '{$property}'");
266
+			}
267
+			$this->properties[$prop_match[1]] = new Property($this, $prop_match[3]);
268
+			if ($prop_match[2] !== '!' && $prop_match[2] !== '?') {
269
+				$this->required[$prop_match[1]] = true;
270
+			}
271
+		}
272 272
 
273
-    }
273
+	}
274 274
 
275
-    /**
276
-     * @param string $definition
277
-     * @param string[] $match
278
-     * @throws Exception
279
-     */
280
-    private function parseRange($definition, $match)
281
-    {
282
-        if (!empty($match[3])) {
283
-            if ($match[4] === '' && $match[5] === '') {
284
-                throw new Exception("Empty object range: '{$definition}'");
285
-            }
275
+	/**
276
+	 * @param string $definition
277
+	 * @param string[] $match
278
+	 * @throws Exception
279
+	 */
280
+	private function parseRange($definition, $match)
281
+	{
282
+		if (!empty($match[3])) {
283
+			if ($match[4] === '' && $match[5] === '') {
284
+				throw new Exception("Empty object range: '{$definition}'");
285
+			}
286 286
 
287
-            $exclusiveMinimum = $match[3] == '<';
288
-            $this->minProperties = $match[4] === '' ? null : (int)$match[4];
289
-            $this->maxProperties = $match[5] === '' ? null : (int)$match[5];
290
-            $exclusiveMaximum = isset($match[6]) ? ($match[6] == '>') : null;
291
-            if ($this->minProperties && $this->maxProperties && $this->minProperties > $this->maxProperties) {
292
-                self::swap($this->minProperties, $this->maxProperties);
293
-                self::swap($exclusiveMinimum, $exclusiveMaximum);
294
-            }
295
-            $this->minProperties = $this->minProperties === null ? null : max(0, $exclusiveMinimum ? $this->minProperties + 1 : $this->minProperties);
296
-            $this->maxProperties = $this->maxProperties === null ? null : max(0, $exclusiveMaximum ? $this->maxProperties - 1 : $this->maxProperties);
297
-        }
298
-    }
287
+			$exclusiveMinimum = $match[3] == '<';
288
+			$this->minProperties = $match[4] === '' ? null : (int)$match[4];
289
+			$this->maxProperties = $match[5] === '' ? null : (int)$match[5];
290
+			$exclusiveMaximum = isset($match[6]) ? ($match[6] == '>') : null;
291
+			if ($this->minProperties && $this->maxProperties && $this->minProperties > $this->maxProperties) {
292
+				self::swap($this->minProperties, $this->maxProperties);
293
+				self::swap($exclusiveMinimum, $exclusiveMaximum);
294
+			}
295
+			$this->minProperties = $this->minProperties === null ? null : max(0, $exclusiveMinimum ? $this->minProperties + 1 : $this->minProperties);
296
+			$this->maxProperties = $this->maxProperties === null ? null : max(0, $exclusiveMaximum ? $this->maxProperties - 1 : $this->maxProperties);
297
+		}
298
+	}
299 299
 
300 300
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -120,18 +120,18 @@  discard block
 block discarded – undo
120 120
                 return $this;
121 121
 
122 122
             case 'min':
123
-                $this->minProperties = (int)$data;
123
+                $this->minProperties = (int) $data;
124 124
                 if ($this->minProperties < 0) {
125 125
                     throw new Exception("Minimum less than zero: '{$data}'");
126 126
                 }
127 127
                 if ($this->maxProperties !== null && $this->minProperties > $this->maxProperties) {
128 128
                     throw new Exception("Minimum greater than maximum: '{$data}'");
129 129
                 }
130
-                $this->minProperties = (int)$data;
130
+                $this->minProperties = (int) $data;
131 131
                 return $this;
132 132
 
133 133
             case 'max':
134
-                $this->maxProperties = (int)$data;
134
+                $this->maxProperties = (int) $data;
135 135
                 if ($this->minProperties !== null && $this->minProperties > $this->maxProperties) {
136 136
                     throw new Exception("Maximum less than minimum: '{$data}'");
137 137
                 }
@@ -285,8 +285,8 @@  discard block
 block discarded – undo
285 285
             }
286 286
 
287 287
             $exclusiveMinimum = $match[3] == '<';
288
-            $this->minProperties = $match[4] === '' ? null : (int)$match[4];
289
-            $this->maxProperties = $match[5] === '' ? null : (int)$match[5];
288
+            $this->minProperties = $match[4] === '' ? null : (int) $match[4];
289
+            $this->maxProperties = $match[5] === '' ? null : (int) $match[5];
290 290
             $exclusiveMaximum = isset($match[6]) ? ($match[6] == '>') : null;
291 291
             if ($this->minProperties && $this->maxProperties && $this->minProperties > $this->maxProperties) {
292 292
                 self::swap($this->minProperties, $this->maxProperties);
Please login to merge, or discard this patch.