Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

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.
Passed
Pull Request — dev-extbase-fluid (#771)
by
unknown
03:16
created

RstSection::format()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 6
c 1
b 0
f 0
nc 4
nop 2
dl 0
loc 11
rs 10
1
<?php
2
3
namespace Kitodo\Dlf\Common\DbDocs;
4
5
use Kitodo\Dlf\Common\Helper;
6
7
/**
8
 * Simple utility to write .rst (reStructuredText).
9
 */
10
class RstSection
11
{
12
    /** @var string */
13
    protected $header = '';
14
15
    /** @var string */
16
    protected $text = '';
17
18
    /** @var RstSection[] */
19
    protected $subsections = [];
20
21
    public static function format(string $text, array $format = [])
22
    {
23
        if (!empty($text)) {
24
            if ($format['bold'] ?? false) {
25
                $text = '**' . $text . '**';
26
            } elseif ($format['italic'] ?? false) {
27
                $text = '*' . $text . '*';
28
            }
29
        }
30
31
        return $text;
32
    }
33
34
    public static function paragraphs(array $paragraphs)
35
    {
36
        return implode("\n\n", Helper::withoutEmpty($paragraphs));
37
    }
38
39
    public function subsection()
40
    {
41
        $section = new static();
42
        $this->subsections[] = $section;
43
        return $section;
44
    }
45
46
    public function setHeader(string $text)
47
    {
48
        $this->header = $text;
49
    }
50
51
    public function addText(string $text)
52
    {
53
        if (!empty($text)) {
54
            $this->text .= $text . "\n\n";
55
        }
56
    }
57
58
    public function addTable(array $rows, array $headerRows)
59
    {
60
        $numHeaderRows = count($headerRows);
61
62
        $tableRst = <<<RST
63
.. t3-field-list-table::
64
   :header-rows: $numHeaderRows
65
66
67
RST;
68
69
        // Pattern for a row:
70
        //
71
        // - :key1:      value
72
        //   :key2:      another
73
        //               value that may
74
        //               span multiple lines
75
        //
76
        foreach (array_merge($headerRows, $rows) as $row) {
77
            $entry = '';
78
            foreach ($row as $key => $value) {
79
                $valueLines = explode("\n", $value);
80
                $numLines = count($valueLines);
81
                for ($i = 0; $i < $numLines; $i++) {
82
                    $prefix = $i === 0
83
                        ? '     :' . $key . ':'
84
                        : '';
85
86
                    $entry .= str_pad($prefix, 32) . trim($valueLines[$i]) . "\n";
87
                }
88
            }
89
90
            if (!empty($entry)) {
91
                $entry[3] = '-';
92
                $entry .= "\n";
93
            }
94
95
            $tableRst .= $entry;
96
        }
97
98
        $this->addText($tableRst);
99
    }
100
101
    public function render(int $level = 0)
102
    {
103
        $result = '';
104
105
        $result .= $this->renderHeader($level);
106
        $result .= $this->text;
107
108
        foreach ($this->subsections as $section) {
109
            $result .= $section->render($level + 1);
110
            $result .= "\n";
111
        }
112
113
        return $result;
114
    }
115
116
    protected function renderHeader(int $level)
117
    {
118
        $result = '';
119
120
        $headerChar = ['=', '=', '-', '~', '"'][$level];
121
        $headerSep = str_repeat($headerChar, mb_strlen($this->header));
122
123
        if ($level === 0) {
124
            $result .= $headerSep . "\n";
125
        }
126
127
        $result .= $this->header . "\n" . $headerSep . "\n\n";
128
129
        return $result;
130
    }
131
}
132