IssueFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 38
rs 10
ccs 17
cts 17
cp 1
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getTitle() 0 6 1
A getLabels() 0 7 1
A create() 0 10 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