Passed
Push — master ( fc36dd...97e630 )
by Aleksandr
01:54
created
codegen/readme.php 1 patch
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -46,55 +46,55 @@
 block discarded – undo
46 46
 HTML;
47 47
 
48 48
 $description = [
49
-    ['Метод', 'Описание']
49
+	['Метод', 'Описание']
50 50
 ];
51 51
 $sectionData = [];
52 52
 foreach ($data as $section) {
53
-    $description[] = [
54
-        '$client->' . $section['name'] . '()',
55
-        $section['description']
56
-    ];
57
-    $sectionData[] = asHeader($section['description']);
58
-    $sectionData[] = <<<HTML
53
+	$description[] = [
54
+		'$client->' . $section['name'] . '()',
55
+		$section['description']
56
+	];
57
+	$sectionData[] = asHeader($section['description']);
58
+	$sectionData[] = <<<HTML
59 59
 ```php
60 60
 \$client->{$section['name']}();
61 61
 ```
62 62
 HTML;
63 63
 
64
-    $methods = [
65
-        ['Метод', 'Описание', 'Входные данные', 'Выходные данные']
66
-    ];
64
+	$methods = [
65
+		['Метод', 'Описание', 'Входные данные', 'Выходные данные']
66
+	];
67 67
 
68
-    foreach ($section['methods'] as $method) {
69
-        $results = [];
70
-        $params = [];
71
-        foreach ($method['returns'] as $result) {
72
-            $results[] = formParamLine($result);
73
-            if (isset($result['result'])) {
74
-                foreach ($result['result'] as $res) {
75
-                    $results[] = formParamLine($res);
76
-                }
77
-            }
78
-        }
79
-        if (isset($method['params'])) {
80
-            foreach ($method['params'] as $param) {
81
-                $params[] = '**' . $param['name'] . "** ({$param['type']}) - " . stripLines($param['description']);
82
-            }
83
-        }
68
+	foreach ($section['methods'] as $method) {
69
+		$results = [];
70
+		$params = [];
71
+		foreach ($method['returns'] as $result) {
72
+			$results[] = formParamLine($result);
73
+			if (isset($result['result'])) {
74
+				foreach ($result['result'] as $res) {
75
+					$results[] = formParamLine($res);
76
+				}
77
+			}
78
+		}
79
+		if (isset($method['params'])) {
80
+			foreach ($method['params'] as $param) {
81
+				$params[] = '**' . $param['name'] . "** ({$param['type']}) - " . stripLines($param['description']);
82
+			}
83
+		}
84 84
 
85
-        $methods[] = [
86
-            formMethodName($method['name']),
87
-            stripLines($method['description']),
88
-            join('<br /><br />', $params),
89
-            join('<br /><br />', $results),
90
-        ];
91
-    }
92
-    $sectionData[] = asTable($methods);
85
+		$methods[] = [
86
+			formMethodName($method['name']),
87
+			stripLines($method['description']),
88
+			join('<br /><br />', $params),
89
+			join('<br /><br />', $results),
90
+		];
91
+	}
92
+	$sectionData[] = asTable($methods);
93 93
 }
94 94
 $content .= asTable($description);
95 95
 
96 96
 foreach ($sectionData as $sectionDatum) {
97
-    $content .= $sectionDatum;
97
+	$content .= $sectionDatum;
98 98
 }
99 99
 
100 100
 $content .= asHeader('Внимание');
Please login to merge, or discard this patch.
codegen/func.php 1 patch
Indentation   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -2,108 +2,108 @@
 block discarded – undo
2 2
 
3 3
 function formParamLine($param)
4 4
 {
5
-    return '**' . $param['name'] . "** ({$param['type']}) - " . stripLines($param['description']);
5
+	return '**' . $param['name'] . "** ({$param['type']}) - " . stripLines($param['description']);
6 6
 }
7 7
 
8 8
 function stripLines($str)
9 9
 {
10
-    $str = str_replace("\n", " ", $str);
11
-    $str = preg_replace('/[\s]{2,}/', ' ', $str);
12
-    return $str;
10
+	$str = str_replace("\n", " ", $str);
11
+	$str = preg_replace('/[\s]{2,}/', ' ', $str);
12
+	return $str;
13 13
 }
14 14
 
15 15
 function formMethodName($str)
