Passed
Push — master ( 351308...878789 )
by Alexander
02:24 queued 10s
created

DefaultFormatter::setConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 0
c 0
b 0
f 0
dl 0
loc 2
ccs 1
cts 1
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Vasoft\VersionIncrement\Changelog;
6
7
use Vasoft\VersionIncrement\Commits\CommitCollection;
8
use Vasoft\VersionIncrement\Config;
9
use Vasoft\VersionIncrement\Contract\ChangelogFormatterInterface;
10
11
/**
12
 * It generates a changelog in a default format by iterating through visible sections and their commits.
13
 * This formatter does not preserve or filter scopes; it simply lists all commits under their respective sections.
14
 */
15
final class DefaultFormatter implements ChangelogFormatterInterface
16
{
17
    /**
18
     * Generates a changelog in the default format.
19
     *
20
     * @param CommitCollection $commitCollection a collection of commits grouped into sections
21
     * @param string           $version          the version number for which the changelog is generated
22
     *
23
     * @return string The formatted changelog as a string.
24
     *
25
     * The changelog includes:
26
     * - The version number and date at the top.
27
     * - Sections with their titles.
28
     * - Commits listed under each section without preserving scopes.
29
     */
30 21
    public function __invoke(CommitCollection $commitCollection, string $version): string
31
    {
32 21
        $date = date('Y-m-d');
33 21
        $changelog = "# {$version} ({$date})\n\n";
34 21
        $sections = $commitCollection->getVisibleSections();
35 21
        foreach ($sections as $section) {
36 21
            $changelog .= sprintf("### %s\n", $section->title);
37 21
            foreach ($section->getCommits() as $commit) {
38 21
                $changelog .= "- {$commit->comment}\n";
39
            }
40 21
            $changelog .= "\n";
41
        }
42
43 21
        return $changelog;
44
    }
45
46 21
    public function setConfig(Config $config): void
47
    {
48
        // Do nothing
49 21
    }
50
}
51