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

ChangelogGenerator::generate()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 0
cts 17
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 13
nc 3
nop 4
crap 12
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