Completed
Pull Request — master (#51)
by
unknown
20s
created
SwaggerGen/Swagger/Type/NumberType.php 1 patch
Indentation   +149 added lines, -149 removed lines patch added patch discarded remove patch
@@ -15,154 +15,154 @@
 block discarded – undo
15 15
 class NumberType extends AbstractType
16 16
 {
17 17
 
18
-    const REGEX_RANGE = '(?:([[<])(-?(?:\\d*\\.?\\d+|\\d+\\.\\d*))?,(-?(?:\\d*\\.?\\d+|\\d+\\.\\d*))?([\\]>]))?';
19
-    const REGEX_DEFAULT = '(?:=(-?(?:\\d*\\.?\\d+|\\d+\\.\\d*)))?';
20
-
21
-    private static $formats = array(
22
-        'float' => 'float',
23
-        'double' => 'double',
24
-    );
25
-    private $format;
26
-    private $default = null;
27
-    private $maximum = null;
28
-    private $exclusiveMaximum = null;
29
-    private $minimum = null;
30
-    private $exclusiveMinimum = null;
31
-    private $enum = array();
32
-    private $multipleOf = null;
33
-
34
-    /**
35
-     * @throws Exception
36
-     */
37
-    protected function parseDefinition($definition)
38
-    {
39
-        $match = array();
40
-        if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_RANGE . self::REGEX_DEFAULT . self::REGEX_END, $definition, $match) !== 1) {
41
-            throw new Exception("Unparseable number definition: '{$definition}'");
42
-        }
43
-
44
-        $this->parseFormat($definition, $match);
45
-        $this->parseRange($definition, $match);
46
-        $this->parseDefault($definition, $match);
47
-    }
48
-
49
-    /**
50
-     * @param string[] $match
51
-     * @throws Exception
52
-     */
53
-    private function parseFormat($definition, $match)
54
-    {
55
-        if (!isset(self::$formats[strtolower($match[1])])) {
56
-            throw new Exception("Not a number: '{$definition}'");
57
-        }
58
-        $this->format = self::$formats[strtolower($match[1])];
59
-    }
60
-
61
-    /**
62
-     * @param string[] $match
63
-     * @throws Exception
64
-     */
65
-    private function parseRange($definition, $match)
66
-    {
67
-        if (!empty($match[2])) {
68
-            if ($match[3] === '' && $match[4] === '') {
69
-                throw new Exception("Empty number range: '{$definition}'");
70
-            }
71
-
72
-            $this->exclusiveMinimum = $match[2] == '<';
73
-            $this->minimum = $match[3] === '' ? null : doubleval($match[3]);
74
-            $this->maximum = $match[4] === '' ? null : doubleval($match[4]);
75
-            $this->exclusiveMaximum = isset($match[5]) ? ($match[5] == '>') : null;
76
-            if ($this->minimum && $this->maximum && $this->minimum > $this->maximum) {
77
-                self::swap($this->minimum, $this->maximum);
78
-                self::swap($this->exclusiveMinimum, $this->exclusiveMaximum);
79
-            }
80
-        }
81
-    }
82
-
83
-    /**
84
-     * @param string[] $match
85
-     * @throws Exception
86
-     */
87
-    private function parseDefault($definition, $match)
88
-    {
89
-        $this->default = isset($match[6]) && $match[6] !== '' ? $this->validateDefault($match[6]) : null;
90
-    }
91
-
92
-    /**
93
-     * @param string $command The comment command
94
-     * @param string $data Any data added after the command
95
-     * @return AbstractType|boolean
96
-     * @throws Exception
97
-     * @throws Exception
98
-     * @throws Exception
99
-     */
100
-    public function handleCommand($command, $data = null)
101
-    {
102
-        switch (strtolower($command)) {
103
-            case 'default':
104
-                $this->default = $this->validateDefault($data);
105
-                return $this;
106
-
107
-            case 'enum':
108
-                $words = self::wordSplit($data);
109
-                foreach ($words as &$word) {
110
-                    $word = $this->validateDefault($word);
111
-                }
112
-                $this->enum = array_merge($this->enum, $words);
113
-                return $this;
114
-
115
-            case 'step':
116
-                if (($step = doubleval($data)) > 0) {
117
-                    $this->multipleOf = $step;
118
-                }
119
-                return $this;
120
-        }
121
-
122
-        return parent::handleCommand($command, $data);
123
-    }
124
-
125
-    public function toArray()
126
-    {
127
-        return self::arrayFilterNull(array_merge(array(
128
-            'type' => 'number',
129
-            'format' => $this->format,
130
-            'default' => $this->default,
131
-            'minimum' => $this->minimum,
132
-            'exclusiveMinimum' => ($this->exclusiveMinimum && !is_null($this->minimum)) ? true : null,
133
-            'maximum' => $this->maximum,
134
-            'exclusiveMaximum' => ($this->exclusiveMaximum && !is_null($this->maximum)) ? true : null,
135
-            'enum' => $this->enum,
136
-            'multipleOf' => $this->multipleOf,
137
-        ), parent::toArray()));
138
-    }
139
-
140
-    public function __toString()
141
-    {
142
-        return __CLASS__;
143
-    }
144
-
145
-    /**
146
-     * @throws Exception
147
-     */
148
-    private function validateDefault($value)
149
-    {
150
-        if (preg_match('~^-?(?:\\d*\\.?\\d+|\\d+\\.\\d*)$~', $value) !== 1) {
151
-            throw new Exception("Invalid number default: '{$value}'");
152
-        }
153
-
154
-        if ($this->maximum) {
155
-            if (($value > $this->maximum) || ($this->exclusiveMaximum && $value == $this->maximum)) {
156
-                throw new Exception("Default number beyond maximum: '{$value}'");
157
-            }
158
-        }
159
-        if ($this->minimum) {
160
-            if (($value < $this->minimum) || ($this->exclusiveMinimum && $value == $this->minimum)) {
161
-                throw new Exception("Default number beyond minimum: '{$value}'");
162
-            }
163
-        }
164
-
165
-        return doubleval($value);
166
-    }
18
+	const REGEX_RANGE = '(?:([[<])(-?(?:\\d*\\.?\\d+|\\d+\\.\\d*))?,(-?(?:\\d*\\.?\\d+|\\d+\\.\\d*))?([\\]>]))?';
19
+	const REGEX_DEFAULT = '(?:=(-?(?:\\d*\\.?\\d+|\\d+\\.\\d*)))?';
20
+
21
+	private static $formats = array(
22
+		'float' => 'float',
23
+		'double' => 'double',
24
+	);
25
+	private $format;
26
+	private $default = null;
27
+	private $maximum = null;
28
+	private $exclusiveMaximum = null;
29
+	private $minimum = null;
30
+	private $exclusiveMinimum = null;
31
+	private $enum = array();
32
+	private $multipleOf = null;
33
+
34
+	/**
35
+	 * @throws Exception
36
+	 */
37
+	protected function parseDefinition($definition)
38
+	{
39
+		$match = array();
40
+		if (preg_match(self::REGEX_START . self::REGEX_FORMAT . self::REGEX_RANGE . self::REGEX_DEFAULT . self::REGEX_END, $definition, $match) !== 1) {
41
+			throw new Exception("Unparseable number definition: '{$definition}'");
42
+		}
43
+
44
+		$this->parseFormat($definition, $match);
45
+		$this->parseRange($definition, $match);
46
+		$this->parseDefault($definition, $match);
47
+	}
48
+
49
+	/**
50
+	 * @param string[] $match
51
+	 * @throws Exception
52
+	 */
53
+	private function parseFormat($definition, $match)
54
+	{
55
+		if (!isset(self::$formats[strtolower($match[1])])) {
56
+			throw new Exception("Not a number: '{$definition}'");
57
+		}
58
+		$this->format = self::$formats[strtolower($match[1])];
59
+	}
60
+
61
+	/**
62
+	 * @param string[] $match
63
+	 * @throws Exception
64
+	 */
65
+	private function parseRange($definition, $match)
66
+	{
67
+		if (!empty($match[2])) {
68
+			if ($match[3] === '' && $match[4] === '') {
69
+				throw new Exception("Empty number range: '{$definition}'");
70
+			}
71
+
72
+			$this->exclusiveMinimum = $match[2] == '<';
73
+			$this->minimum = $match[3] === '' ? null : doubleval($match[3]);
74
+			$this->maximum = $match[4] === '' ? null : doubleval($match[4]);
75
+			$this->exclusiveMaximum = isset($match[5]) ? ($match[5] == '>') : null;
76
+			if ($this->minimum && $this->maximum && $this->minimum > $this->maximum) {
77
+				self::swap($this->minimum, $this->maximum);
78
+				self::swap($this->exclusiveMinimum, $this->exclusiveMaximum);
79
+			}
80
+		}
81
+	}
82
+
83
+	/**
84
+	 * @param string[] $match
85
+	 * @throws Exception
86
+	 */
87
+	private function parseDefault($definition, $match)
88
+	{
89
+		$this->default = isset($match[6]) && $match[6] !== '' ? $this->validateDefault($match[6]) : null;
90
+	}
91
+
92
+	/**
93
+	 * @param string $command The comment command
94
+	 * @param string $data Any data added after the command
95
+	 * @return AbstractType|boolean
96
+	 * @throws Exception
97
+	 * @throws Exception
98
+	 * @throws Exception
99
+	 */
100
+	public function handleCommand($command, $data = null)
101
+	{
102
+		switch (strtolower($command)) {
103
+			case 'default':
104
+				$this->default = $this->validateDefault($data);
105
+				return $this;
106
+
107
+			case 'enum':
108
+				$words = self::wordSplit($data);
109
+				foreach ($words as &$word) {
110
+					$word = $this->validateDefault($word);
111
+				}
112
+				$this->enum = array_merge($this->enum, $words);
113
+				return $this;
114
+
115
+			case 'step':
116
+				if (($step = doubleval($data)) > 0) {
117
+					$this->multipleOf = $step;
118
+				}
119
+				return $this;
120
+		}
121
+
122
+		return parent::handleCommand($command, $data);
123
+	}
124
+
125
+	public function toArray()
126
+	{
127
+		return self::arrayFilterNull(array_merge(array(
128
+			'type' => 'number',
129
+			'format' => $this->format,
130
+			'default' => $this->default,
131
+			'minimum' => $this->minimum,
132
+			'exclusiveMinimum' => ($this->exclusiveMinimum && !is_null($this->minimum)) ? true : null,
133
+			'maximum' => $this->maximum,
134
+			'exclusiveMaximum' => ($this->exclusiveMaximum && !is_null($this->maximum)) ? true : null,
135
+			'enum' => $this->enum,
136
+			'multipleOf' => $this->multipleOf,
137
+		), parent::toArray()));
138
+	}
139
+
140
+	public function __toString()
141
+	{
142
+		return __CLASS__;
143
+	}
144
+
145
+	/**
146
+	 * @throws Exception
147
+	 */
148
+	private function validateDefault($value)
149
+	{
150
+		if (preg_match('~^-?(?:\\d*\\.?\\d+|\\d+\\.\\d*)$~', $value) !== 1) {
151
+			throw new Exception("Invalid number default: '{$value}'");
152
+		}
153
+
154
+		if ($this->maximum) {
155
+			if (($value > $this->maximum) || ($this->exclusiveMaximum && $value == $this->maximum)) {
156
+				throw new Exception("Default number beyond maximum: '{$value}'");
157
+			}
158
+		}
159
+		if ($this->minimum) {
160
+			if (($value < $this->minimum) || ($this->exclusiveMinimum && $value == $this->minimum)) {
161
+				throw new Exception("Default number beyond minimum: '{$value}'");
162
+			}
163
+		}
164
+
165
+		return doubleval($value);
166
+	}
167 167
 
