Passed
Push — master ( b917eb...fefbb9 )
by Aleksandr
02:16
created

formMethodName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
function formParamLine($param)
4
{
5
    return '**' . $param['name'] . "** ({$param['type']}) - " . stripLines($param['description']);
6
}
7
8
function stripLines($str)
9
{
10
    $str = str_replace("\n", " ", $str);
11
    $str = preg_replace('/[\s]{2,}/', ' ', $str);
12
    return $str;
13
}
14
15
function formMethodName($str)
16
{
17
    $arr = array_filter(explode('_', $str));
18
    $arr = array_map('ucfirst', $arr);
19
    $arr[0] = lcfirst($arr[0]);
20
    return join('', $arr);
21
}
22
23
function formClassName($str)
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);
36
}
37
38
function formParamType($str)
39
{
40
    if ($str == 'text') {
41
        return 'string';
42
    }
43
    return $str;
44
}
45
46
function parseParams($str)
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
    }
58
}
59
60
function parseReturns($tdHtml)
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 View Code Duplication
        foreach ($uls->eq(1)->find('li') as $param) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
74
            if ($parsedParam = parseParams(pq($param)->text())) {
75
                $result[] = $parsedParam;
76
            }
77
        }
78
        $returnParam['result'] = $result;
79
        $returns[] = $returnParam;
80
    } else {
81 View Code Duplication
        foreach ($uls->eq(0)->find('li') as $param) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
82
            if ($parsedParam = parseParams(pq($param)->text())) {
83
                $returns[] = $parsedParam;
84
            }
85
        }
86
    }
87
    return $returns;
88
}
89
90
function asTable($array)
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;
99
}
100
101
function asHeader($string)
102
{
103
    return "\n\n" . $string . "\n" . str_repeat('=', mb_strlen($string, 'utf-8')) . "\n";
104
}
105
106
function asCode($code)
107
{
108
    return "`$code`";
109
}