Passed
Push — master ( 472e0b...efc763 )
by Aleksandr
02:00
created

clearFolder()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
cc 3
eloc 4
nc 3
nop 1
rs 9.4285
1
<?php
2
function clearFolder($folder)
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);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for unlink(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

7
            /** @scrutinizer ignore-unhandled */ @unlink($file);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
8
        }
9
    }
10
}
11
12
function stripAndWordWrap($str)
13
{
14
    return wordwrap(stripSpaces($str), 180) . "\n";
15
}
16
17
function formParamLine($param)
18
{
19
    return '**' . $param['name'] . "** ({$param['type']}) - " . stripLines($param['description']);
20
}
21
22
function stripSpaces($str)
23
{
24
    $str = preg_replace('/[\s]{2,}/', " ", $str);
25
    return $str;
26
}
27
28
function stripLines($str)
29
{
30
    $str = str_replace("\n", " ", $str);
31
    $str = stripSpaces($str);
32
    return $str;
33
}
34
35
function formMethodName($str)
36
{
37
    $arr = array_filter(explode('_', $str));
38
    $arr = array_map('ucfirst', $arr);
39
    $arr[0] = lcfirst($arr[0]);
40
    return join('', $arr);
41
}
42
43
function formClassName($str, $clear = ['get_', '_array'])
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);
51
}
52
53
function formParamType($str)
54
{
55
    if ($str == 'text') {
56
        return 'string';
57
    }
58
    return $str;
59
}
60
61
function parseParams($str)
62
{
63
    if (preg_match('/^(\w+)\s+\((\w+)\)\s+-\s+(.+)/uis', $str, $m)) {
64
        return [
65
            'name' => $m[1],
66
            'type' => $m[2],
67
            'description' => $m[3],
68
            'required' => mb_strpos($m[3], 'Необязательный', 0, 'utf-8') === false
69
        ];
70
    } else {
71
        return [];
72
    }
73
}
74
75
function parseReturns($tdHtml)
76
{
77
    $uls = pq($tdHtml)->find('ul');
78
    $returns = [];
79
    if ($uls->count() == 1 && strpos($tdHtml, 'Каждый элемент') !== false) {
80
        if (preg_match('/<td>(.)+<ul>/s', $tdHtml, $m)) {
81
            $ul = "<ul><li>" . trim(strip_tags($m[0])) . "</li></ul>";
82
            $uls = pq("<td>$ul{$uls->eq(0)->htmlOuter()}</td>")->find('ul');
83
        }
84
    }
85
    if ($uls->count() == 2) {
86
        $returnParam = parseParams($uls->eq(0)->text());
87
        $result = [];
88 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...
89
            if ($parsedParam = parseParams(pq($param)->text())) {
90
                $result[] = $parsedParam;
91
            }
92
        }
93
        $returnParam['result'] = $result;
94
        $returns[] = $returnParam;
95
    } else {
96 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...
97
            if ($parsedParam = parseParams(pq($param)->text())) {
98
                $returns[] = $parsedParam;
99
            }
100
        }
101
    }
102
    return $returns;
103
}
104
105
function asTable($array)
106
{
107
    $header = array_shift($array);
108
    $content = "\n\n|" . join("|", $header) . "\n";
109
    $content .= preg_replace('/[^\|]/iu', '-', trim($content)) . "\n";
110
    foreach ($array as $key => $columns) {
111
        $content .= "|" . join("|", $columns) . "\n";
112
    }
113
    return $content;
114
}
115
116
function asHeader($string)
117
{
118
    return "\n\n" . $string . "\n" . str_repeat('=', mb_strlen($string, 'utf-8')) . "\n";
119
}
120
121
function asCode($code)
122
{
123
    return "`$code`";
124
}