Skip to content

Commit 3d4768d

Browse files
committed
AC-14557:: False positives in the backward-incompatible changes report (SVC)
1 parent 1b3b365 commit 3d4768d

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/Analyzer/ClassMethodAnalyzer.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,24 @@ protected function reportChanged($report, $contextBefore, $contextAfter, $method
266266
$beforeParam = $paramsBefore[$i];
267267
$afterParam = $paramsAfter[$i];
268268

269+
// $beforeParam->
270+
269271
$beforeType = $beforeParam->type;
270272
$afterType = $afterParam->type;
273+
// $beforeParam->default->
274+
275+
$beforeNullable = $this->isNullable($beforeType);
276+
$afterNullable = $this->isNullable($afterType);
277+
278+
$beforeTypeName = $this->getTypeName($beforeType);
279+
$afterTypeName = $this->getTypeName($afterType);
280+
281+
if ($beforeNullable !== $afterNullable && $beforeTypeName === $afterTypeName) {
282+
echo "️Nullable type change detected for parameter \${$beforeParam->var->name}:\n";
283+
echo "Before: " . ($beforeNullable ? '?' : '') . $beforeTypeName . "\n";
284+
echo "After: " . ($afterNullable ? '?' : '') . $afterTypeName . "\n";
285+
}
286+
271287

272288
$beforeDefaultIsNull = isset($beforeParam->default) && $beforeParam->default->value === null;
273289
print_r("Default value: $beforeParam->default->value\n");
@@ -421,6 +437,19 @@ protected function reportChanged($report, $contextBefore, $contextAfter, $method
421437
}
422438
}
423439

440+
private function isNullable($type): bool {
441+
return $type instanceof \PhpParser\Node\NullableType;
442+
}
443+
444+
private function getTypeName($type): ?string {
445+
if ($type instanceof \PhpParser\Node\NullableType) {
446+
return $type->type instanceof \PhpParser\Node\Identifier ? $type->type->name : null;
447+
} elseif ($type instanceof \PhpParser\Node\Identifier) {
448+
return $type->name;
449+
}
450+
return null; // For union types or no type
451+
}
452+
424453
/**
425454
* Checks if return type declaration or annotation was changed
426455
*

0 commit comments

Comments
 (0)