Passed
Push — master ( efc763...1dbf07 )
by Aleksandr
02:12
created
codegen/generate.php 1 patch
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -15,49 +15,49 @@
 block discarded – undo
15 15
 clearFolder('response');
16 16
 
17 17
 $sections = [
18
-    'api1' => 'order',
19
-    'api2' => 'user',
20
-    'api3' => 'microTask',
21
-    'api4' => 'message',
18
+	'api1' => 'order',
19
+	'api2' => 'user',
20
+	'api3' => 'microTask',
21
+	'api4' => 'message',
22 22
 ];
23 23
 $apidoc = 'apidoc.html';
24 24
 if (file_exists($apidoc)) {
25
-    $content = file_get_contents($apidoc);
25
+	$content = file_get_contents($apidoc);
26 26
 } else {
27
-    $content = (new Client())->get('https://www.turbotext.ru/api-info/')->getBody()->getContents();
28
-    file_put_contents($apidoc, $content);
27
+	$content = (new Client())->get('https://www.turbotext.ru/api-info/')->getBody()->getContents();
28
+	file_put_contents($apidoc, $content);
29 29
 }
30 30
 $query = \phpQuery::newDocumentHTML($content);
31 31
 $data = [];
32 32
 $i = 1;
33 33
 foreach ($desc = $query->find('.api_descr') as $desc) {
34
-    $h3 = pq($desc)->prev('h3')->text();
35
-    $item = [
36
-        'name' => $sections['api' . $i++],
37
-        'description' => $h3,
38
-        'methods' => []
39
-    ];
40
-    foreach (pq($desc)->find('table tr') as $tr) {
41
-        $tr = pq($tr);
42
-        if (!$name = trim($tr->find('td')->eq(0)->text())) {
43
-            continue;
44
-        }
45
-        $params = [];
46
-        foreach ($tr->find('td')->eq(2)->find('li') as $param) {
47
-            if ($parsedParam = parseParams(pq($param)->text())) {
48
-                $params[] = $parsedParam;
49
-            }
50
-        }
51
-        $returns = parseReturns($uls = $tr->find('td')->eq(3)->htmlOuter());
52
-        $method = [
53
-            'name' => $name,
54
-            'description' => $tr->find('td')->eq(1)->text(),
55
-            'params' => $params,
56
-            'returns' => $returns
57
-        ];
58
-        $item['methods'][] = $method;
59
-    }
60
-    $data[] = $item;
34
+	$h3 = pq($desc)->prev('h3')->text();
35
+	$item = [
36
+		'name' => $sections['api' . $i++],
37
+		'description' => $h3,
38
+		'methods' => []
39
+	];
40
+	foreach (pq($desc)->find('table tr') as $tr) {
41
+		$tr = pq($tr);
42
+		if (!$name = trim($tr->find('td')->eq(0)->text())) {
43
+			continue;
44
+		}
45
+		$params = [];
46
+		foreach ($tr->find('td')->eq(2)->find('li') as $param) {
47
+			if ($parsedParam = parseParams(pq($param)->text())) {
48
+				$params[] = $parsedParam;
49
+			}
50
+		}
51
+		$returns = parseReturns($uls = $tr->find('td')->eq(3)->htmlOuter());
52
+		$method = [
53
+			'name' => $name,
54
+			'description' => $tr->find('td')->eq(1)->text(),
55
+			'params' => $params,
56
+			'returns' => $returns
57
+		];
58
+		$item['methods'][] = $method;
59
+	}
60
+	$data[] = $item;
61 61
 };
62 62
 file_put_contents('data.json', json_encode($data));
