Skip to content

Commit 0054175

Browse files
committed
AC-15344:: Add change level to breaking change table report in SVC
1 parent 4c476cb commit 0054175

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

src/Analyzer/ClassMethodAnalyzer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,8 @@ protected function reportChanged($report, $contextBefore, $contextAfter, $method
259259
$report->add($this->context, $data);
260260
$signatureChanged = true;
261261
} elseif ($signatureChanges['parameter_typing_changed']) {
262-
if ($signatureChanges['parameter_nullable_type_added']) {
262+
if ($signatureChanges['parameter_nullable_type_added']
263+
|| $signatureChanges['parameter_nullable_type_removed']) {
263264
$data = new ClassMethodParameterTypingChangedNullable(
264265
$this->context,
265266
$this->fileAfter,
@@ -465,8 +466,7 @@ private function isReturnsEqualByNullability(ClassMethod $before, ClassMethod $a
465466
*/
466467
private function getDocReturnDeclaration(ClassMethod $method)
467468
{
468-
if (
469-
($parsedComment = $method->getAttribute('docCommentParsed'))
469+
if (($parsedComment = $method->getAttribute('docCommentParsed'))
470470
&& isset($parsedComment['return'])
471471
) {
472472
if ($parsedComment['return'][0] instanceof NullableType) {

src/Comparator/Signature.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,14 @@ public static function analyze(array $parametersA, array $parametersB): array
147147
if ($parametersA[$i]->type !== null && $parametersB[$i]->type !== null) {
148148
$changes['parameter_typing_changed'] = true;
149149
// Custom: detect nullable added
150-
if (
151-
$typeBefore instanceof \PhpParser\Node\NullableType
150+
if ($typeBefore instanceof \PhpParser\Node\NullableType
152151
&& !$typeAfter instanceof \PhpParser\Node\NullableType
153152
) {
154153
$changes['parameter_nullable_type_added'] = true;
154+
} elseif (!$typeBefore instanceof \PhpParser\Node\NullableType
155+
&& $typeAfter instanceof \PhpParser\Node\NullableType
156+
) {
157+
$changes['parameter_nullable_type_removed'] = true;
155158
}
156159
} elseif ($parametersA[$i]->type !== null) {
157160
$changes['parameter_typing_removed'] = true;

src/Reporter/BreakingChangeTableReporter.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class BreakingChangeTableReporter extends TableReporter
1616
private $breakChangeLevels = [
1717
Level::MAJOR,
1818
Level::MINOR,
19+
Level::PATCH,
1920
];
2021

2122
/**
@@ -96,7 +97,7 @@ private function outputChangeReport(OutputInterface $output, Report $report, $co
9697
protected function outputTable(OutputInterface $output, Report $report, $context)
9798
{
9899
$table = new HtmlTableRenderer($output);
99-
$table->setHeaders(['What changed', 'How it changed']);
100+
$table->setHeaders(['<strong>Change Level</strong>', '<strong>What Changed</strong>', '<strong>How It Changed</strong>']);
100101
$rows = [];
101102
foreach (Level::asList('desc') as $level) {
102103
if (!in_array($level, $this->breakChangeLevels)) {
@@ -105,15 +106,36 @@ protected function outputTable(OutputInterface $output, Report $report, $context
105106
$reportForLevel = $report[$context][$level];
106107
/** @var \PHPSemVerChecker\Operation\Operation $operation */
107108
foreach ($reportForLevel as $operation) {
109+
$levelLabel = $this->getLevelLabel($level);
108110
$target = $operation->getTarget();
109111
$reason = $operation->getReason();
110-
$rows[] = [$target, $reason];
112+
$rows[] = [$levelLabel, $target, $reason];
111113
}
112114
}
113115
$table->setRows($rows);
114116
$table->render();
115117
}
116118

119+
/**
120+
* Get a human-readable label for the change level
121+
*
122+
* @param int $level
123+
* @return string
124+
*/
125+
private function getLevelLabel(int $level): string
126+
{
127+
switch ($level) {
128+
case Level::MAJOR:
129+
return '<span style="color: #d73a49; font-weight: bold;">MAJOR (Breaking)</span>';
130+
case Level::MINOR:
131+
return '<span style="color: #f6a434; font-weight: bold;">MINOR (Non-breaking)</span>';
132+
case Level::PATCH:
133+
return '<span style="color: #28a745; font-weight: bold;">PATCH</span>';
134+
default:
135+
return 'UNKNOWN';
136+
}
137+
}
138+
117139
/**
118140
* Generate the HTML header line for a report section
119141
*

0 commit comments

Comments
 (0)