16 16
 {
17
-    $arr = array_filter(explode('_', $str));
18
-    $arr = array_map('ucfirst', $arr);
19
-    $arr[0] = lcfirst($arr[0]);
20
-    return join('', $arr);
17
+	$arr = array_filter(explode('_', $str));
18
+	$arr = array_map('ucfirst', $arr);
19
+	$arr[0] = lcfirst($arr[0]);
20
+	return join('', $arr);
21 21
 }
22 22
 
23 23
 function formClassName($str)
24 24
 {
25
-    $clear = [
26
-        'get_',
27
-        'create_',
28
-        '_array'
29
-    ];
30
-    foreach ($clear as $item) {
31
-        $str = str_ireplace($item, '', $str);
32
-    }
33
-    $arr = array_filter(explode('_', $str));
34
-    $arr = array_map('ucfirst', $arr);
35
-    return join('', $arr);
25
+	$clear = [
26
+		'get_',
27
+		'create_',
28
+		'_array'
29
+	];
30
+	foreach ($clear as $item) {
31
+		$str = str_ireplace($item, '', $str);
32
+	}
33
+	$arr = array_filter(explode('_', $str));
34
+	$arr = array_map('ucfirst', $arr);
35
+	return join('', $arr);
36 36
 }
37 37
 
38 38
 function formParamType($str)
39 39
 {
40
-    if ($str == 'text') {
41
-        return 'string';
42
-    }
43
-    return $str;
40
+	if ($str == 'text') {
41
+		return 'string';
42
+	}
43
+	return $str;
44 44
 }
45 45
 
46 46
 function parseParams($str)
47 47
 {
48
-    if (preg_match('/^(\w+)\s+\((\w+)\)\s+-\s+(.+)/uis', $str, $m)) {
49
-        return [
50
-            'name' => $m[1],
51
-            'type' => $m[2],
52
-            'description' => $m[3],
53
-            'required' => mb_strpos($m[3], 'Необязательный', 0, 'utf-8') === false
54
-        ];
55
-    } else {
56
-        return [];
57
-    }
48
+	if (preg_match('/^(\w+)\s+\((\w+)\)\s+-\s+(.+)/uis', $str, $m)) {
49
+		return [
50
+			'name' => $m[1],
51
+			'type' => $m[2],
52
+			'description' => $m[3],
53
+			'required' => mb_strpos($m[3], 'Необязательный', 0, 'utf-8') === false
54
+		];
55
+	} else {
56
+		return [];
57
+	}
58 58
 }
59 59
 
60 60
 function parseReturns($tdHtml)
61 61
 {
62
-    $uls = pq($tdHtml)->find('ul');
63
-    $returns = [];
64
-    if ($uls->count() == 1 && strpos($tdHtml, 'Каждый элемент') !== false) {
65
-        if (preg_match('/<td>(.)+<ul>/s', $tdHtml, $m)) {
66
-            $ul = "<ul><li>" . trim(strip_tags($m[0])) . "</li></ul>";
67
-            $uls = pq("<td>$ul{$uls->eq(0)->htmlOuter()}</td>")->find('ul');
68
-        }
69
-    }
70
-    if ($uls->count() == 2) {
71
-        $returnParam = parseParams($uls->eq(0)->text());
72
-        $result = [];
73
-        foreach ($uls->eq(1)->find('li') as $param) {
74
-            if ($parsedParam = parseParams(pq($param)->text())) {
75
-                $result[] = $parsedParam;
76
-            }
77
-        }
78
-        $returnParam['result'] = $result;
79
-        $returns[] = $returnParam;
80
-    } else {
81
-        foreach ($uls->eq(0)->find('li') as $param) {
82
-            if ($parsedParam = parseParams(pq($param)->text())) {
83
-                $returns[] = $parsedParam;
84
-            }
85
-        }
86
-    }
87
-    return $returns;
62
+	$uls = pq($tdHtml)->find('ul');
63
+	$returns = [];
64
+	if ($uls->count() == 1 && strpos($tdHtml, 'Каждый элемент') !== false) {
65
+		if (preg_match('/<td>(.)+<ul>/s', $tdHtml, $m)) {
66
+			$ul = "<ul><li>" . trim(strip_tags($m[0])) . "</li></ul>";
67
+			$uls = pq("<td>$ul{$uls->eq(0)->htmlOuter()}</td>")->find('ul');
68
+		}
69
+	}
70
+	if ($uls->count() == 2) {
71
+		$returnParam = parseParams($uls->eq(0)->text());
72
+		$result = [];
73
+		foreach ($uls->eq(1)->find('li') as $param) {
74
+			if ($parsedParam = parseParams(pq($param)->text())) {
75
+				$result[] = $parsedParam;
76
+			}
77
+		}
78
+		$returnParam['result'] = $result;
79
+		$returns[] = $returnParam;
80
+	} else {
81
+		foreach ($uls->eq(0)->find('li') as $param) {
82
+			if ($parsedParam = parseParams(pq($param)->text())) {
83
+				$returns[] = $parsedParam;
84
+			}
85
+		}
86
+	}
87
+	return $returns;
88 88
 }
