Completed
Push — master ( 109027...065f8e )
by Jonathan
11s
created

IssueFactory::getLabels()   A

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 9.4285
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 const ENT_COMPAT;
8
use function array_column;
9
use function htmlentities;
10
use function sort;
11
use function str_replace;
12
13
class IssueFactory
14
{
15
    /**
16
     * @param mixed[] $issue
17
     */
18 1
    public function create(array $issue) : Issue
19
    {
20 1
        return new Issue(
21 1
            $issue['number'],
22 1
            $this->getTitle($issue['title']),
23 1
            $issue['body'],
24 1
            $issue['html_url'],
25 1
            $issue['user']['login'],
26 1
            $this->getLabels($issue['labels']),
27 1
            isset($issue['pull_request']) ? true : false
28
        );
29
    }
30
31 1
    private function getTitle(string $title) : string
32
    {
33 1
        $title = htmlentities($title, ENT_COMPAT, 'UTF-8');
34 1
        $title = str_replace(['[', ']', '_'], ['&#91;', '&#92;', '&#95;'], $title);
35
36 1
        return $title;
37
    }
38
39
    /**
40
     * @param string[] $labels
41
     *
42
     * @return string[]
43
     */
44 1
    private function getLabels(array $labels) : array
45
    {
46 1
        $labels = array_column($labels, 'name');
47
48 1
        sort($labels);
49
50 1
        return $labels;
51
    }
52
}
53