168 168
 }
Please login to merge, or discard this patch.
SwaggerGen/Swagger/Info.php 2 patches
Indentation   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -14,106 +14,106 @@
 block discarded – undo
14 14
 class Info extends AbstractObject
15 15
 {
16 16
 
17
-    /**
18
-     * @var string
19
-     */
20
-    private $title = 'undefined';
21
-
22
-    /**
23
-     * @var string
24
-     */
25
-    private $description;
26
-
27
-    /**
28
-     * @var string
29
-     */
30
-    private $termsofservice;
31
-
32
-    /**
33
-     * @var Contact
34
-     */
35
-    private $contact;
36
-
37
-    /**
38
-     * @var License
39
-     */
40
-    private $license;
41
-
42
-    /**
43
-     * @var string|integer|float
44
-     */
45
-    private $version = 0;
46
-
47
-    /**
48
-     * @param string $command
49
-     * @param string $data
50
-     * @return AbstractObject|boolean
51
-     */
52
-    public function handleCommand($command, $data = null)
53
-    {
54
-        switch (strtolower($command)) {
55
-            case 'title':
56
-            case 'description':
57
-            case 'termsofservice':
58
-            case 'version':
59
-                $this->$command = $data;
60
-                return $this;
61
-
62
-            case 'terms': // alias
63
-            case 'tos': // alias
64
-                $this->termsofservice = $data;
65
-                return $this;
66
-
67
-            case 'contact':
68
-                $name = array();
69
-                $url = null;
70
-                $email = null;
71
-                foreach (self::wordSplit($data) as $word) {
72
-                    if (filter_var($word, FILTER_VALIDATE_URL)) {
73
-                        $url = $word;
74
-                    } elseif (filter_var($word, FILTER_VALIDATE_EMAIL)) {
75
-                        $email = $word;
76
-                    } else {
77
-                        $name[] = $word;
78
-                    }
79
-                }
80
-                $name = join(' ', array_filter($name));
81
-                $this->contact = new Contact($this, $name, $url, $email);
82
-                return $this->contact;
83
-
84
-            case 'license':
85
-                $name = array();
86
-                $url = null;
87
-                foreach (self::wordSplit($data) as $word) {
88
-                    if (filter_var($word, FILTER_VALIDATE_URL)) {
89
-                        $url = $word;
90
-                    } else {
91
-                        $name[] = $word;
92
-                    }
93
-                }
94
-                $name = join(' ', array_filter($name));
95
-                $this->license = new License($this, $name, $url);
96
-                return $this->license;
97
-        }
98
-
99
-        return parent::handleCommand($command, $data);
100
-    }
101
-
102
-    public function toArray()
103
-    {
104
-        return self::arrayFilterNull(array_merge(array(
105
-            'title' => $this->title,
106
-            'description' => $this->description,
107
-            'termsOfService' => $this->termsofservice,
108
-            'contact' => $this->contact ? $this->contact->toArray() : null,
109
-            'license' => $this->license ? $this->license->toArray() : null,
110
-            'version' => (string)$this->version,
111
-        ), parent::toArray()));
112
-    }
113
-
114
-    public function __toString()
115
-    {
116
-        return __CLASS__ . ' \'' . $this->title . '\'';
117
-    }
17
+	/**
18
+	 * @var string
19
+	 */
20
+	private $title = 'undefined';
21
+
22
+	/**
23
+	 * @var string
24
+	 */
25
+	private $description;
26
+
27
+	/**
28
+	 * @var string
29
+	 */
30
+	private $termsofservice;
31
+
32
+	/**
33
+	 * @var Contact
34
+	 */
35
+	private $contact;
36
+
37
+	/**
38
+	 * @var License
39
+	 */
40
+	private $license;
41
+
42
+	/**
43
+	 * @var string|integer|float
44
+	 */
45
+	private $version = 0;
46
+
47
+	/**
48
+	 * @param string $command
49
+	 * @param string $data
50
+	 * @return AbstractObject|boolean
51
+	 */
52
+	public function handleCommand($command, $data = null)
53
+	{
54
+		switch (strtolower($command)) {
55
+			case 'title':
56
+			case 'description':
57
+			case 'termsofservice':
58
+			case 'version':
59
+				$this->$command = $data;
60
+				return $this;
61
+
62
+			case 'terms': // alias
63
+			case 'tos': // alias
64
+				$this->termsofservice = $data;
65
+				return $this;
66
+
67
+			case 'contact':
68
+				$name = array();
69
+				$url = null;
70
+				$email = null;
71
+				foreach (self::wordSplit($data) as $word) {
72
+					if (filter_var($word, FILTER_VALIDATE_URL)) {
73
+						$url = $word;
74
+					} elseif (filter_var($word, FILTER_VALIDATE_EMAIL)) {
75
+						$email = $word;
76
+					} else {
77
+						$name[] = $word;
78
+					}
79
+				}
80
+				$name = join(' ', array_filter($name));
81
+				$this->contact = new Contact($this, $name, $url, $email);
82
+				return $this->contact;
83
+
84
+			case 'license':
85
+				$name = array();
86
+				$url = null;
87
+				foreach (self::wordSplit($data) as $word) {
88
+					if (filter_var($word, FILTER_VALIDATE_URL)) {
89
+						$url = $word;
90
+					} else {
91
+						$name[] = $word;
92
+					}
93
+				}
94
+				$name = join(' ', array_filter($name));
95
+				$this->license = new License($this, $name, $url);
96
+				return $this->license;
97
+		}
98
+
99
+		return parent::handleCommand($command, $data);
100
+	}
101
+
102
+	public function toArray()
103
+	{
104
+		return self::arrayFilterNull(array_merge(array(
105
+			'title' => $this->title,
106
+			'description' => $this->description,
107
+			'termsOfService' => $this->termsofservice,
108
+			'contact' => $this->contact ? $this->contact->toArray() : null,
109
+			'license' => $this->license ? $this->license->toArray() : null,
110
+			'version' => (string)$this->version,
111
+		), parent::toArray()));
112
+	}
113
+
114
+	public function __toString()
115
+	{
116
+		return __CLASS__ . ' \'' . $this->title . '\'';
117
+	}
118 118
 
119 119
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -107,7 +107,7 @@
 block discarded – undo
107 107
             'termsOfService' => $this->termsofservice,
108 108
             'contact' => $this->contact ? $this->contact->toArray() : null,
109 109
             'license' => $this->license ? $this->license->toArray() : null,
110
-            'version' => (string)$this->version,
110
+            'version' => (string) $this->version,
111 111
         ), parent::toArray()));