89 89
 
90 90
 function asTable($array)
91 91
 {
92
-    $header = array_shift($array);
93
-    $content = "\n\n|" . join("|", $header) . "\n";
94
-    $content .= preg_replace('/[^\|]/iu', '-', trim($content)) . "\n";
95
-    foreach ($array as $key => $columns) {
96
-        $content .= "|" . join("|", $columns) . "\n";
97
-    }
98
-    return $content;
92
+	$header = array_shift($array);
93
+	$content = "\n\n|" . join("|", $header) . "\n";
94
+	$content .= preg_replace('/[^\|]/iu', '-', trim($content)) . "\n";
95
+	foreach ($array as $key => $columns) {
96
+		$content .= "|" . join("|", $columns) . "\n";
97
+	}
98
+	return $content;
99 99
 }
100 100
 
101 101
 function asHeader($string)
102 102
 {
103
-    return "\n\n" . $string . "\n" . str_repeat('=', mb_strlen($string, 'utf-8')) . "\n";
103
+	return "\n\n" . $string . "\n" . str_repeat('=', mb_strlen($string, 'utf-8')) . "\n";
104 104
 }
105 105
 
106 106
 function asCode($code)
107 107
 {
108
-    return "`$code`";
108
+	return "`$code`";
109 109
 }
110 110
\ No newline at end of file
Please login to merge, or discard this patch.
codegen/RequestAbstract.php 1 patch
Indentation   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -6,108 +6,108 @@
 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\turbotext\RequestAbstract';
15
-    }
9
+	/**
10
+	 * @return string
11
+	 */
12
+	protected function formExtends()
13
+	{
14
+		return 'carono\turbotext\RequestAbstract';
15
+	}
16 16
 
17
-    /**
18
-     * @return string
19
-     */
20
-    protected function formClassName()
21
-    {
22
-        return ucfirst($this->params['name']) . 'Request';
23
-    }
17
+	/**
18
+	 * @return string
19
+	 */
20
+	protected function formClassName()
21
+	{
22
+		return ucfirst($this->params['name']) . 'Request';
23
+	}
24 24
 
