Completed
Push — master ( 2f1531...a6cc58 )
by Martijn
17s
created
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.
SwaggerGen/Parser/Text/Parser.php 1 patch
Indentation   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -17,99 +17,99 @@
 block discarded – undo
17 17
 class Parser implements IParser
18 18
 {
19 19
 
20
-    /**
21
-     * List of directories to scan for class files referenced in the parsed
22
-     * command statements.
23
-     *
24
-     * @var string[]
25
-     */
26
-    protected $common_dirs = [];
20
+	/**
21
+	 * List of directories to scan for class files referenced in the parsed
22
+	 * command statements.
23
+	 *
24
+	 * @var string[]
25
+	 */
26
+	protected $common_dirs = [];
27 27
 
28
-    /**
29
-     * @var AbstractPreprocessor
30
-     */
31
-    private $Preprocessor;
28
+	/**
29
+	 * @var AbstractPreprocessor
30
+	 */
31
+	private $Preprocessor;
32 32
 
33
-    /**
34
-     * Create a new text parser and set directories to scan for referenced
35
-     * class files.
36
-     *
37
-     * @param string[] $dirs
38
-     */
39
-    public function __construct(array $dirs = [])
40
-    {
41
-        foreach ($dirs as $dir) {
42
-            $this->common_dirs[] = realpath($dir);
43
-        }
33
+	/**
34
+	 * Create a new text parser and set directories to scan for referenced
35
+	 * class files.
36
+	 *
37
+	 * @param string[] $dirs
38
+	 */
39
+	public function __construct(array $dirs = [])
40
+	{
41
+		foreach ($dirs as $dir) {
42
+			$this->common_dirs[] = realpath($dir);
43
+		}
44 44
 
45
-        $this->Preprocessor = new Preprocessor();
46
-    }
45
+		$this->Preprocessor = new Preprocessor();
46
+	}
47 47
 
48
-    /**
49
-     * Add additional directories to scan for referenced class files.
50
-     *
51
-     * @param string[] $dirs
52
-     */
53
-    public function addDirs(array $dirs)
54
-    {
55
-        foreach ($dirs as $dir) {
56
-            $this->common_dirs[] = realpath($dir);
57
-        }
58
-    }
48
+	/**
49
+	 * Add additional directories to scan for referenced class files.
50
+	 *
51
+	 * @param string[] $dirs
52
+	 */
53
+	public function addDirs(array $dirs)
54
+	{
55
+		foreach ($dirs as $dir) {
56
+			$this->common_dirs[] = realpath($dir);
57
+		}
58
+	}
59 59
 
60
-    /**
61
-     * Parse a text file
62
-     *
63
-     * @param string $file
64
-     * @param string[] $dirs
65
-     * @param string[] $defines
66
-     * @return Statement[]
67
-     */
68
-    public function parse($file, array $dirs = [], array $defines = [])
69
-    {
70
-        return $this->parseText(file_get_contents(realpath($file)), $dirs);
71
-    }
60
+	/**
61
+	 * Parse a text file
62
+	 *
63
+	 * @param string $file
64
+	 * @param string[] $dirs
65
+	 * @param string[] $defines
66
+	 * @return Statement[]
67
+	 */
68
+	public function parse($file, array $dirs = [], array $defines = [])
69
+	{
70
+		return $this->parseText(file_get_contents(realpath($file)), $dirs);
71
+	}
72 72
 
73
-    /**
74
-     * Parse plain text
75
-     *
76
-     * @param string $text
77
-     * @param string[] $dirs
78
-     * @param string[] $defines
79
-     * @return Statement[]
80
-     */
81
-    public function parseText($text, array $dirs = [], array $defines = []): array
82
-    {
83
-        $this->Preprocessor->resetDefines();
84
-        $this->Preprocessor->addDefines($defines);
85
-        $text = $this->Preprocessor->preprocess($text);
73
+	/**
74
+	 * Parse plain text
75
+	 *
76
+	 * @param string $text
77
+	 * @param string[] $dirs
78
+	 * @param string[] $defines
79
+	 * @return Statement[]
80
+	 */
81
+	public function parseText($text, array $dirs = [], array $defines = []): array
82
+	{
83
+		$this->Preprocessor->resetDefines();
84
+		$this->Preprocessor->addDefines($defines);
85
+		$text = $this->Preprocessor->preprocess($text);
86 86
 
87
-        $Statements = [];
87
+		$Statements = [];
88 88
 
89
-        foreach (preg_split('/\\R/m', $text) as $line => $data) {
90
-            $data = trim($data);
91
-            $command = self::wordShift($data);
92
-            if (!empty($command)) {
93
-                $Statements[] = new Statement($command, $data, null, $line);
94
-            }
95
-        }
89
+		foreach (preg_split('/\\R/m', $text) as $line => $data) {
90
+			$data = trim($data);
91
+			$command = self::wordShift($data);
92
+			if (!empty($command)) {
93
+				$Statements[] = new Statement($command, $data, null, $line);
94
+			}
95
+		}
96 96
 
97
-        return $Statements;
98
-    }
97
+		return $Statements;
98
+	}
99 99
 
100
-    /**
101
-     * Get the first word from a string and remove it from the string.
102
-     *
103
-     * @param string $data
104
-     * @return boolean|string
105
-     */
106
-    private static function wordShift(&$data)
107
-    {
108
-        if (preg_match('~^(\S+)\s*(.*)$~', $data, $matches) === 1) {
109
-            $data = $matches[2];
110
-            return $matches[1];
111
-        }
112
-        return false;
113
-    }
100
+	/**
101
+	 * Get the first word from a string and remove it from the string.
102
+	 *
103
+	 * @param string $data
104
+	 * @return boolean|string
105
+	 */
106
+	private static function wordShift(&$data)
107
+	{
108
+		if (preg_match('~^(\S+)\s*(.*)$~', $data, $matches) === 1) {
109
+			$data = $matches[2];
110
+			return $matches[1];
111
+		}
112
+		return false;
113
+	}
114 114
 
115 115
 }
