Passed
Branch master (bce341)
by Aleksandr
03:04
created
src/RequestAbstract.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -6,23 +6,23 @@
 block discarded – undo
6 6
 
7 7
 abstract class RequestAbstract
8 8
 {
9
-    protected $_client;
9
+	protected $_client;
10 10
 
11
-    /**
12
-     * RequestAbstract constructor.
13
-     *
14
-     * @param Client|ClientAbstract $client
15
-     */
16
-    public function __construct($client)
17
-    {
18
-        $this->_client = $client;
19
-    }
11
+	/**
12
+	 * RequestAbstract constructor.
13
+	 *
14
+	 * @param Client|ClientAbstract $client
15
+	 */
16
+	public function __construct($client)
17
+	{
18
+		$this->_client = $client;
19
+	}
20 20
 
21
-    /**
22
-     * @return Client
23
-     */
24
-    public function getClient()
25
-    {
26
-        return $this->_client;
27
-    }
21
+	/**
22
+	 * @return Client
23
+	 */
24
+	public function getClient()
25
+	{
26
+		return $this->_client;
27
+	}
28 28
 }
29 29
\ No newline at end of file
Please login to merge, or discard this patch.
codegen/generate.php 1 patch
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -17,10 +17,10 @@  discard block
 block discarded – undo
17 17
 
18 18
 $apidoc = 'apidoc.html';
19 19
 if (file_exists($apidoc)) {
20
-    $content = file_get_contents($apidoc);
20
+	$content = file_get_contents($apidoc);
21 21
 } else {
22
-    $content = (new Client())->get('https://www.etxt.ru/api/')->getBody()->getContents();
23
-    file_put_contents($apidoc, $content);
22
+	$content = (new Client())->get('https://www.etxt.ru/api/')->getBody()->getContents();
23
+	file_put_contents($apidoc, $content);
24 24
 }
25 25
 
26 26
 
@@ -28,54 +28,54 @@  discard block
 block discarded – undo
28 28
 $data = [];
29 29
 
30 30
 foreach ($query->find('h4') as $title) {
31
-    $name = pq($title)->text();
32
-    if (strpos($name, '.') === false) {
33
-        continue;
34
-    }
35
-    echo $name . "\n";
36
-    $description = $query->find("td:contains('$name')")->next('td')->text();
37
-    list($api, $method) = explode('.', $name);
31
+	$name = pq($title)->text();
32
+	if (strpos($name, '.') === false) {
33
+		continue;
34
+	}
35
+	echo $name . "\n";
36
+	$description = $query->find("td:contains('$name')")->next('td')->text();
37
+	list($api, $method) = explode('.', $name);
38 38
 
39 39
 
40
-    $params = [];
41
-    if (pq($title)->nextAll('h5')->eq(0)->text() === 'Параметры') {
42
-        foreach (pq($title)->nextAll('h5:contains("Параметры")')->eq(0)->next('table')->eq(0)->find('tr')->eq(0)->nextAll() as $tr) {
43
-            $td = pq($tr)->find('td');
44
-            foreach (explode(', ', $td->eq(0)->text()) as $name) {
45
-                $params[] = [
46
-                    'name' => $name,
47
-                    'type' => $td->eq(1)->text(),
48
-                    'description' => $td->eq(2)->text(),
49
-                    'required' => isRequired($td->eq(2)->text())
50
-                ];
51
-            }
52
-        }
53
-    }
54
-    $results = [];
55
-    foreach (pq($title)->nextAll('h5:contains("Результат")')->next('table')->eq(0)->find('tr')->eq(0)->nextAll() as $tr) {
56
-        $td = pq($tr)->find('td');
57
-        foreach (explode(', ', $td->eq(0)->text()) as $name) {
58
-            $results[] = [
59
-                'name' => $name,
60
-                'description' => $td->eq(1)->text(),
61
-            ];
62
-        }
63
-    }
40
+	$params = [];
41
+	if (pq($title)->nextAll('h5')->eq(0)->text() === 'Параметры') {
42
+		foreach (pq($title)->nextAll('h5:contains("Параметры")')->eq(0)->next('table')->eq(0)->find('tr')->eq(0)->nextAll() as $tr) {
43
+			$td = pq($tr)->find('td');
44
+			foreach (explode(', ', $td->eq(0)->text()) as $name) {
45
+				$params[] = [
46
+					'name' => $name,
47
+					'type' => $td->eq(1)->text(),
48
+					'description' => $td->eq(2)->text(),
49
+					'required' => isRequired($td->eq(2)->text())
50
+				];
51
+			}
52
+		}
53
+	}
54
+	$results = [];
55
+	foreach (pq($title)->nextAll('h5:contains("Результат")')->next('table')->eq(0)->find('tr')->eq(0)->nextAll() as $tr) {
56
+		$td = pq($tr)->find('td');
57
+		foreach (explode(', ', $td->eq(0)->text()) as $name) {
58
+			$results[] = [
59
+				'name' => $name,
60
+				'description' => $td->eq(1)->text(),
61
+			];
62
+		}
63
+	}
64 64
 
65
-    if (!isset($data[$api])) {
66
-        $data[$api] = [
67
-            'name' => $api,
68
-            'description' => $description,
69
-            'methods' => []
70
-        ];
71
-    }
65
+	if (!isset($data[$api])) {
66
+		$data[$api] = [
67
+			'name' => $api,
68
+			'description' => $description,
69
+			'methods' => []
70
+		];
71
+	}
72 72
 
73
-    $data[$api]['methods'][] = [
74
-        'name' => $method,
75
-        'description' => pq($title)->next('p')->text(),
76
-        'params' => $params,
77
-        'returns' => $results
78
-    ];
73
+	$data[$api]['methods'][] = [
74
+		'name' => $method,
75
+		'description' => pq($title)->next('p')->text(),
76
+		'params' => $params,
77
+		'returns' => $results
78
+	];
79 79
 };
