Passed
Push — master ( 62f23d...7bf3c6 )
by Aleksandr
02:16
created
src/Client.php 1 patch
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -6,66 +6,66 @@
 block discarded – undo
6 6
 
7 7
 class Client extends ClientAbstract
8 8
 {
9
-    public $apiKey;
10
-    public $url = 'www.turbotext.ru';
11
-    public $protocol = 'http';
12
-    public $method = 'POST';
13
-    public $type = self::TYPE_FORM;
14
-    public $output_type = self::TYPE_JSON;
9
+	public $apiKey;
10
+	public $url = 'www.turbotext.ru';
11
+	public $protocol = 'http';
12
+	public $method = 'POST';
13
+	public $type = self::TYPE_FORM;
14
+	public $output_type = self::TYPE_JSON;
15 15
 
16
-    /**
17
-     * @param array $data
18
-     * @return array|string
19
-     */
20
-    public function prepareData(array $data)
21
-    {
22
-        $data = parent::prepareData($data);
23
-        $data['api_key'] = $this->apiKey;
24
-        return $data;
25
-    }
16
+	/**
17
+	 * @param array $data
18
+	 * @return array|string
19
+	 */
20
+	public function prepareData(array $data)
21
+	{
22
+		$data = parent::prepareData($data);
23
+		$data['api_key'] = $this->apiKey;
24
+		return $data;
25
+	}
26 26
 
27
-    /**
28
-     * @param $urlRequest
29
-     * @param array $data
30
-     * @param string $responseClass
31
-     * @return mixed
32
-     */
33
-    public function getContent($urlRequest, $data = [], $responseClass = '\carono\turbotext\Response')
34
-    {
35
-        try {
36
-            $content = parent::getContent($urlRequest, $data);
37
-            return self::stdClassToResponse($content, $responseClass);
38
-        } catch (\Exception $e) {
39
-            $response = new Response();
40
-            $response->success = false;
41
-            $response->errors = $e->getMessage();
42
-            return $response;
43
-        }
44
-    }
27
+	/**
28
+	 * @param $urlRequest
29
+	 * @param array $data
30
+	 * @param string $responseClass
31
+	 * @return mixed
32
+	 */
33
+	public function getContent($urlRequest, $data = [], $responseClass = '\carono\turbotext\Response')
34
+	{
35
+		try {
36
+			$content = parent::getContent($urlRequest, $data);
37
+			return self::stdClassToResponse($content, $responseClass);
38
+		} catch (\Exception $e) {
39
+			$response = new Response();
40
+			$response->success = false;
41
+			$response->errors = $e->getMessage();
42
+			return $response;
43
+		}
44
+	}
45 45
 
46
-    /**
47
-     * @param $stdClass
48
-     * @param $responseClass
49
-     * @return ResponseAbstract
50
-     */
51
-    protected static function stdClassToResponse($stdClass, $responseClass)
52
-    {
53
-        /**
54
-         * @var ResponseAbstract $response
55
-         */
56
-        $response = new $responseClass();
57
-        foreach ($stdClass as $key => $value) {
58
-            if (method_exists($response, 'getResponseClass') && ($class = $response->getResponseClass($key)) && is_array($value)) {
59
-                foreach ($value as $item) {
60
-                    $response->{$key}[] = self::stdClassToResponse($item, $class);
61
-                }
62
-            } else {
63
-                $response->$key = $value;
64
-            }
65
-        }
66
-        if (isset($response->success)) {
67
-            $response->success = filter_var($response->success, FILTER_VALIDATE_BOOLEAN);
68
-        }
69
-        return $response;
70
-    }
46
+	/**
47
+	 * @param $stdClass
48
+	 * @param $responseClass
49
+	 * @return ResponseAbstract
50
+	 */
51
+	protected static function stdClassToResponse($stdClass, $responseClass)
52
+	{
53
+		/**
54
+		 * @var ResponseAbstract $response
55
+		 */
56
+		$response = new $responseClass();
57
+		foreach ($stdClass as $key => $value) {
58
+			if (method_exists($response, 'getResponseClass') && ($class = $response->getResponseClass($key)) && is_array($value)) {
59
+				foreach ($value as $item) {
60
+					$response->{$key}[] = self::stdClassToResponse($item, $class);
61
+				}
62
+			} else {
63
+				$response->$key = $value;
64
+			}
65
+		}
66
+		if (isset($response->success)) {
67
+			$response->success = filter_var($response->success, FILTER_VALIDATE_BOOLEAN);
68
+		}
69
+		return $response;
70
+	}
71 71
 }
72 72
\ No newline at end of file
Please login to merge, or discard this patch.
codegen/generate.php 1 patch
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -15,45 +15,45 @@
 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 = parseParamsFromQuery($tr->find('td')->eq(2)->find('li'));
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 = parseParamsFromQuery($tr->find('td')->eq(2)->find('li'));
46 46
 
47
-        $returns = parseReturns($uls = $tr->find('td')->eq(3)->htmlOuter());
48
-        $method = [
49
-            'name' => $name,
50
-            'description' => $tr->find('td')->eq(1)->text(),
51
-            'params' => $params,
52
-            'returns' => $returns
53
-        ];
54
-        $item['methods'][] = $method;
55
-    }
56
-    $data[] = $item;
47
+		$returns = parseReturns($uls = $tr->find('td')->eq(3)->htmlOuter());
48
+		$method = [
49
+			'name' => $name,
50
+			'description' => $tr->find('td')->eq(1)->text(),
51
+			'params' => $params,
52
+			'returns' => $returns
53
+		];
54
+		$item['methods'][] = $method;
55
+	}
56
+	$data[] = $item;
57 57
 };