Please login to merge, or discard this patch.
SwaggerGen/TypeRegistry.php 2 patches
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -15,55 +15,55 @@
 block discarded – undo
15 15
 class TypeRegistry
16 16
 {
17 17
 
18
-    /**
19
-     * Map of format-name => class-name
20
-     *
21
-     * @var array
22
-     */
23
-    private $formats = array();
18
+	/**
19
+	 * Map of format-name => class-name
20
+	 *
21
+	 * @var array
22
+	 */
23
+	private $formats = array();
24 24
 
25
-    /**
26
-     * Add a type name from classname
27
-     *
28
-     * @param string $classname
29
-     */
30
-    public function add(string $classname): void
31
-    {
32
-        if (is_subclass_of($classname, ICustomType::class)) {
33
-            foreach ($classname::getFormats() as $format) {
34
-                $this->formats[$format] = $classname;
35
-            }
36
-        }
37
-    }
25
+	/**
26
+	 * Add a type name from classname
27
+	 *
28
+	 * @param string $classname
29
+	 */
30
+	public function add(string $classname): void
31
+	{
32
+		if (is_subclass_of($classname, ICustomType::class)) {
33
+			foreach ($classname::getFormats() as $format) {
34
+				$this->formats[$format] = $classname;
35
+			}
36
+		}
37
+	}
38 38
 
39
-    /**
40
-     * Remove type format by explicitly nulling it (disables it)
41
-     *
42
-     * @param string $name
43
-     */
44
-    public function remove($name)
45
-    {
46
-        $this->formats[$name] = null;
47
-    }
39
+	/**
40
+	 * Remove type format by explicitly nulling it (disables it)
41
+	 *
42
+	 * @param string $name
43
+	 */
44
+	public function remove($name)
45
+	{
46
+		$this->formats[$name] = null;
47
+	}
48 48
 
49
-    /**
50
-     * Is a type format known?
51
-     *
52
-     * @return bool
53
-     */
54
-    public function has($name)
55
-    {
56
-        return !empty($this->formats[$name]);
57
-    }
49
+	/**
50
+	 * Is a type format known?
51
+	 *
52
+	 * @return bool
53
+	 */
54
+	public function has($name)
55
+	{
56
+		return !empty($this->formats[$name]);
57
+	}
58 58
 
59
-    /**
60
-     * Get the format class name
61
-     *
62
-     * @return null|string
63
-     */
64
-    public function get($name)
65
-    {
66
-        return !empty($this->formats[$name]) ? $this->formats[$name] : null;
67
-    }
59
+	/**
60
+	 * Get the format class name
61
+	 *
62
+	 * @return null|string
63
+	 */
64
+	public function get($name)
65
+	{
66
+		return !empty($this->formats[$name]) ? $this->formats[$name] : null;
67
+	}
68 68
 
69 69
 }