80 80
 file_put_contents('data.json', json_encode($data));
81 81
 
Please login to merge, or discard this patch.
codegen/ClientAbstract.php 1 patch
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -6,42 +6,42 @@
 block discarded – undo
6 6
 
7 7
 class ClientAbstract extends ClassGenerator
8 8
 {
9
-    protected function formExtends()
10
-    {
11
-        return 'carono\rest\Client';
12
-    }
13
-
14
-    protected function formClassName()
15
-    {
16
-        return 'ClientAbstract';
17
-    }
18
-
19
-    protected function formClassNamespace()
20
-    {
21
-        return 'carono\etxtru';
22
-    }
23
-
24
-    protected function formOutputPath()
25
-    {
26
-        return dirname(__DIR__) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . $this->formClassName() . '.php';
27
-    }
28
-
29
-    public function methods()
30
-    {
31
-        $this->phpClass->setAbstract(true);
32
-        foreach ($this->params as $request => $data) {
33
-            $sectionRequest = new RequestAbstract();
34
-            $sectionRequest->renderToFile($data);
35
-            $className = "\\" . $sectionRequest->formClassNamespace() . "\\" . $sectionRequest->formClassName();
36
-
37
-            $method = $this->phpClass->addMethod(formMethodName($request));
38
-            $body = <<<PHP
9
+	protected function formExtends()
10
+	{
11
+		return 'carono\rest\Client';
12
+	}
13
+
14
+	protected function formClassName()
15
+	{
16
+		return 'ClientAbstract';
17
+	}
18
+
19
+	protected function formClassNamespace()
20
+	{
21
+		return 'carono\etxtru';
22
+	}
23
+
24
+	protected function formOutputPath()
25
+	{
26
+		return dirname(__DIR__) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . $this->formClassName() . '.php';
27
+	}
28
+
29
+	public function methods()
30
+	{
31
+		$this->phpClass->setAbstract(true);
32
+		foreach ($this->params as $request => $data) {
33
+			$sectionRequest = new RequestAbstract();
34
+			$sectionRequest->renderToFile($data);
35
+			$className = "\\" . $sectionRequest->formClassNamespace() . "\\" . $sectionRequest->formClassName();
36
+
37
+			$method = $this->phpClass->addMethod(formMethodName($request));
38
+			$body = <<<PHP
39 39
 return (new $className(\$this));
40 40
 PHP;
41
-            $method->addBody($body);
42
-            $method->addComment($data['description']);
43
-            $method->addComment("@return $className");
44
-        }
45
-        return false;
46
-    }
41
+			$method->addBody($body);
42
+			$method->addComment($data['description']);
43
+			$method->addComment("@return $className");
44
+		}
45
+		return false;
46
+	}
47 47
 }
48 48
\ No newline at end of file
Please login to merge, or discard this patch.
codegen/readme.php 1 patch
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -51,40 +51,40 @@  discard block
 block discarded – undo
51 51
 
52 52
 $data = json_decode(file_get_contents('data.json'), true);
53 53
 $description = [
54
-    ['Метод', 'Описание']
54
+	['Метод', 'Описание']
55 55
 ];
