Passed
Push — master ( 247b33...4111ab )
by Jonathan
02:02 queued 18s
created

ChangelogGenerator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 34
ccs 0
cts 22
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A generate() 0 20 3
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ChangelogGenerator;
6
7
use Symfony\Component\Console\Output\OutputInterface;
8
use function count;
9
use function sprintf;
10
11
class ChangelogGenerator
12
{
13
    /** @var IssueRepository */
14
    private $issueRepository;
15
16
    /** @var IssueGrouper */
17
    private $issueGrouper;
18
19
    public function __construct(IssueRepository $issueRepository, IssueGrouper $issueGrouper)
20
    {
21
        $this->issueRepository = $issueRepository;
22
        $this->issueGrouper    = $issueGrouper;
23
    }
24
25
    public function generate(string $user, string $repository, string $milestone, OutputInterface $output) : void
26
    {
27
        $issues      = $this->issueRepository->getMilestoneIssues($user, $repository, $milestone);
28
        $issueGroups = $this->issueGrouper->groupIssues($issues);
29
30
        $output->writeln([
31
            sprintf('## %s', $milestone),
32
            '',
33
            sprintf('Total issues resolved: **%s**', count($issues)),
34
        ]);
35
36
        foreach ($issueGroups as $issueGroup) {
37
            $output->writeln([
38
                '',
39
                sprintf('### %s', $issueGroup->getName()),
40
                '',
41
            ]);
42
43
            foreach ($issueGroup->getIssues() as $issue) {
44
                $output->writeln($issue->render());
45
            }
46
        }
47
    }
48
}
49