112 112
     }
113 113
 
Please login to merge, or discard this patch.
SwaggerGen/Parser/AbstractPreprocessor.php 1 patch
Indentation   +119 added lines, -119 removed lines patch added patch discarded remove patch
@@ -13,123 +13,123 @@
 block discarded – undo
13 13
 abstract class AbstractPreprocessor
14 14
 {
15 15
 
16
-    private $defines = array();
17
-    private $stack = array();
18
-
19
-    public function __construct()
20
-    {
21
-        $this->resetDefines();
22
-    }
23
-
24
-    public function resetDefines()
25
-    {
26
-        $this->defines = array();
27
-    }
28
-
29
-    public function addDefines(array $defines)
30
-    {
31
-        $this->defines = array_merge($this->defines, $defines);
32
-    }
33
-
34
-    public function define($name, $value = 1)
35
-    {
36
-        $this->defines[$name] = $value;
37
-    }
38
-
39
-    public function undefine($name)
40
-    {
41
-        unset($this->defines[$name]);
42
-    }
43
-
44
-    protected function getState()
45
-    {
46
-        return empty($this->stack) || end($this->stack);
47
-    }
48
-
49
-    /**
50
-     * Get the first word from a string and remove it from the string.
51
-     *
52
-     * @param string $data
53
-     * @return boolean|string
54
-     */
55
-    private static function wordShift(&$data)
56
-    {
57
-        if (preg_match('~^(\S+)\s*(.*)$~', $data, $matches) === 1) {
58
-            $data = $matches[2];
59
-            return $matches[1];
60
-        }
61
-        return false;
62
-    }
63
-
64
-    protected function handle($command, $expression)
65
-    {
66
-        switch (strtolower($command)) {
67
-            case 'if':
68
-                $name = self::wordShift($expression);
69
-                $state = $this->getState();
70
-                if (empty($expression)) {
71
-                    $this->stack[] = $state && !empty($this->defines[$name]);
72
-                } else {
73
-                    $this->stack[] = $state && isset($this->defines[$name]) && $this->defines[$name] == $expression;
74
-                }
75
-                break;
76
-
77
-            case 'ifdef':
78
-                $this->stack[] = $this->getState() && isset($this->defines[$expression]);
79
-                break;
80
-
81
-            case 'ifndef':
82
-                $this->stack[] = $this->getState() && !isset($this->defines[$expression]);
83
-                break;
84
-
85
-            case 'else':
86
-                $state = $this->getState();
87
-                array_pop($this->stack);
88
-                $this->stack[] = !$state;
89
-                break;
90
-
91
-            case 'elif':
92
-                $name = self::wordShift($expression);
93
-                $state = $this->getState();
94
-                array_pop($this->stack);
95
-                if (empty($expression)) {
96
-                    $this->stack[] = !$state && !empty($this->defines[$name]);
97
-                } else {
98
-                    $this->stack[] = !$state && isset($this->defines[$name]) && $this->defines[$name] == $expression;
99
-                }
100
-                break;
101
-
102
-            case 'define':
103
-                $name = self::wordShift($expression);
104
-                $this->defines[$name] = $expression;
105
-                break;
106
-
107
-            case 'undef':
108
-                unset($this->defines[$expression]);
109
-                break;
110
-
111
-            case 'endif':
112
-                array_pop($this->stack);
113
-                break;
114
-
115
-            default:
116
-                return false;
117
-        }
118
-
119
-        return true;
120
-    }
121
-
122
-    public function preprocess($content)
123
-    {
124
-        $this->stack = array();
125
-
126
-        return $this->parseContent($content);
127
-    }
128
-
129
-    public function preprocessFile($filename)
130
-    {
131
-        return $this->preprocess(file_get_contents($filename));
132
-    }
133
-
134
-    abstract protected function parseContent($content);
16
+	private $defines = array();
17
+	private $stack = array();
18
+
19
+	public function __construct()
20
+	{
21
+		$this->resetDefines();
22
+	}
23
+
24
+	public function resetDefines()
25
+	{
26
+		$this->defines = array();
27
+	}
28
+
29
+	public function addDefines(array $defines)
30
+	{
31
+		$this->defines = array_merge($this->defines, $defines);
32
+	}
33
+
34
+	public function define($name, $value = 1)
35
+	{
36
+		$this->defines[$name] = $value;
37
+	}
38
+
39
+	public function undefine($name)
40
+	{
41
+		unset($this->defines[$name]);
42
+	}
43
+
44
+	protected function getState()
45
+	{
46
+		return empty($this->stack) || end($this->stack);
47
+	}
48
+
49
+	/**
50
+	 * Get the first word from a string and remove it from the string.
51
+	 *
52
+	 * @param string $data
53
+	 * @return boolean|string
54
+	 */
55
+	private static function wordShift(&$data)
56
+	{
57
+		if (preg_match('~^(\S+)\s*(.*)$~', $data, $matches) === 1) {
58
+			$data = $matches[2];
59
+			return $matches[1];
60
+		}
61
+		return false;
62
+	}
63
+
64
+	protected function handle($command, $expression)
65
+	{
66
+		switch (strtolower($command)) {
67
+			case 'if':
68
+				$name = self::wordShift($expression);
69
+				$state = $this->getState();
70
+				if (empty($expression)) {
71
+					$this->stack[] = $state && !empty($this->defines[$name]);
72
+				} else {
73
+					$this->stack[] = $state && isset($this->defines[$name]) && $this->defines[$name] == $expression;
74
+				}
75
+				break;
76
+
77
+			case 'ifdef':
78
+				$this->stack[] = $this->getState() && isset($this->defines[$expression]);
79
+				break;
80
+
81
+			case 'ifndef':
82
+				$this->stack[] = $this->getState() && !isset($this->defines[$expression]);
83
+				break;
84
+
85
+			case 'else':
86
+				$state = $this->getState();
87
+				array_pop($this->stack);
88
+				$this->stack[] = !$state;
89
+				break;
90
+
91
+			case 'elif':
92
+				$name = self::wordShift($expression);
93
+				$state = $this->getState();
94
+				array_pop($this->stack);
95
+				if (empty($expression)) {
96
+					$this->stack[] = !$state && !empty($this->defines[$name]);
97
+				} else {
98
+					$this->stack[] = !$state && isset($this->defines[$name]) && $this->defines[$name] == $expression;
99
+				}
100
+				break;
101
+
102
+			case 'define':
103
+				$name = self::wordShift($expression);
104
+				$this->defines[$name] = $expression;
105
+				break;
106
+
107
+			case 'undef':
108
+				unset($this->defines[$expression]);
109
+				break;
110
+
111
+			case 'endif':
112
+				array_pop($this->stack);
113
+				break;
114
+
115
+			default:
116
+				return false;
117
+		}
118
+
119
+		return true;
120
+	}
121
+
122
+	public function preprocess($content)
123
+	{
124
+		$this->stack = array();
125
+
126
+		return $this->parseContent($content);
127
+	}
128
+
129
+	public function preprocessFile($filename)
130
+	{
131
+		return $this->preprocess(file_get_contents($filename));
132
+	}
133
+
134
+	abstract protected function parseContent($content);
135 135
 }