56 56
 $sectionData = [];
57 57
 foreach ($data as $api => $section) {
58
-    $sectionName = formMethodName($section['name']);
59
-    $description[] = ['$client->' . $sectionName . '()', $section['description']];
58
+	$sectionName = formMethodName($section['name']);
59
+	$description[] = ['$client->' . $sectionName . '()', $section['description']];
60 60
 
61
-    $sectionData[] = asHeader($section['description']);
62
-    $sectionData[] = <<<HTML
61
+	$sectionData[] = asHeader($section['description']);
62
+	$sectionData[] = <<<HTML
63 63
 ```php
64 64
 \$client->{$sectionName}();
65 65
 ```
66 66
 
67 67
 HTML;
68
-    $methods = [
69
-        ['Метод', 'Описание', 'Входные данные', 'Выходные данные']
70
-    ];
71
-    $sectionData[] = asHeader('Доступные методы', 2);
72
-    foreach ($section['methods'] as $method) {
73
-        $sectionData[] = '**' . $method['name'] . '** - ' . $method['description'];
74
-
75
-
76
-        if (count($method['params']) > 4) {
77
-            $params = '$config';
78
-        } else {
79
-            $params = [];
80
-            foreach ($method['params'] as $param) {
81
-                $params[] = '$' . $param['name'];
82
-            }
83
-            $params = implode(', ', $params);
84
-        }
85
-        $methodName = formMethodName($method['name']);
86
-
87
-        $sectionData[] = <<<HTML
68
+	$methods = [
69
+		['Метод', 'Описание', 'Входные данные', 'Выходные данные']
70
+	];
71
+	$sectionData[] = asHeader('Доступные методы', 2);
72
+	foreach ($section['methods'] as $method) {
73
+		$sectionData[] = '**' . $method['name'] . '** - ' . $method['description'];
74
+
75
+
76
+		if (count($method['params']) > 4) {
77
+			$params = '$config';
78
+		} else {
79
+			$params = [];
80
+			foreach ($method['params'] as $param) {
81
+				$params[] = '$' . $param['name'];
82
+			}
83
+			$params = implode(', ', $params);
84
+		}
85
+		$methodName = formMethodName($method['name']);
86
+
87
+		$sectionData[] = <<<HTML
88 88
         
89 89
 ```php
90 90
 \$client->{$sectionName}()->{$methodName}($params);
@@ -93,22 +93,22 @@  discard block
 block discarded – undo
93 93
 HTML;
94 94
 
95 95
 
96
-        $sectionData[] = '';
97
-        if ($method['params']) {
98
-            $sectionData[] = asHeader('Входные параметры', 4);
99
-            $params = [['Параметр', 'Тип', 'Описание']];
100
-            foreach ($method['params'] as $param) {
101
-                $params[] = [$param['name'], $param['type'], stripLines($param['description'])];
102
-            }
103
-            $sectionData[] = asTable($params);
104
-        }
96
+		$sectionData[] = '';
97
+		if ($method['params']) {
98
+			$sectionData[] = asHeader('Входные параметры', 4);
99
+			$params = [['Параметр', 'Тип', 'Описание']];
100
+			foreach ($method['params'] as $param) {
101
+				$params[] = [$param['name'], $param['type'], stripLines($param['description'])];
102
+			}
103
+			$sectionData[] = asTable($params);
104
+		}
105 105
 
106
-        $sectionData[] = asHeader('Результат', 4);
107
-        $params = [['Параметр', 'Описание']];
108
-        foreach ($method['returns'] as $param) {
109
-            $params[] = [$param['name'], stripLines($param['description'])];
110
-        }
111
-        $sectionData[] = asTable($params);
106
+		$sectionData[] = asHeader('Результат', 4);
107
+		$params = [['Параметр', 'Описание']];
108
+		foreach ($method['returns'] as $param) {
109
+			$params[] = [$param['name'], stripLines($param['description'])];
110
+		}
111
+		$sectionData[] = asTable($params);
112 112
 
113 113
 
114 114
 //            $results[] = formParamLine($result);
@@ -118,14 +118,14 @@  discard block
 block discarded – undo
118 118
 //                }
119 119
 //            }
120 120
 
121
-        $sectionData[] = "\n\n***\n\n";
122
-    }
123
-    $sectionData[] = asTable($methods);
121
+		$sectionData[] = "\n\n***\n\n";
122
+	}
123
+	$sectionData[] = asTable($methods);
124 124
 }
125 125
 $content .= asTable($description);
126 126
 
127 127
 foreach ($sectionData as $sectionDatum) {
128
-    $content .= $sectionDatum;
128
+	$content .= $sectionDatum;
129 129
 }
130 130
 
131 131
 file_put_contents('../README.md', trim($content));
Please login to merge, or discard this patch.
codegen/ResponseAbstract.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -6,51 +6,51 @@
 block discarded – undo
6 6
 
7 7
 class ResponseAbstract extends ClassGenerator
8 8
 {
9
-    public $properties = [];
10
-
11
-    protected function formExtends()
12
-    {
13
-        if (strpos($this->formClassName(), 'ElementResponse')) {
14
-            return 'carono\etxtru\ArrayObject';
15
-        }
16
-
17
-        return 'carono\etxtru\ResponseAbstract';
18
-    }
19
-
20
-    protected function formClassName()
21
-    {
22
-        $name = $this->params['name'];
23
-
24
-
25
-        $name = formClassName($name);
26
-        if (!isset($this->params['returns']) && substr($name, -1, 1) == 's') {
27
-            $name = substr($name, 0, -1) . 'Element';
28
-        }
29
-        return $name . 'Response';
30
-    }
31
-
32
-    protected function formClassNamespace()
33
-    {
34
-        return 'carono\etxtru\response';
35
-    }
36
-
37
-    protected function formOutputPath()
38
-    {
39
-        return dirname(__DIR__) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'response' . DIRECTORY_SEPARATOR . $this->formClassName() . '.php';
40
-    }
41
-
42
-    protected function classProperties()
43
-    {
44
-        $properties = [];
45
-        foreach ($this->params['returns'] as $param) {
46
-            $properties[$param['name']] = [
47
-                'comment' => [
48
-                    stripAndWordWrap($param['description'])
49
-                ],
50
-                'value' => null
51
-            ];
52
-        }
53
-        return $properties;
54
-    }
9
+	public $properties = [];
10
+
11
+	protected function formExtends()
12
+	{
13
+		if (strpos($this->formClassName(), 'ElementResponse')) {
14
+			return 'carono\etxtru\ArrayObject';
15
+		}
16
+
17
+		return 'carono\etxtru\ResponseAbstract';
18
+	}
19
+
20
+	protected function formClassName()
21
+	{
22
+		$name = $this->params['name'];
23
+
24
+
25
+		$name = formClassName($name);
26
+		if (!isset($this->params['returns']) && substr($name, -1, 1) == 's') {
27
+			$name = substr($name, 0, -1) . 'Element';
28
+		}
29
+		return $name . 'Response';
30
+	}
31
+
32
+	protected function formClassNamespace()
33
+	{
34
+		return 'carono\etxtru\response';
35
+	}
36
+
37
+	protected function formOutputPath()
38
+	{
39
+		return dirname(__DIR__) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'response' . DIRECTORY_SEPARATOR . $this->formClassName() . '.php';
40
+	}
41
+
42
+	protected function classProperties()
43
+	{
44
+		$properties = [];
45
+		foreach ($this->params['returns'] as $param) {
46
+			$properties[$param['name']] = [
47
+				'comment' => [
48
+					stripAndWordWrap($param['description'])
49
+				],
50
+				'value' => null
51
+			];
52
+		}
53
+		return $properties;
54
+	}
55 55
 
56 56
 }
57 57
\ No newline at end of file
Please login to merge, or discard this patch.
codegen/ConfigAbstract.php 1 patch
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -7,40 +7,40 @@
 block discarded – undo
7 7
 
8 8
 class ConfigAbstract extends ClassGenerator
9 9
 {
10
-    protected function formExtends()
11
-    {
12
-        return 'carono\etxtru\ConfigAbstract';
13
-    }
14
-
15
-    protected function formClassName()
16
-    {
17
-        return formClassName($this->params['api'] . '_' . $this->params['name'], []) . 'Config';
18
-    }
19
-
20
-    protected function formClassNamespace()
21
-    {
22
-        return 'carono\etxtru\config';
23
-    }
24
-
25
-    protected function formOutputPath()
26
-    {
27
-        return dirname(__DIR__) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . $this->formClassName() . '.php';
28
-    }
29
-
30
-    protected function classProperties()
31
-    {
32
-        $properties = [];
33
-        foreach ($this->params['params'] as $param) {
34
-            if (is_string($param)) {
35
-                continue;
36
-            }
37
-            $properties[$param['name']] = [
38
-                'comment' => [
39
-                    stripAndWordWrap(stripSpaces($param['description'])),
40
-                    '@var ' . formParamType($param['type'])
41
-                ]
42
-            ];
43
-        }
44
-        return $properties;
45
-    }
10
+	protected function formExtends()
11
+	{
12
+		return 'carono\etxtru\ConfigAbstract';
13
+	}
14
+
15
+	protected function formClassName()
16
+	{
17
+		return formClassName($this->params['api'] . '_' . $this->params['name'], []) . 'Config';
18
+	}
19
+
20
+	protected function formClassNamespace()
21
+	{
22
+		return 'carono\etxtru\config';
23
+	}
24
+
25
+	protected function formOutputPath()
26
+	{
27
+		return dirname(__DIR__) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . $this->formClassName() . '.php';
28
+	}
29
+
30
+	protected function classProperties()
31
+	{
32
+		$properties = [];
33
+		foreach ($this->params['params'] as $param) {
34
+			if (is_string($param)) {
35
+				continue;
36
+			}
37
+			$properties[$param['name']] = [
38
+				'comment' => [
39
+					stripAndWordWrap(stripSpaces($param['description'])),
40
+					'@var ' . formParamType($param['type'])
41
+				]
42
+			];
43
+		}
44
+		return $properties;
45
+	}
46 46
 }
47 47
\ No newline at end of file
Please login to merge, or discard this patch.
codegen/RequestAbstract.php 1 patch
Indentation   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -6,105 +6,105 @@
 block discarded – undo
6 6
 
7 7
 class RequestAbstract extends ClassGenerator
8 8
 {
9
-    /**
10
-     * @return string
11
-     */
12
-    protected function formExtends()
13
-    {
14
-        return 'carono\etxtru\RequestAbstract';
15
-    }
9
+	/**
10
+	 * @return string
11
+	 */
12
+	protected function formExtends()
13
+	{
14
+		return 'carono\etxtru\RequestAbstract';
15
+	}
16 16
 
17
-    /**
18
-     * @return string
19
-     */
20
-    protected function formClassName()
21
-    {
22
-        return ucfirst(formClassName($this->params['name'])) . 'Request';
23
-    }
17
+	/**
18
+	 * @return string
19
+	 */
20
+	protected function formClassName()
21
+	{
22
+		return ucfirst(formClassName($this->params['name'])) . 'Request';
23
+	}
24 24
 
25
-    /**
26
-     * @return string
27
-     */
28
-    protected function formClassNamespace()
29
-    {
30
-        return 'carono\etxtru\request';
31
-    }
25
+	/**
26
+	 * @return string
27
+	 */
28
+	protected function formClassNamespace()
29
+	{
30
+		return 'carono\etxtru\request';
31
+	}
32 32
 
33
-    /**
34
-     * @return string
35
-     */
36
-    protected function formOutputPath()
37
-    {
38
-        return dirname(__DIR__) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'request' . DIRECTORY_SEPARATOR . $this->formClassName() . '.php';
39
-    }
33
+	/**
34
+	 * @return string
35
+	 */
36
+	protected function formOutputPath()
37
+	{
38
+		return dirname(__DIR__) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'request' . DIRECTORY_SEPARATOR . $this->formClassName() . '.php';
39
+	}
40 40
 
41
-    /**
42
-     * @return bool
43
-     */
44
-    public function methods()
45
-    {
41
+	/**
42
+	 * @return bool
43
+	 */
44
+	public function methods()
45
+	{
46 46
 
47
-        foreach ($this->params['methods'] as $methodData) {
47
+		foreach ($this->params['methods'] as $methodData) {
48 48
 
49
-            $methodName = formMethodName($methodData['name']);
50
-            $method = $this->phpClass->addMethod($methodName);
51
-            $method->addComment(stripAndWordWrap($methodData['description']));
52
-            $params = [];
53
-            if (count($methodData['params']) > 4) {
54
-                $config = new ConfigAbstract();
55
-                $config->renderToFile(array_merge(['api' => $this->params['name']], $methodData));
56
-                $className = '\\' . $config->formClassNamespace() . '\\' . $config->formClassName();
57
-                $method->addParameter('config');
58
-                $method->addComment("@param $className|array \$config");
59
-                $body = <<<PHP
49
+			$methodName = formMethodName($methodData['name']);
50
+			$method = $this->phpClass->addMethod($methodName);
51
+			$method->addComment(stripAndWordWrap($methodData['description']));
52
+			$params = [];
53
+			if (count($methodData['params']) > 4) {
54
+				$config = new ConfigAbstract();
55
+				$config->renderToFile(array_merge(['api' => $this->params['name']], $methodData));
56
+				$className = '\\' . $config->formClassNamespace() . '\\' . $config->formClassName();
57
+				$method->addParameter('config');
58
+				$method->addComment("@param $className|array \$config");
59
+				$body = <<<PHP
60 60
 foreach (\$config instanceof \carono\\etxtru\ConfigAbstract ? \$config->toArray() : \$config as \$key => \$value) {
61 61
     \$params[\$key] = \$value;
62 62
 }
63 63
 PHP;
64
-                $paramsStr = self::arrayAsPhpVar($params);
65
-                $method->addBody("\$params = $paramsStr;");
66
-                $method->addBody($body);
67
-            } else {
68
-                foreach ($methodData['params'] as $param) {
69
-                    $type = formParamType($param['type']);
70
-                    $description = trim(stripAndWordWrap($param['description']));
71
-                    $method->addComment("@param {$type} \${$param['name']} {$description}");
72
-                    $params[$param['name']] = '$' . $param['name'];
73
-                    if ($param['required']) {
74
-                        $method->addParameter($param['name']);
75
-                    } else {
76
-                        $method->addParameter($param['name'], null);
77
-                    }
78
-                }
79
-                $paramsStr = self::arrayAsPhpVar($params);
80
-                $method->addBody("\$params = $paramsStr;");
81
-            }
82
-            $response = new ResponseAbstract();
83
-            if (isset($methodData['returns'][0])) {
84
-                $response->renderToFile(['name' => $methodName, 'returns' => $methodData['returns']]);
85
-                $className = $response->formClassNamespace() . '\\' . $response->formClassName();
86
-            } else {
87
-                $className = 'carono\etxtru\Response';
88
-            }
89
-            $method->addComment("@return \\$className|\stdClass");
90
-            $api = $this->params['name'] . '.' . $methodData['name'];
91
-            $method->addBody("return \$this->getClient()->getContent('$api', \$params, '$className');");
92
-        }
93
-        return false;
94
-    }
64
+				$paramsStr = self::arrayAsPhpVar($params);
65
+				$method->addBody("\$params = $paramsStr;");
66
+				$method->addBody($body);
67
+			} else {
68
+				foreach ($methodData['params'] as $param) {
69
+					$type = formParamType($param['type']);
70
+					$description = trim(stripAndWordWrap($param['description']));
71
+					$method->addComment("@param {$type} \${$param['name']} {$description}");
72
+					$params[$param['name']] = '$' . $param['name'];
73
+					if ($param['required']) {
74
+						$method->addParameter($param['name']);
75
+					} else {
76
+						$method->addParameter($param['name'], null);
77
+					}
78
+				}
79
+				$paramsStr = self::arrayAsPhpVar($params);
80
+				$method->addBody("\$params = $paramsStr;");
81
+			}
82
+			$response = new ResponseAbstract();
83
+			if (isset($methodData['returns'][0])) {
84
+				$response->renderToFile(['name' => $methodName, 'returns' => $methodData['returns']]);
85
+				$className = $response->formClassNamespace() . '\\' . $response->formClassName();
86
+			} else {
87
+				$className = 'carono\etxtru\Response';
88
+			}
89
+			$method->addComment("@return \\$className|\stdClass");
90
+			$api = $this->params['name'] . '.' . $methodData['name'];
91
+			$method->addBody("return \$this->getClient()->getContent('$api', \$params, '$className');");
92
+		}
93
+		return false;
94
+	}
95 95
 
96
-    protected static function arrayAsPhpVar($array)
97
-    {
98
-        $export = [];
99
-        foreach ($array as $key => $value) {
100
-            $export[] = "'$key' => " . (strpos($value, '$') === false ? "'$value'" : $value);
101
-        }
102
-        $export = implode(",\n\t", $export);
103
-        if ($array) {
104
-            $result = "[\n\t$export\n]";
105
-        } else {
106
-            $result = '[]';
107
-        }
108
-        return $result;
109
-    }
96
+	protected static function arrayAsPhpVar($array)
97
+	{
98
+		$export = [];
99
+		foreach ($array as $key => $value) {
100
+			$export[] = "'$key' => " . (strpos($value, '$') === false ? "'$value'" : $value);
101
+		}
102
+		$export = implode(",\n\t", $export);
103
+		if ($array) {
104
+			$result = "[\n\t$export\n]";
105
+		} else {
106
+			$result = '[]';
107
+		}
108
+		return $result;
109
+	}
110 110
 }
111 111
\ No newline at end of file
Please login to merge, or discard this patch.
codegen/func.php 1 patch
Indentation   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -2,144 +2,144 @@
 block discarded – undo
2 2
 
3 3
 function parseParamsFromQuery($query)
4 4
 {
5
-    $params = [];
6
-    foreach ($query as $param) {
7
-        if ($parsedParam = parseParams(pq($param)->text())) {
8
-            $params[] = $parsedParam;
9
-        }
10
-    }
11
-    return $params;
5
+	$params = [];
6
+	foreach ($query as $param) {
7
+		if ($parsedParam = parseParams(pq($param)->text())) {
8
+			$params[] = $parsedParam;
9
+		}
10
+	}
11
+	return $params;
12 12
 }
13 13
 
14 14
 function clearFolder($folder)
15 15
 {
16
-    $files = glob(dirname(__DIR__) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . $folder . DIRECTORY_SEPARATOR . '*');
17
-    foreach ($files as $file) {
18
-        if (is_file($file)) {
19
-            @unlink($file);
20
-        }
21
-    }
16
+	$files = glob(dirname(__DIR__) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . $folder . DIRECTORY_SEPARATOR . '*');
17
+	foreach ($files as $file) {
18
+		if (is_file($file)) {
19
+			@unlink($file);
20
+		}
21
+	}
22 22
 }
23 23
 
24 24
 function stripAndWordWrap($str)
25 25
 {
26
-    return wordwrap(stripSpaces($str), 180) . "\n";
26
+	return wordwrap(stripSpaces($str), 180) . "\n";
27 27
 }
28 28
 
29 29
 function formParamLine($param)
30 30
 {
31
-    return '**' . $param['name'] . '** - ' . stripLines($param['description']);
31
+	return '**' . $param['name'] . '** - ' . stripLines($param['description']);
32 32
 }
33 33
 
34 34
 function stripSpaces($str)
35 35
 {
36
-    $str = preg_replace('/[\s]{2,}/', ' ', $str);
37
-    return $str;
36
+	$str = preg_replace('/[\s]{2,}/', ' ', $str);
37
+	return $str;
38 38
 }
39 39
 
40 40
 function stripLines($str)
41 41
 {
42
-    $str = str_replace("\n", ' ', $str);
43
-    $str = stripSpaces($str);
44
-    return $str;
42
+	$str = str_replace("\n", ' ', $str);
43
+	$str = stripSpaces($str);
44
+	return $str;
45 45
 }
46 46
 
47 47
 function formMethodName($str)
48 48
 {
49
-    $arr = array_filter(explode('_', $str));
50
-    $arr = array_map('ucfirst', $arr);
51
-    $arr[0] = lcfirst($arr[0]);
52
-    return implode('', $arr);
49
+	$arr = array_filter(explode('_', $str));
50
+	$arr = array_map('ucfirst', $arr);
51
+	$arr[0] = lcfirst($arr[0]);
52
+	return implode('', $arr);
53 53
 }
54 54
 
55 55
 function formClassName($str, $clear = ['get_', '_array'])
56 56
 {
57
-    foreach ($clear as $item) {
58
-        $str = str_ireplace($item, '', $str);
59
-    }
60
-    $arr = array_filter(explode('_', $str));
61
-    $arr = array_map('ucfirst', $arr);
62
-    return implode('', $arr);
57
+	foreach ($clear as $item) {
58
+		$str = str_ireplace($item, '', $str);
59
+	}
60
+	$arr = array_filter(explode('_', $str));
61
+	$arr = array_map('ucfirst', $arr);
62
+	return implode('', $arr);
63 63
 }
64 64
 
65 65
 function formParamType($str)
66 66
 {
67
-    switch ($str) {
68
-        case 'text':
69
-            return 'string';
70
-            break;
71
-        case 'date':
72
-            return 'string Y-m-d';
73
-            break;
74
-        case 'datetime':
75
-            return 'string Y-m-d H:i:s';
76
-            break;
77
-        case 'string':
78
-            return 'string';
79
-            break;
80
-        case 'int':
81
-            return 'int';
82
-            break;
83
-    }
84
-    return $str;
67
+	switch ($str) {
68
+		case 'text':
69
+			return 'string';
70
+			break;
71
+		case 'date':
72
+			return 'string Y-m-d';
73
+			break;
74
+		case 'datetime':
75
+			return 'string Y-m-d H:i:s';
76
+			break;
77
+		case 'string':
78
+			return 'string';
79
+			break;
80
+		case 'int':
81
+			return 'int';
82
+			break;
83
+	}
84
+	return $str;
85 85
 }
86 86
 
87 87
 function isRequired($text)
88 88
 {
89
-    return mb_strpos($text, 'Необязательный', 0, 'utf-8') === false;
89
+	return mb_strpos($text, 'Необязательный', 0, 'utf-8') === false;
90 90
 }
91 91
 
92 92
 function parseParams($str)
93 93
 {
94
-    if (preg_match('/^(\w+)\s+\((\w+)\)\s+-\s+(.+)/uis', $str, $m)) {
95
-        return [
96
-            'name' => $m[1],
97
-            'type' => $m[2],
98
-            'description' => $m[3],
99
-            'required' => isRequired($m[3])
100
-        ];
101
-    }
102
-
103
-    return [];
94
+	if (preg_match('/^(\w+)\s+\((\w+)\)\s+-\s+(.+)/uis', $str, $m)) {
95
+		return [
96
+			'name' => $m[1],
97
+			'type' => $m[2],
98
+			'description' => $m[3],
99
+			'required' => isRequired($m[3])
100
+		];
101
+	}
102
+
103
+	return [];
104 104
 }
105 105
 
106 106
 function parseReturns($tdHtml)
107 107
 {
108
-    $uls = pq($tdHtml)->find('ul');
109
-    if ($uls->count() == 1 && strpos($tdHtml, 'Каждый элемент') !== false) {
110
-        if (preg_match('/<td>(.)+<ul>/s', $tdHtml, $m)) {
111
-            $ul = "<ul><li>" . trim(strip_tags($m[0])) . "</li></ul>";
112
-            $uls = pq("<td>$ul{$uls->eq(0)->htmlOuter()}</td>")->find('ul');
113
-        }
114
-    }
115
-    $count = $uls->count();
116
-    $parsing = parseParamsFromQuery($uls->eq($count == 2 ? 1 : 0)->find('li'));
117
-    if ($count == 2) {
118
-        $returnParam = parseParams($uls->eq(0)->text());
119
-        $returnParam['result'] = $parsing;
120
-        return [$returnParam];
121
-    }
122
-
123
-    return $parsing;
108
+	$uls = pq($tdHtml)->find('ul');
109
+	if ($uls->count() == 1 && strpos($tdHtml, 'Каждый элемент') !== false) {
110
+		if (preg_match('/<td>(.)+<ul>/s', $tdHtml, $m)) {
111
+			$ul = "<ul><li>" . trim(strip_tags($m[0])) . "</li></ul>";
112
+			$uls = pq("<td>$ul{$uls->eq(0)->htmlOuter()}</td>")->find('ul');
113
+		}
114
+	}
115
+	$count = $uls->count();
116
+	$parsing = parseParamsFromQuery($uls->eq($count == 2 ? 1 : 0)->find('li'));
117
+	if ($count == 2) {
118
+		$returnParam = parseParams($uls->eq(0)->text());
119
+		$returnParam['result'] = $parsing;
120
+		return [$returnParam];
121
+	}
122
+
123
+	return $parsing;
124 124
 }
125 125
 
126 126
 function asTable($array)
127 127
 {
128
-    $header = array_shift($array);
129
-    $content = "\n\n|" . implode('|', $header) . "\n";
130
-    $content .= preg_replace('/[^\|]/iu', '-', trim($content)) . "\n";
131
-    foreach ($array as $key => $columns) {
132
-        $content .= '|' . implode('|', $columns) . "\n";
133
-    }
134
-    return $content;
128
+	$header = array_shift($array);
129
+	$content = "\n\n|" . implode('|', $header) . "\n";
130
+	$content .= preg_replace('/[^\|]/iu', '-', trim($content)) . "\n";
131
+	foreach ($array as $key => $columns) {
132
+		$content .= '|' . implode('|', $columns) . "\n";
133
+	}
134
+	return $content;
135 135
 }
136 136
 
137 137
 function asHeader($string, $sub = 1)
138 138
 {
139
-    return "\n\n" . str_repeat('#', $sub) . $string . "\n\n";
139
+	return "\n\n" . str_repeat('#', $sub) . $string . "\n\n";
140 140
 }
141 141
 
142 142
 function asCode($code)
143 143
 {
144
-    return "`$code`";
144
+	return "`$code`";
145 145
 }
146 146
\ No newline at end of file
Please login to merge, or discard this patch.