IssueFactory::getLabels()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
ccs 4
cts 4
cp 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ChangelogGenerator;
6
7
use function array_column;
8
use function htmlentities;
9
use function sort;
10
use function str_replace;
11
12
use const ENT_COMPAT;
13
14
class IssueFactory
15
{
16
    /**
17
     * @param mixed[] $issue
18
     */
19 1
    public function create(array $issue): Issue
20
    {
21 1
        return new Issue(
22 1
            $issue['number'],
23 1
            $this->getTitle($issue['title']),
24 1
            $issue['body'],
25 1
            $issue['html_url'],
26 1
            $issue['user']['login'],
27 1
            $this->getLabels($issue['labels']),
28 1
            isset($issue['pull_request'])
29
        );
30
    }
31
32 1
    private function getTitle(string $title): string
33
    {
34 1
        $title = htmlentities($title, ENT_COMPAT, 'UTF-8');
35 1
        $title = str_replace(['[', ']', '_'], ['&#91;', '&#93;', '&#95;'], $title);
36
37 1
        return $title;
38
    }
39
40
    /**
41
     * @param string[] $labels
42
     *
43
     * @return string[]
44
     */
45 1
    private function getLabels(array $labels): array
46
    {
47 1
        $labels = array_column($labels, 'name');
48
49 1
        sort($labels);
50
51 1
        return $labels;
52
    }
53
}
54