GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 6afad4...c7cb95 )
by Anton
02:17
created

ApiGen   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 49
c 1
b 0
f 0
dl 0
loc 77
rs 10
wmc 11

2 Methods

Rating   Name   Duplication   Size   Complexity  
A markdown() 0 30 3
B parse() 0 39 8
1
<?php
2
/* (c) Anton Medvedev <[email protected]>
3
 *
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 */
7
8
namespace Deployer\Documentation;
9
10
class ApiGen
11
{
12
    private $fns = [];
13
14
    public function parse(string $source)
15
    {
16
        $comment = '';
17
        $params = '';
18
19
        $state = 'root';
20
        foreach (explode("\n", $source) as $lineNumber => $line) {
21
            switch ($state) {
22
                case 'root':
23
                    if (str_starts_with($line, '/**')) {
24
                        $state = 'comment';
25
                        break;
26
                    }
27
                    if (str_starts_with($line, 'function')) {
28
                        $signature = preg_replace('/^function\s+/', '', $line);
29
                        $funcName = preg_replace('/\(.+$/', '', $signature);
30
                        $this->fns[] = [
31
                            'comment' => $comment,
32
                            'params' => $params,
33
                            'funcName' => $funcName,
34
                            'signature' => $signature,
35
                        ];
36
                        $comment = '';
37
                        $params = '';
38
                        break;
39
                    }
40
                    break;
41
42
                case 'comment':
43
                    if (str_ends_with($line, '*/')) {
44
                        $state = 'root';
45
                        break;
46
                    }
47
                    if (str_starts_with($line, ' * @')) {
48
                        $params .= $line . "\n";
49
                        break;
50
                    }
51
                    $comment .= preg_replace('/^\s\*\s?/', '', $line) . "\n";
52
                    break;
53
            }
54
        }
55
    }
56
57
    public function markdown()
58
    {
59
        $output = "API Reference\n\n";
60
61
        foreach ($this->fns as $fn) {
62
            ['funcName' => $funcName] = $fn;
63
            $output .= " * [`$funcName()`](#$funcName)\n";
64
        }
65
        $output .= "\n";
66
67
        foreach ($this->fns as $fn) {
68
            [
69
                'comment' => $comment,
70
                'params' => $params,
71
                'funcName' => $funcName,
72
                'signature' => $signature,
73
            ] = $fn;
74
75
            $output .= <<<MD
76
## $funcName()
77
78
```php
79
$signature
80
```
81
82
$comment
83
84
MD;
85
        }
86
        return $output;
87
    }
88
}
89