Completed
Push — master ( 065f8e...3ac984 )
by Jonathan
10s
created

ChangelogGenerator::getNumberOfIssues()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ChangelogGenerator;
6
7
use Symfony\Component\Console\Output\OutputInterface;
8
use function array_filter;
9
use function count;
10
use function sprintf;
11
12
class ChangelogGenerator
13
{
14
    /** @var IssueRepository */
15
    private $issueRepository;
16
17
    /** @var IssueGrouper */
18
    private $issueGrouper;
19
20 1
    public function __construct(IssueRepository $issueRepository, IssueGrouper $issueGrouper)
21
    {
22 1
        $this->issueRepository = $issueRepository;
23 1
        $this->issueGrouper    = $issueGrouper;
24 1
    }
25
26 1
    public function generate(string $user, string $repository, string $milestone, OutputInterface $output) : void
27
    {
28 1
        $issues      = $this->issueRepository->getMilestoneIssues($user, $repository, $milestone);
29 1
        $issueGroups = $this->issueGrouper->groupIssues($issues);
30
31 1
        $output->writeln([
32 1
            sprintf('## %s', $milestone),
33 1
            '',
34 1
            sprintf('Total issues resolved: **%s**', $this->getNumberOfIssues($issues)),
35 1
            sprintf('Total pull requests resolved: **%s**', $this->getNumberOfPullRequests($issues)),
36
        ]);
37
38 1
        foreach ($issueGroups as $issueGroup) {
39 1
            $output->writeln([
40 1
                '',
41 1
                sprintf('### %s', $issueGroup->getName()),
42 1
                '',
43
            ]);
44
45 1
            foreach ($issueGroup->getIssues() as $issue) {
46 1
                $output->writeln($issue->render());
47
            }
48
        }
49 1
    }
50
51
    /**
52
     * @param Issue[] $issues
53
     */
54 1
    private function getNumberOfIssues(array $issues) : int
55
    {
56
        return count(array_filter($issues, function (Issue $issue) : bool {
57 1
            return ! $issue->isPullRequest();
58 1
        }));
59
    }
60
61
    /**
62
     * @param Issue[] $issues
63
     */
64 1
    private function getNumberOfPullRequests(array $issues) : int
65
    {
66
        return count(array_filter($issues, function (Issue $issue) : bool {
67 1
            return $issue->isPullRequest();
68 1
        }));
69
    }
70
}
71