Passed
Push — master ( bce341...cc6cb1 )
by Aleksandr
02:11
created
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.
codegen/readme.php 1 patch
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -52,37 +52,37 @@  discard block
 block discarded – undo
52 52
 
53 53
 $data = json_decode(file_get_contents('data.json'), true);
54 54
 $description = [
55
-    ['Метод', 'Описание']
55
+	['Метод', 'Описание']
56 56
 ];
57 57
 
58 58
 foreach ($data as $api => $section) {
59
-    $sectionName = formMethodName($section['name']);
60
-    $description[] = ['$client->' . $sectionName . '()', $section['description']];
59
+	$sectionName = formMethodName($section['name']);
60
+	$description[] = ['$client->' . $sectionName . '()', $section['description']];
61 61
 
62
-    $sectionData[] = asHeader($section['description']);
63
-    $sectionData[] = <<<HTML
62
+	$sectionData[] = asHeader($section['description']);
63
+	$sectionData[] = <<<HTML
64 64
 ```php
65 65
 \$client->{$sectionName}();
66 66
 ```
67 67
 
68 68
 HTML;
69
-    $sectionData[] = asHeader('Доступные методы', 2);
70
-    foreach ($section['methods'] as $method) {
71
-        $sectionData[] = '**' . $method['name'] . '** - ' . $method['description'];
72
-
73
-
74
-        if (count($method['params']) > 4) {
75
-            $params = '$config';
76
-        } else {
77
-            $params = [];
78
-            foreach ($method['params'] as $param) {
79
-                $params[] = '$' . $param['name'];
80
-            }
81
-            $params = implode(', ', $params);
82
-        }
83
-        $methodName = formMethodName($method['name']);
84
-
85
-        $sectionData[] = <<<HTML
69
+	$sectionData[] = asHeader('Доступные методы', 2);
70
+	foreach ($section['methods'] as $method) {
71
+		$sectionData[] = '**' . $method['name'] . '** - ' . $method['description'];
72
+
73
+
74
+		if (count($method['params']) > 4) {
75
+			$params = '$config';
76
+		} else {
77
+			$params = [];
78
+			foreach ($method['params'] as $param) {
79
+				$params[] = '$' . $param['name'];
80
+			}
81
+			$params = implode(', ', $params);
82
+		}
83
+		$methodName = formMethodName($method['name']);
84
+
85
+		$sectionData[] = <<<HTML
86 86
         
87 87
 ```php
88 88
 \$client->{$sectionName}()->{$methodName}($params);
@@ -91,24 +91,24 @@  discard block
 block discarded – undo
91 91
 HTML;
92 92
 
93 93
 
94
-        $sectionData[] = '';
95
-        if ($method['params']) {
96
-            $sectionData[] = asHeader('Входные параметры', 4);
97
-            $params = [['Параметр', 'Тип', 'Описание']];
98
-            foreach ($method['params'] as $param) {
99
-                $params[] = [$param['name'], $param['type'], stripLines($param['description'])];
100
-            }
101
-            $sectionData[] = asTable($params);
102
-        }
103
-
104
-        $sectionData[] = asHeader('Результат', 4);
105
-        $params = [['Параметр', 'Описание']];
106
-        foreach ($method['returns'] as $param) {
107
-            $params[] = [$param['name'], stripLines($param['description'])];
108
-        }
109
-        $sectionData[] = asTable($params);
110
-        $sectionData[] = "\n\n***\n\n";
111
-    }
94
+		$sectionData[] = '';
95
+		if ($method['params']) {
96
+			$sectionData[] = asHeader('Входные параметры', 4);
97
+			$params = [['Параметр', 'Тип', 'Описание']];
98
+			foreach ($method['params'] as $param) {
99
+				$params[] = [$param['name'], $param['type'], stripLines($param['description'])];
100
+			}
101
+			$sectionData[] = asTable($params);
102
+		}
103
+
104
+		$sectionData[] = asHeader('Результат', 4);
105
+		$params = [['Параметр', 'Описание']];
106
+		foreach ($method['returns'] as $param) {
107
+			$params[] = [$param['name'], stripLines($param['description'])];
108
+		}
109
+		$sectionData[] = asTable($params);
110
+		$sectionData[] = "\n\n***\n\n";
111
+	}
112 112
 }
113 113
 
114 114
 file_put_contents('../README.md', trim(implode('', $sectionData)));
Please login to merge, or discard this patch.