Please login to merge, or discard this patch.
SwaggerGen/Parser/Php/Preprocessor.php 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -18,72 +18,72 @@
 block discarded – undo
18 18
 class Preprocessor extends AbstractPreprocessor
19 19
 {
20 20
 
21
-    private $prefix = 'rest';
21
+	private $prefix = 'rest';
22 22
 
23
-    public function __construct($prefix = null)
24
-    {
25
-        parent::__construct();
26
-        if (!empty($prefix)) {
27
-            $this->prefix = $prefix;
28
-        }
29
-    }
23
+	public function __construct($prefix = null)
24
+	{
25
+		parent::__construct();
26
+		if (!empty($prefix)) {
27
+			$this->prefix = $prefix;
28
+		}
29
+	}
30 30
 
31
-    public function getPrefix()
32
-    {
33
-        return $this->prefix;
34
-    }
31
+	public function getPrefix()
32
+	{
33
+		return $this->prefix;
34
+	}
35 35
 
36
-    public function setPrefix($prefix)
37
-    {
38
-        $this->prefix = $prefix;
39
-    }
36
+	public function setPrefix($prefix)
37
+	{
38
+		$this->prefix = $prefix;
39
+	}
40 40
 
41
-    protected function parseContent($content)
42
-    {
43
-        $pattern = '/@' . preg_quote($this->getPrefix()) . '\\\\([a-z]+)\\s*(.*)$/';
41
+	protected function parseContent($content)
42
+	{
43
+		$pattern = '/@' . preg_quote($this->getPrefix()) . '\\\\([a-z]+)\\s*(.*)$/';
44 44
 
45
-        $output_file = '';
45
+		$output_file = '';
46 46
 
47
-        foreach (token_get_all($content) as $token) {
48
-            $output = '';
47
+		foreach (token_get_all($content) as $token) {
48
+			$output = '';
49 49
 
50
-            if (is_array($token)) {
51
-                switch ($token[0]) {
52
-                    case T_DOC_COMMENT:
53
-                    case T_COMMENT:
54
-                        foreach (preg_split('/(\\R)/m', $token[1], -1, PREG_SPLIT_DELIM_CAPTURE) as $index => $line) {
55
-                            if ($index % 2) {
56
-                                $output .= $line;
57
-                            } else {
58
-                                $match = array();
59
-                                if (preg_match($pattern, $line, $match) === 1) {
60
-                                    if (!$this->handle($match[1], $match[2]) && $this->getState()) {
61
-                                        $output .= $line;
62
-                                    } else {
63
-                                        $output .= str_replace('@' . $this->getPrefix() . '\\', '@!' . $this->getPrefix() . '\\', $line);
64
-                                    }
65
-                                } else {
66
-                                    $output .= $line;
67
-                                }
68
-                            }
69
-                        }
70
-                        break;
50
+			if (is_array($token)) {
51
+				switch ($token[0]) {
52
+					case T_DOC_COMMENT:
53
+					case T_COMMENT:
54
+						foreach (preg_split('/(\\R)/m', $token[1], -1, PREG_SPLIT_DELIM_CAPTURE) as $index => $line) {
55
+							if ($index % 2) {
56
+								$output .= $line;
57
+							} else {
58
+								$match = array();
59
+								if (preg_match($pattern, $line, $match) === 1) {
60
+									if (!$this->handle($match[1], $match[2]) && $this->getState()) {
61
+										$output .= $line;
62
+									} else {
63
+										$output .= str_replace('@' . $this->getPrefix() . '\\', '@!' . $this->getPrefix() . '\\', $line);
64
+									}
65
+								} else {
66
+									$output .= $line;
67
+								}
68
+							}
69
+						}
70
+						break;
71 71
 
72
-                    default:
73
-                        $output .= $token[1];
74
-                }
75
-            } else {
76
-                $output .= $token;
77
-            }
72
+					default:
73
+						$output .= $token[1];
74
+				}
75
+			} else {
76
+				$output .= $token;
77
+			}
78 78
 
79
-            if ($this->getState()) {
80
-                $output_file .= $output;
81
-            } else {
82
-                $output_file .= '/* ' . $output . ' */';
83
-            }
84
-        }
79
+			if ($this->getState()) {
80
+				$output_file .= $output;
81
+			} else {
82
+				$output_file .= '/* ' . $output . ' */';
83
+			}
84
+		}
85 85
 
86
-        return $output_file;
87
-    }
86
+		return $output_file;
87
+	}
88 88
 
89 89
 }