Please login to merge, or discard this patch.
Braces   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -12,8 +12,8 @@  discard block
 block discarded – undo
12 12
  * @copyright  2014-2017 Martijn van der Lee
13 13
  * @license    https://opensource.org/licenses/MIT MIT
14 14
  */
15
-class TypeRegistry
16
-{
15
+class TypeRegistry
16
+{
17 17
 
18 18
     /**
19 19
      * Map of format-name => class-name
@@ -29,8 +29,8 @@  discard block
 block discarded – undo
29 29
      */
30 30
     public function add(string $classname): void
31 31
     {
32
-        if (is_subclass_of($classname, ICustomType::class)) {
33
-            foreach ($classname::getFormats() as $format) {
32
+        if (is_subclass_of($classname, ICustomType::class)) {
33
+            foreach ($classname::getFormats() as $format) {
34 34
                 $this->formats[$format] = $classname;
35 35
             }
36 36
         }
@@ -41,8 +41,8 @@  discard block
 block discarded – undo
41 41
      *
42 42
      * @param string $name
43 43
      */
44
-    public function remove($name)
45
-    {
44
+    public function remove($name)
45
+    {
46 46
         $this->formats[$name] = null;
47 47
     }
48 48
 
@@ -51,8 +51,8 @@  discard block
 block discarded – undo
51 51
      *
52 52
      * @return bool
53 53
      */
54
-    public function has($name)
55
-    {
54
+    public function has($name)
55
+    {
56 56
         return !empty($this->formats[$name]);
57 57
     }
58 58
 
@@ -61,8 +61,8 @@  discard block
 block discarded – undo
61 61
      *
62 62
      * @return null|string
63 63
      */
64
-    public function get($name)
65
-    {
64
+    public function get($name)
65
+    {
66 66
         return !empty($this->formats[$name]) ? $this->formats[$name] : null;
67 67
     }
68 68
 
Please login to merge, or discard this patch.
tests/Base/PHPUnit7.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -2,11 +2,11 @@
 block discarded – undo
2 2
 
3 3
 class Base_PHPUnit7 extends PHPUnit\Framework\TestCase
4 4
 {
5
-    public function expectException(string $exception, string $message = ''): void
6
-    {
7
-        parent::expectException($exception);
8
-        if ($message !== '') {
9
-            parent::expectExceptionMessage($message);
10
-        }
11
-    }
5
+	public function expectException(string $exception, string $message = ''): void
6
+	{
7
+		parent::expectException($exception);
8
+		if ($message !== '') {
9
+			parent::expectExceptionMessage($message);
10
+		}
11
+	}
12 12
 }
Please login to merge, or discard this patch.
tests/Base/PHPUnit5.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -2,13 +2,13 @@
 block discarded – undo
2 2
 
3 3
 class Base_PHPUnit5 extends PHPUnit_Framework_TestCase
4 4
 {
5
-    /**
6
-     * @param string $exception
7
-     * @param string $message
8
-     * @return void
9
-     */
10
-    public function expectException($exception, $message = '')
11
-    {
12
-        parent::setExpectedException($exception, $message);
13
-    }
5
+	/**
6
+	 * @param string $exception
7
+	 * @param string $message
8
+	 * @return void
9
+	 */
10
+	public function expectException($exception, $message = '')
11
+	{
12
+		parent::setExpectedException($exception, $message);
13
+	}
14 14
 }
Please login to merge, or discard this patch.
tests/Base/PHPUnit6.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -2,16 +2,16 @@
 block discarded – undo
2 2
 
3 3
 class Base_PHPUnit6 extends PHPUnit\Framework\TestCase
4 4
 {
5
-    /**
6
-     * @param string $exception
7
-     * @param string $message
8
-     * @return void
9
-     */
10
-    public function expectException($exception, $message = '')
11
-    {
12
-        parent::expectException($exception);
13
-        if ($message !== '') {
14
-            parent::expectExceptionMessage($message);
15
-        }
16
-    }
5
+	/**
6
+	 * @param string $exception
7
+	 * @param string $message
8
+	 * @return void
9
+	 */
10
+	public function expectException($exception, $message = '')
11
+	{
12
+		parent::expectException($exception);
13
+		if ($message !== '') {
14
+			parent::expectExceptionMessage($message);
15
+		}
16
+	}
17 17
 }
Please login to merge, or discard this patch.
tests/StatementTest.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -3,29 +3,29 @@
 block discarded – undo
3 3
 class StatementTest extends SwaggerGen_TestCase
4 4
 {
5 5
 
6
-    /**
7
-     * @covers \SwaggerGen\Statement::__construct
8
-     */
9
-    public function testConstructor()
10
-    {
11
-        $object = new \SwaggerGen\Statement('command', 'some data');
6
+	/**
7
+	 * @covers \SwaggerGen\Statement::__construct
8
+	 */
9
+	public function testConstructor()
10
+	{
11
+		$object = new \SwaggerGen\Statement('command', 'some data');
12 12
 
13
-        $this->assertInstanceOf('\SwaggerGen\Statement', $object);
14
-        $this->assertSame('command', $object->getCommand());
15
-        $this->assertSame('some data', $object->getData());
16
-    }
13
+		$this->assertInstanceOf('\SwaggerGen\Statement', $object);
14
+		$this->assertSame('command', $object->getCommand());
15
+		$this->assertSame('some data', $object->getData());
16
+	}
17 17
 
18
-    /**
19
-     * @covers \SwaggerGen\Statement::__construct
20
-     */
21
-    public function testConstructor_File()
22
-    {
23
-        $object = new \SwaggerGen\Statement('command', 'some data', 'file', 123);
24
-        $this->assertInstanceOf('\SwaggerGen\Statement', $object);
18
+	/**
19
+	 * @covers \SwaggerGen\Statement::__construct
20
+	 */
21
+	public function testConstructor_File()
22
+	{
23
+		$object = new \SwaggerGen\Statement('command', 'some data', 'file', 123);
24
+		$this->assertInstanceOf('\SwaggerGen\Statement', $object);
25 25
 
26
-        $this->assertSame('command', $object->getCommand());
27
-        $this->assertSame('some data', $object->getData());
28
-        $this->assertSame('file', $object->getFile());
29
-        $this->assertSame(123, $object->getLine());
30
-    }
26
+		$this->assertSame('command', $object->getCommand());
27
+		$this->assertSame('some data', $object->getData());
28
+		$this->assertSame('file', $object->getFile());
29
+		$this->assertSame(123, $object->getLine());
30
+	}
31 31
 }
Please login to merge, or discard this patch.
tests/bootstrap.php 2 patches
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -1,10 +1,10 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 spl_autoload_register(function ($classname) {
4
-    $file = dirname(__DIR__) . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $classname) . '.php';
5
-    if (is_file($file)) {
6
-        require_once $file;
7
-    }
4
+	$file = dirname(__DIR__) . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $classname) . '.php';
5
+	if (is_file($file)) {
6
+		require_once $file;
7
+	}
8 8
 });
9 9
 
10 10
 
@@ -16,20 +16,20 @@  discard block
 block discarded – undo
16 16
 // inbetween there was `expectException()` without type hint
17 17
 
18 18
 if (class_exists('PHPUnit\Runner\Version')) {
19
-    $version = PHPUnit\Runner\Version::id();
19
+	$version = PHPUnit\Runner\Version::id();
20 20
 } else if (class_exists('PHPUnit_Runner_Version')) {
21
-    $version = PHPUnit_Runner_Version::id();
21
+	$version = PHPUnit_Runner_Version::id();
22 22
 } else {
23
-    throw new Exception('Cannot detect PHPUnit version');
23
+	throw new Exception('Cannot detect PHPUnit version');
24 24
 }
25 25
 
26 26
 if (version_compare($version, '7.0.0', '>=')) {
27
-    require dirname(__FILE__) . '/Base/PHPUnit7.php';
28
-    class_alias('Base_PHPUnit7', 'SwaggerGen_TestCase');
27
+	require dirname(__FILE__) . '/Base/PHPUnit7.php';
28
+	class_alias('Base_PHPUnit7', 'SwaggerGen_TestCase');
29 29
 } else if (version_compare($version, '6.0.0', '>=')) {
30
-    require dirname(__FILE__) . '/Base/PHPUnit6.php';
31
-    class_alias('Base_PHPUnit6', 'SwaggerGen_TestCase');
30
+	require dirname(__FILE__) . '/Base/PHPUnit6.php';
31
+	class_alias('Base_PHPUnit6', 'SwaggerGen_TestCase');
32 32
 } else {
33
-    require dirname(__FILE__) . '/Base/PHPUnit5.php';
34
-    class_alias('Base_PHPUnit5', 'SwaggerGen_TestCase');
33
+	require dirname(__FILE__) . '/Base/PHPUnit5.php';
34
+	class_alias('Base_PHPUnit5', 'SwaggerGen_TestCase');
35 35
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-spl_autoload_register(function ($classname) {
3
+spl_autoload_register(function($classname) {
4 4
     $file = dirname(__DIR__) . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $classname) . '.php';
5 5
     if (is_file($file)) {
6 6
         require_once $file;
Please login to merge, or discard this patch.
tests/output/OutputTest.php 1 patch
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -3,57 +3,57 @@
 block discarded – undo
3 3
 class OutputTest extends SwaggerGen_TestCase
4 4
 {
5 5
 
6
-    /**
7
-     * @covers       \SwaggerGen\Exception::__construct
8
-     * @dataProvider provideAllCases
9
-     */
10
-    public function testAllCases($name, $files, $expected)
11
-    {
12
-        $SwaggerGen = new \SwaggerGen\SwaggerGen('example.com', '/base');
13
-        $actual = $SwaggerGen->getSwagger($files, array(), \SwaggerGen\SwaggerGen::FORMAT_JSON);
14
-        $this->assertJsonStringEqualsJsonString($expected, $this->normalizeJson($actual), $name);
15
-    }
16
-
17
-    /**
18
-     * Normalizes and pretty-prints json (whitespace mostly)
19
-     *
20
-     * This is useful to get better diff results when assertions fail.
21
-     *
22
-     * @param string $json
23
-     * @return string
24
-     */
25
-    private function normalizeJson($json)
26
-    {
27
-        return json_encode(
28
-            json_decode($json),
29
-            PHP_VERSION_ID >= 50400 ? constant('JSON_PRETTY_PRINT') : 0
30
-        );
31
-    }
32
-
33
-    public function provideAllCases()
34
-    {
35
-        $cases = array();
36
-
37
-        foreach (glob(__DIR__ . '/*', GLOB_ONLYDIR) as $dir) {
38
-            $path = realpath($dir);
39
-            $json = $this->normalizeJson(file_get_contents($path . '/expected.json'));
40
-
41
-            $files = array();
42
-            if (file_exists($path . '/source.php')) {
43
-                $files[] = $path . '/source.php';
44
-            }
45
-            if (file_exists($path . '/source.txt')) {
46
-                $files[] = $path . '/source.txt';
47
-            }
48
-
49
-            $cases[] = array(
50
-                basename($dir),
51
-                $files,
52
-                $json
53
-            );
54
-        }
55
-
56
-        return $cases;
57
-    }
6
+	/**
7
+	 * @covers       \SwaggerGen\Exception::__construct
8
+	 * @dataProvider provideAllCases
9
+	 */
10
+	public function testAllCases($name, $files, $expected)
11
+	{
12
+		$SwaggerGen = new \SwaggerGen\SwaggerGen('example.com', '/base');
13
+		$actual = $SwaggerGen->getSwagger($files, array(), \SwaggerGen\SwaggerGen::FORMAT_JSON);
14
+		$this->assertJsonStringEqualsJsonString($expected, $this->normalizeJson($actual), $name);
15
+	}
16
+
17
+	/**
18
+	 * Normalizes and pretty-prints json (whitespace mostly)
19
+	 *
20
+	 * This is useful to get better diff results when assertions fail.
21
+	 *
22
+	 * @param string $json
23
+	 * @return string
24
+	 */
25
+	private function normalizeJson($json)
26
+	{
27
+		return json_encode(
28
+			json_decode($json),
29
+			PHP_VERSION_ID >= 50400 ? constant('JSON_PRETTY_PRINT') : 0
30
+		);
31
+	}
32
+
33
+	public function provideAllCases()
34
+	{
35
+		$cases = array();
36
+
37
+		foreach (glob(__DIR__ . '/*', GLOB_ONLYDIR) as $dir) {
38
+			$path = realpath($dir);
39
+			$json = $this->normalizeJson(file_get_contents($path . '/expected.json'));
40
+
41
+			$files = array();
42
+			if (file_exists($path . '/source.php')) {
43
+				$files[] = $path . '/source.php';
44
+			}
45
+			if (file_exists($path . '/source.txt')) {
46
+				$files[] = $path . '/source.txt';
47
+			}
48
+
49
+			$cases[] = array(
50
+				basename($dir),
51
+				$files,
52
+				$json
53
+			);
54
+		}
55
+
56
+		return $cases;
57
+	}
58 58
 
59 59
 }
Please login to merge, or discard this patch.