58 58
 file_put_contents('data.json', json_encode($data));
59 59
 
Please login to merge, or discard this patch.
codegen/func.php 1 patch
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -2,133 +2,133 @@
 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'] . "** ({$param['type']}) - " . stripLines($param['description']);
31
+	return '**' . $param['name'] . "** ({$param['type']}) - " . 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 join('', $arr);
49
+	$arr = array_filter(explode('_', $str));
50
+	$arr = array_map('ucfirst', $arr);
51
+	$arr[0] = lcfirst($arr[0]);
52
+	return join('', $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 join('', $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 join('', $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
-    }
78
-    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
+	}
78
+	return $str;
79 79
 }
80 80
 
81 81
 function parseParams($str)
82 82
 {
83
-    if (preg_match('/^(\w+)\s+\((\w+)\)\s+-\s+(.+)/uis', $str, $m)) {
84
-        return [
85
-            'name' => $m[1],
86
-            'type' => $m[2],
87
-            'description' => $m[3],
88
-            'required' => mb_strpos($m[3], 'Необязательный', 0, 'utf-8') === false
89
-        ];
90
-    } else {
91
-        return [];
92
-    }
83
+	if (preg_match('/^(\w+)\s+\((\w+)\)\s+-\s+(.+)/uis', $str, $m)) {
84
+		return [
85
+			'name' => $m[1],
86
+			'type' => $m[2],
87
+			'description' => $m[3],
88
+			'required' => mb_strpos($m[3], 'Необязательный', 0, 'utf-8') === false
89
+		];
90
+	} else {
91
+		return [];
92
+	}
93 93
 }
94 94
 
95 95
 function parseReturns($tdHtml)
96 96
 {
97
-    $uls = pq($tdHtml)->find('ul');
98
-    if ($uls->count() == 1 && strpos($tdHtml, 'Каждый элемент') !== false) {
99
-        if (preg_match('/<td>(.)+<ul>/s', $tdHtml, $m)) {
100
-            $ul = "<ul><li>" . trim(strip_tags($m[0])) . "</li></ul>";
101
-            $uls = pq("<td>$ul{$uls->eq(0)->htmlOuter()}</td>")->find('ul');
102
-        }
103
-    }
104
-    $count = $uls->count();
105
-    $parsing = parseParamsFromQuery($uls->eq($count == 2 ? 1 : 0)->find('li'));
106
-    if ($count == 2) {
107
-        $returnParam = parseParams($uls->eq(0)->text());
108
-        $returnParam['result'] = $parsing;
109
-        return [$returnParam];
110
-    } else {
111
-        return $parsing;
112
-    }
97
+	$uls = pq($tdHtml)->find('ul');
98
+	if ($uls->count() == 1 && strpos($tdHtml, 'Каждый элемент') !== false) {
99
+		if (preg_match('/<td>(.)+<ul>/s', $tdHtml, $m)) {
100
+			$ul = "<ul><li>" . trim(strip_tags($m[0])) . "</li></ul>";
101
+			$uls = pq("<td>$ul{$uls->eq(0)->htmlOuter()}</td>")->find('ul');
102
+		}
103
+	}
104
+	$count = $uls->count();
105
+	$parsing = parseParamsFromQuery($uls->eq($count == 2 ? 1 : 0)->find('li'));
106
+	if ($count == 2) {
107
+		$returnParam = parseParams($uls->eq(0)->text());
108
+		$returnParam['result'] = $parsing;
109
+		return [$returnParam];
110
+	} else {
111
+		return $parsing;
112
+	}
113 113
 }
114 114
 
115 115
 function asTable($array)
116 116
 {
117
-    $header = array_shift($array);
118
-    $content = "\n\n|" . join("|", $header) . "\n";
119
-    $content .= preg_replace('/[^\|]/iu', '-', trim($content)) . "\n";
120
-    foreach ($array as $key => $columns) {
121
-        $content .= "|" . join("|", $columns) . "\n";
122
-    }
123
-    return $content;
117
+	$header = array_shift($array);
118
+	$content = "\n\n|" . join("|", $header) . "\n";
119
+	$content .= preg_replace('/[^\|]/iu', '-', trim($content)) . "\n";
120
+	foreach ($array as $key => $columns) {
121
+		$content .= "|" . join("|", $columns) . "\n";
122
+	}
123
+	return $content;
124 124
 }
125 125
 
126 126
 function asHeader($string)
127 127
 {
128
-    return "\n\n" . $string . "\n" . str_repeat('=', mb_strlen($string, 'utf-8')) . "\n";
128
+	return "\n\n" . $string . "\n" . str_repeat('=', mb_strlen($string, 'utf-8')) . "\n";
129 129
 }
130 130
 
131 131
 function asCode($code)
132 132
 {
133
-    return "`$code`";
133
+	return "`$code`";
134 134
 }
135 135
\ No newline at end of file
Please login to merge, or discard this patch.