Please login to merge, or discard this patch.
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 = array();
27
-
28
-    /**
29
-     * @var string
30
-     */
31
-    public $extends = null;
32
-
33
-    /**
34
-     * @var string[]
35
-     */
36
-    public $implements = array();
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 = array();
27
+
28
+	/**
29
+	 * @var string
30
+	 */
31
+	public $extends = null;
32
+
33
+	/**
34
+	 * @var string[]
35
+	 */
36
+	public $implements = array();
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/Php/Entity/AbstractEntity.php 1 patch
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -15,30 +15,30 @@
 block discarded – undo
15 15
 class AbstractEntity
16 16
 {
17 17
 
18
-    /**
19
-     * @var Statement[]
20
-     */
21
-    public $Statements = array();
22
-
23
-    /**
24
-     * Returns true if a statement with the specified command exists.
25
-     * @param string $command
26
-     * @return boolean
27
-     */
28
-    public function hasCommand($command)
29
-    {
30
-        foreach ($this->Statements as $Statement) {
31
-            if ($Statement->getCommand() === $command) {
32
-                return true;
33
-            }
34
-        }
35
-
36
-        return false;
37
-    }
38
-
39
-    public function getStatements()
40
-    {
41
-        return $this->Statements;
42
-    }
18
+	/**
19
+	 * @var Statement[]
20
+	 */
21
+	public $Statements = array();
22
+
23
+	/**
24
+	 * Returns true if a statement with the specified command exists.
25
+	 * @param string $command
26
+	 * @return boolean
27
+	 */
28
+	public function hasCommand($command)
29
+	{
30
+		foreach ($this->Statements as $Statement) {
31
+			if ($Statement->getCommand() === $command) {
32
+				return true;
33
+			}
34
+		}
35
+
36
+		return false;
37
+	}
38
+
39
+	public function getStatements()
40
+	{
41
+		return $this->Statements;
42
+	}
43 43
 
44 44
 }