25
-    /**
26
-     * @return string
27
-     */
28
-    protected function formClassNamespace()
29
-    {
30
-        return 'carono\turbotext\request';
31
-    }
25
+	/**
26
+	 * @return string
27
+	 */
28
+	protected function formClassNamespace()
29
+	{
30
+		return 'carono\turbotext\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
-    {
46
-        foreach ($this->params['methods'] as $methodData) {
47
-            $methodName = formMethodName($methodData['name']);
48
-            $method = $this->phpClass->addMethod($methodName);
49
-            $method->addComment(trim($methodData['description']));
50
-            $params = [];
51
-            $params['action'] = $methodData['name'];
52
-            if (count($methodData['params']) > 4) {
53
-                $config = new ConfigAbstract();
54
-                $config->renderToFile($methodData);
55
-                $className = '\\' . $config->formClassNamespace() . '\\' . $config->formClassName();
56
-                $method->addParameter('config');
57
-                $method->addComment("@param $className|array \$config");
41
+	/**
42
+	 * @return bool
43
+	 */
44
+	public function methods()
45
+	{
46
+		foreach ($this->params['methods'] as $methodData) {
47
+			$methodName = formMethodName($methodData['name']);
48
+			$method = $this->phpClass->addMethod($methodName);
49
+			$method->addComment(trim($methodData['description']));
50
+			$params = [];
51
+			$params['action'] = $methodData['name'];
52
+			if (count($methodData['params']) > 4) {
53
+				$config = new ConfigAbstract();
54
+				$config->renderToFile($methodData);
55
+				$className = '\\' . $config->formClassNamespace() . '\\' . $config->formClassName();
56
+				$method->addParameter('config');
57
+				$method->addComment("@param $className|array \$config");
58 58
 
59
-                $body = <<<PHP
59
+				$body = <<<PHP
60 60
 foreach ((\$config instanceof \carono\\turbotext\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
-                    $method->addComment("@param {$type} \${$param['name']} {$param['description']}");
71
-                    $params[$param['name']] = '$' . $param['name'];
72
-                    if ($param['required']) {
73
-                        $method->addParameter($param['name']);
74
-                    } else {
75
-                        $method->addParameter($param['name'], null);
76
-                    }
77
-                }
78
-                $paramsStr = self::arrayAsPhpVar($params);
79
-                $method->addBody("\$params = $paramsStr;");
80
-            }
81
-            $response = new ResponseAbstract();
82
-            if (isset($methodData['returns'][0]['result'])) {
83
-                $response->renderToFile($methodData['returns'][0]);
84
-                $className = $response->formClassNamespace() . '\\' . $response->formClassName();
85
-            } elseif ($methodData['returns']) {
86
-                $methodData['returns']['name'] = $methodData['name'];
87
-                $response->properties['asd'] = 213;
88
-                $response->renderToFile($methodData['returns']);
89
-                $className = $response->formClassNamespace() . '\\' . $response->formClassName();
90
-            } else {
91
-                $className = 'carono\turbotext\Response';
92
-            }
93
-            $method->addComment("@return \\$className|string|\stdClass|\SimpleXMLElement");
94
-            $method->addBody("return \$this->getClient()->getContent('api', \$params, '$className');");
95
-        }
96
-        return false;
97
-    }
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
+					$method->addComment("@param {$type} \${$param['name']} {$param['description']}");
71
+					$params[$param['name']] = '$' . $param['name'];
72
+					if ($param['required']) {
73
+						$method->addParameter($param['name']);
74
+					} else {
75
+						$method->addParameter($param['name'], null);
76
+					}
77
+				}
78
+				$paramsStr = self::arrayAsPhpVar($params);
79
+				$method->addBody("\$params = $paramsStr;");
80
+			}
81
+			$response = new ResponseAbstract();
82
+			if (isset($methodData['returns'][0]['result'])) {
83
+				$response->renderToFile($methodData['returns'][0]);
84
+				$className = $response->formClassNamespace() . '\\' . $response->formClassName();
85
+			} elseif ($methodData['returns']) {
86
+				$methodData['returns']['name'] = $methodData['name'];
87
+				$response->properties['asd'] = 213;
88
+				$response->renderToFile($methodData['returns']);
89
+				$className = $response->formClassNamespace() . '\\' . $response->formClassName();
90
+			} else {
91
+				$className = 'carono\turbotext\Response';
92
+			}
93
+			$method->addComment("@return \\$className|string|\stdClass|\SimpleXMLElement");
94
+			$method->addBody("return \$this->getClient()->getContent('api', \$params, '$className');");
95
+		}
96
+		return false;
97
+	}
98 98
 
99
-    protected static function arrayAsPhpVar($array)
100
-    {
101
-        $export = [];
102
-        foreach ($array as $key => $value) {
103
-            $export[] = "'$key' => " . (strpos($value, '$') === false ? "'$value'" : $value);
104
-        }
105
-        $export = join(",\n\t", $export);
106
-        if ($array) {
107
-            $result = "[\n\t$export\n]";
108
-        } else {
109
-            $result = "[]";
110
-        }
111
-        return $result;
112
-    }
99
+	protected static function arrayAsPhpVar($array)
100
+	{
101
+		$export = [];
102
+		foreach ($array as $key => $value) {
103
+			$export[] = "'$key' => " . (strpos($value, '$') === false ? "'$value'" : $value);
104
+		}
105
+		$export = join(",\n\t", $export);
106
+		if ($array) {
107
+			$result = "[\n\t$export\n]";
108
+		} else {
109
+			$result = "[]";
110
+		}
111
+		return $result;
112
+	}
113 113
 }
114 114
\ No newline at end of file
Please login to merge, or discard this patch.