63 63
 
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\turbotext\ConfigAbstract';
13
-    }
14
-
15
-    protected function formClassName()
16
-    {
17
-        return formClassName($this->params['name'], ['get_', '_array', 'create_']) . 'Config';
18
-    }
19
-
20
-    protected function formClassNamespace()
21
-    {
22
-        return 'carono\turbotext\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\turbotext\ConfigAbstract';
13
+	}
14
+
15
+	protected function formClassName()
16
+	{
17
+		return formClassName($this->params['name'], ['get_', '_array', 'create_']) . 'Config';
18
+	}
19
+
20
+	protected function formClassNamespace()
21
+	{
22
+		return 'carono\turbotext\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/func.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -1,132 +1,132 @@
 block discarded – undo
1 1
 <?php
2 2
 function clearFolder($folder)
3 3
 {
4
-    $files = glob(dirname(__DIR__) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . $folder . DIRECTORY_SEPARATOR . '*');
5
-    foreach ($files as $file) {
6
-        if (is_file($file)) {
7
-            @unlink($file);
8
-        }
9
-    }
4
+	$files = glob(dirname(__DIR__) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . $folder . DIRECTORY_SEPARATOR . '*');
5
+	foreach ($files as $file) {
6
+		if (is_file($file)) {
7
+			@unlink($file);
8
+		}
9
+	}
10 10
 }
11 11
 
12 12
 function stripAndWordWrap($str)
13 13
 {
14
-    return wordwrap(stripSpaces($str), 180) . "\n";
14
+	return wordwrap(stripSpaces($str), 180) . "\n";
15 15
 }
16 16
 
17 17
 function formParamLine($param)
18 18
 {
19
-    return '**' . $param['name'] . "** ({$param['type']}) - " . stripLines($param['description']);
19
+	return '**' . $param['name'] . "** ({$param['type']}) - " . stripLines($param['description']);
20 20
 }
21 21
 
22 22
 function stripSpaces($str)
23 23
 {
24
-    $str = preg_replace('/[\s]{2,}/', " ", $str);
25
-    return $str;
24
+	$str = preg_replace('/[\s]{2,}/', " ", $str);
25
+	return $str;
26 26
 }
27 27
 
28 28
 function stripLines($str)
29 29
 {
30
-    $str = str_replace("\n", " ", $str);
31
-    $str = stripSpaces($str);
32
-    return $str;
30
+	$str = str_replace("\n", " ", $str);
31
+	$str = stripSpaces($str);
32
+	return $str;
33 33
 }
34 34
 
35 35
 function formMethodName($str)
36 36
 {
37
-    $arr = array_filter(explode('_', $str));
38
-    $arr = array_map('ucfirst', $arr);
39
-    $arr[0] = lcfirst($arr[0]);
40
-    return join('', $arr);
37
+	$arr = array_filter(explode('_', $str));
38
+	$arr = array_map('ucfirst', $arr);
39
+	$arr[0] = lcfirst($arr[0]);
40
+	return join('', $arr);
41 41
 }
42 42
 
43 43
 function formClassName($str, $clear = ['get_', '_array'])
44 44
 {
45
-    foreach ($clear as $item) {
46
-        $str = str_ireplace($item, '', $str);
47
-    }
48
-    $arr = array_filter(explode('_', $str));
49
-    $arr = array_map('ucfirst', $arr);
50
-    return join('', $arr);
45
+	foreach ($clear as $item) {
46
+		$str = str_ireplace($item, '', $str);
47
+	}
48
+	$arr = array_filter(explode('_', $str));
49
+	$arr = array_map('ucfirst', $arr);
50
+	return join('', $arr);
51 51
 }
52 52
 
53 53
 function formParamType($str)
54 54
 {
55
-    switch ($str) {
56
-        case 'text':
57
-            return 'string';
58
-            break;
59
-        case 'date':
60
-            return 'string Y-m-d';
61
-            break;
62
-        case 'datetime':
63
-            return 'string Y-m-d H:i:s';
64
-            break;
65
-    }
66
-    return $str;
55
+	switch ($str) {
56
+		case 'text':
57
+			return 'string';
58
+			break;
59
+		case 'date':
60
+			return 'string Y-m-d';
61
+			break;
62
+		case 'datetime':
63
+			return 'string Y-m-d H:i:s';
64
+			break;
65
+	}
66
+	return $str;
67 67
 }
68 68
 
69 69
 function parseParams($str)
70 70
 {
71
-    if (preg_match('/^(\w+)\s+\((\w+)\)\s+-\s+(.+)/uis', $str, $m)) {
72
-        return [
73
-            'name' => $m[1],
74
-            'type' => $m[2],
75
-            'description' => $m[3],
76
-            'required' => mb_strpos($m[3], 'Необязательный', 0, 'utf-8') === false
77
-        ];
78
-    } else {
79
-        return [];
80
-    }
71
+	if (preg_match('/^(\w+)\s+\((\w+)\)\s+-\s+(.+)/uis', $str, $m)) {
72
+		return [
73
+			'name' => $m[1],
74
+			'type' => $m[2],
75
+			'description' => $m[3],
76
+			'required' => mb_strpos($m[3], 'Необязательный', 0, 'utf-8') === false
77
+		];
78
+	} else {
79
+		return [];
80
+	}
81 81
 }
82 82
 
83 83
 function parseReturns($tdHtml)
84 84
 {
85
-    $uls = pq($tdHtml)->find('ul');
86
-    $returns = [];
87
-    if ($uls->count() == 1 && strpos($tdHtml, 'Каждый элемент') !== false) {
88
-        if (preg_match('/<td>(.)+<ul>/s', $tdHtml, $m)) {
89
-            $ul = "<ul><li>" . trim(strip_tags($m[0])) . "</li></ul>";
90
-            $uls = pq("<td>$ul{$uls->eq(0)->htmlOuter()}</td>")->find('ul');
91
-        }
92
-    }
93
-    if ($uls->count() == 2) {
94
-        $returnParam = parseParams($uls->eq(0)->text());
95
-        $result = [];
96
-        foreach ($uls->eq(1)->find('li') as $param) {
97
-            if ($parsedParam = parseParams(pq($param)->text())) {
98
-                $result[] = $parsedParam;
99
-            }
100
-        }
101
-        $returnParam['result'] = $result;
102
-        $returns[] = $returnParam;
103
-    } else {
104
-        foreach ($uls->eq(0)->find('li') as $param) {
105
-            if ($parsedParam = parseParams(pq($param)->text())) {
106
-                $returns[] = $parsedParam;
107
-            }
108
-        }
109
-    }
110
-    return $returns;
85
+	$uls = pq($tdHtml)->find('ul');
86
+	$returns = [];
87
+	if ($uls->count() == 1 && strpos($tdHtml, 'Каждый элемент') !== false) {
88
+		if (preg_match('/<td>(.)+<ul>/s', $tdHtml, $m)) {
89
+			$ul = "<ul><li>" . trim(strip_tags($m[0])) . "</li></ul>";
90
+			$uls = pq("<td>$ul{$uls->eq(0)->htmlOuter()}</td>")->find('ul');
91
+		}
92
+	}
93
+	if ($uls->count() == 2) {
94
+		$returnParam = parseParams($uls->eq(0)->text());
95
+		$result = [];
96
+		foreach ($uls->eq(1)->find('li') as $param) {
97
+			if ($parsedParam = parseParams(pq($param)->text())) {
98
+				$result[] = $parsedParam;
99
+			}
100
+		}
101
+		$returnParam['result'] = $result;
102
+		$returns[] = $returnParam;
103
+	} else {
104
+		foreach ($uls->eq(0)->find('li') as $param) {
105
+			if ($parsedParam = parseParams(pq($param)->text())) {
106
+				$returns[] = $parsedParam;
107
+			}
108
+		}
109
+	}
110
+	return $returns;
111 111
 }
112 112
 
113 113
 function asTable($array)
114 114
 {
115
-    $header = array_shift($array);
116
-    $content = "\n\n|" . join("|", $header) . "\n";
117
-    $content .= preg_replace('/[^\|]/iu', '-', trim($content)) . "\n";
118
-    foreach ($array as $key => $columns) {
119
-        $content .= "|" . join("|", $columns) . "\n";
120
-    }
121
-    return $content;
115
+	$header = array_shift($array);
116
+	$content = "\n\n|" . join("|", $header) . "\n";
117
+	$content .= preg_replace('/[^\|]/iu', '-', trim($content)) . "\n";
118
+	foreach ($array as $key => $columns) {
119
+		$content .= "|" . join("|", $columns) . "\n";
120
+	}
121
+	return $content;
122 122
 }
123 123
 
124 124
 function asHeader($string)
125 125
 {
126
-    return "\n\n" . $string . "\n" . str_repeat('=', mb_strlen($string, 'utf-8')) . "\n";
126
+	return "\n\n" . $string . "\n" . str_repeat('=', mb_strlen($string, 'utf-8')) . "\n";
127 127
 }
128 128
 
129 129
 function asCode($code)
130 130
 {
131
-    return "`$code`";
131
+	return "`$code`";
132 132
 }
133 133
\ No newline at end of file
Please login to merge, or discard this patch.