Please login to merge, or discard this patch.
SwaggerGen/Parser/Php/Entity/ParserFunction.php 1 patch
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -16,77 +16,77 @@
 block discarded – undo
16 16
 class ParserFunction extends AbstractEntity
17 17
 {
18 18
 
19
-    public $name = null;
20
-    private $lastStatements = null;
19
+	public $name = null;
20
+	private $lastStatements = null;
21 21
 
22
-    public function __construct(Parser $Parser, &$tokens, $Statements)
23
-    {
24
-        if ($Statements) {
25
-            $this->Statements = array_merge($this->Statements, $Statements);
26
-        }
22
+	public function __construct(Parser $Parser, &$tokens, $Statements)
23
+	{
24
+		if ($Statements) {
25
+			$this->Statements = array_merge($this->Statements, $Statements);
26
+		}
27 27
 
28
-        $depth = 0;
28
+		$depth = 0;
29 29
 
30
-        $token = current($tokens);
31
-        while ($token) {
32
-            switch ($token[0]) {
33
-                case T_STRING:
34
-                    if (empty($this->name)) {
35
-                        $this->name = $token[1];
36
-                    }
37
-                    break;
30
+		$token = current($tokens);
31
+		while ($token) {
32
+			switch ($token[0]) {
33
+				case T_STRING:
34
+					if (empty($this->name)) {
35
+						$this->name = $token[1];
36
+					}
37
+					break;
38 38
 
39
-                case '{':
40
-                case T_CURLY_OPEN:
41
-                case T_DOLLAR_OPEN_CURLY_BRACES:
42
-                case T_STRING_VARNAME:
43
-                    ++$depth;
44
-                    break;
39
+				case '{':
40
+				case T_CURLY_OPEN:
41
+				case T_DOLLAR_OPEN_CURLY_BRACES:
42
+				case T_STRING_VARNAME:
43
+					++$depth;
44
+					break;
45 45
 
46
-                case '}':
47
-                    --$depth;
48
-                    if ($depth == 0) {
49
-                        if ($this->lastStatements) {
50
-                            $this->Statements = array_merge($this->Statements, $this->lastStatements);
51
-                            $this->lastStatements = null;
52
-                        }
53
-                        return;
54
-                    }
55
-                    break;
46
+				case '}':
47
+					--$depth;
48
+					if ($depth == 0) {
49
+						if ($this->lastStatements) {
50
+							$this->Statements = array_merge($this->Statements, $this->lastStatements);
51
+							$this->lastStatements = null;
52
+						}
53
+						return;
54
+					}
55
+					break;
56 56
 
57
-                case T_COMMENT:
58
-                    if ($this->lastStatements) {
59
-                        $this->Statements = array_merge($this->Statements, $this->lastStatements);
60
-                        $this->lastStatements = null;
61
-                    }
62
-                    $Statements = $Parser->tokenToStatements($token);
63
-                    $Parser->queueClassesFromComments($Statements);
64
-                    $this->Statements = array_merge($this->Statements, $Statements);
65
-                    break;
57
+				case T_COMMENT:
58
+					if ($this->lastStatements) {
59
+						$this->Statements = array_merge($this->Statements, $this->lastStatements);
60
+						$this->lastStatements = null;
61
+					}
62
+					$Statements = $Parser->tokenToStatements($token);
63
+					$Parser->queueClassesFromComments($Statements);
64
+					$this->Statements = array_merge($this->Statements, $Statements);
65
+					break;
66 66
 
67
-                case T_DOC_COMMENT:
68
-                    if ($this->lastStatements) {
69
-                        $this->Statements = array_merge($this->Statements, $this->lastStatements);
70
-                    }
71
-                    $Statements = $Parser->tokenToStatements($token);
72
-                    $Parser->queueClassesFromComments($Statements);
73
-                    $this->lastStatements = $Statements;
74
-                    break;
75
-            }
67
+				case T_DOC_COMMENT:
68
+					if ($this->lastStatements) {
69
+						$this->Statements = array_merge($this->Statements, $this->lastStatements);
70
+					}
71
+					$Statements = $Parser->tokenToStatements($token);
72
+					$Parser->queueClassesFromComments($Statements);
73
+					$this->lastStatements = $Statements;
74
+					break;
75
+			}
76 76
 
77
-            $token = next($tokens);
78
-        }
77
+			$token = next($tokens);
78
+		}
79 79
 
80
-        if ($this->lastStatements) {
81
-            $this->Statements = array_merge($this->Statements, $this->lastStatements);
82
-            $this->lastStatements = null;
83
-        }
84
-    }
80
+		if ($this->lastStatements) {
81
+			$this->Statements = array_merge($this->Statements, $this->lastStatements);
82
+			$this->lastStatements = null;
83
+		}
84
+	}
85 85
 
86
-    public function getStatements()
87
-    {
88
-        // inherit
89
-        return $this->Statements;
90
-    }
86
+	public function getStatements()
87
+	{
88
+		// inherit
89
+		return $this->Statements;
90
+	}
91 91
 
92 92
 }
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 = array());
16
+	public function parse($file, array $dirs = array());
17 17
 }
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 = array();
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 = array();
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.