|
10 | 10 | use PHPSemVerChecker\Report\Report;
|
11 | 11 | use PHPSemVerChecker\SemanticVersioning\Level;
|
12 | 12 | use Symfony\Component\Console\Output\OutputInterface;
|
| 13 | +use PHPSemVerChecker\Operation\Operation; |
13 | 14 |
|
14 | 15 | class BreakingChangeTableReporter extends TableReporter
|
15 | 16 | {
|
16 | 17 | private $breakChangeLevels = [
|
17 | 18 | Level::MAJOR,
|
18 | 19 | Level::MINOR,
|
| 20 | + Level::PATCH, |
19 | 21 | ];
|
20 | 22 |
|
21 | 23 | /**
|
@@ -96,24 +98,71 @@ private function outputChangeReport(OutputInterface $output, Report $report, $co
|
96 | 98 | protected function outputTable(OutputInterface $output, Report $report, $context)
|
97 | 99 | {
|
98 | 100 | $table = new HtmlTableRenderer($output);
|
99 |
| - $table->setHeaders(['What changed', 'How it changed']); |
| 101 | + $table->setHeaders(['<strong>Change Level</strong>', '<strong>What Changed</strong>', '<strong>How It Changed</strong>']); |
100 | 102 | $rows = [];
|
101 | 103 | foreach (Level::asList('desc') as $level) {
|
102 | 104 | if (!in_array($level, $this->breakChangeLevels)) {
|
103 | 105 | continue;
|
104 | 106 | }
|
105 | 107 | $reportForLevel = $report[$context][$level];
|
106 |
| - /** @var \PHPSemVerChecker\Operation\Operation $operation */ |
| 108 | + /** @var Operation $operation */ |
107 | 109 | foreach ($reportForLevel as $operation) {
|
| 110 | + // Skip private method/property changes as they shouldn't be in breaking change reports |
| 111 | + if ($this->isPrivateMemberChange($operation)) { |
| 112 | + continue; |
| 113 | + } |
| 114 | + |
| 115 | + $levelLabel = $this->getLevelLabel($level); |
108 | 116 | $target = $operation->getTarget();
|
109 | 117 | $reason = $operation->getReason();
|
110 |
| - $rows[] = [$target, $reason]; |
| 118 | + $rows[] = [$levelLabel, $target, $reason]; |
111 | 119 | }
|
112 | 120 | }
|
113 | 121 | $table->setRows($rows);
|
114 | 122 | $table->render();
|
115 | 123 | }
|
116 | 124 |
|
| 125 | + /** |
| 126 | + * Get a human-readable label for the change level |
| 127 | + * |
| 128 | + * @param int $level |
| 129 | + * @return string |
| 130 | + */ |
| 131 | + private function getLevelLabel(int $level): string |
| 132 | + { |
| 133 | + switch ($level) { |
| 134 | + case Level::MAJOR: |
| 135 | + return '<span style="color: #d73a49; font-weight: bold;">MAJOR (Breaking)</span>'; |
| 136 | + case Level::MINOR: |
| 137 | + return '<span style="color: #f6a434; font-weight: bold;">MINOR (Non-breaking)</span>'; |
| 138 | + case Level::PATCH: |
| 139 | + return '<span style="color: #28a745; font-weight: bold;">PATCH</span>'; |
| 140 | + default: |
| 141 | + return 'UNKNOWN'; |
| 142 | + } |
| 143 | + } |
| 144 | + |
| 145 | + /** |
| 146 | + * Check if the operation represents a private method or property change |
| 147 | + * |
| 148 | + * Private changes are filtered out as they don't affect the public API contract. |
| 149 | + * |
| 150 | + * @param Operation $operation |
| 151 | + * @return bool |
| 152 | + */ |
| 153 | + private function isPrivateMemberChange(Operation $operation): bool |
| 154 | + { |
| 155 | + $target = $operation->getTarget(); |
| 156 | + $reason = $operation->getReason(); |
| 157 | + |
| 158 | + // Simple string check for 'private' keyword (covers all cases) |
| 159 | + if (stripos($target, 'private') !== false || stripos($reason, 'private') !== false) { |
| 160 | + return true; |
| 161 | + } |
| 162 | + |
| 163 | + return false; |
| 164 | + } |
| 165 | + |
117 | 166 | /**
|
118 | 167 | * Generate the HTML header line for a report section
|
119 | 168 | *
|
|
0 commit comments