From 53b3582f7b1048f508de2029a75bb107f12b4a0a Mon Sep 17 00:00:00 2001 From: "Reymart A. Calicdan" Date: Tue, 18 Aug 2026 22:58:37 +0800 Subject: [PATCH] Fix lsp renaming bug where contructor dont follow typephp type annotation enforement --- src/Contract/ContractParser.php | 18 +++++++++++++--- .../BaseShopwareExceptionFixture.php | 21 +++++++++++++++++++ .../Exception/TableHelperExceptionFixture.php | 15 +++++++++++++ .../ConstructorInheritanceMismatchTest.php | 16 ++++++++++++++ 4 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 tests/Fixtures/Shopware/Exception/BaseShopwareExceptionFixture.php create mode 100644 tests/Fixtures/Shopware/Exception/TableHelperExceptionFixture.php create mode 100644 tests/TypeChecking/InheritanceAndAttributes/ConstructorInheritanceMismatchTest.php diff --git a/src/Contract/ContractParser.php b/src/Contract/ContractParser.php index 44d7588..744f329 100644 --- a/src/Contract/ContractParser.php +++ b/src/Contract/ContractParser.php @@ -559,6 +559,7 @@ private static function parseMethodHierarchyDocs( $baseParamNames = []; $baseParamSet = []; $baseParamVariadic = []; + $isConstructor = ($ref->getName() === '__construct'); foreach ($baseParams as $idx => $p) { $baseParamNames[$idx] = $p->getName(); @@ -597,7 +598,13 @@ private static function parseMethodHierarchyDocs( $paramTags = DocblockExtractor::getParamTags($phpDocNode); foreach ($paramTags as $paramName => $paramTag) { - $targetParamName = self::resolveTargetParamName($paramName, $baseParamSet, $baseParamNames, $hierNameToIndex); + $targetParamName = self::resolveTargetParamName( + $paramName, + $baseParamSet, + $baseParamNames, + $hierNameToIndex, + $isConstructor + ); if ($targetParamName !== null && ! isset($types[$targetParamName])) { $type = $paramTag->type; @@ -631,12 +638,17 @@ private static function resolveTargetParamName( string $paramName, array $baseParamSet, array $baseParamNames, - array $hierNameToIndex + array $hierNameToIndex, + bool $isConstructor = false ): ?string { if (isset($baseParamSet[$paramName])) { return $paramName; } + if ($isConstructor) { + return null; + } + $paramIndex = $hierNameToIndex[$paramName] ?? null; if ($paramIndex === null || ! isset($baseParamNames[$paramIndex])) { return null; @@ -782,4 +794,4 @@ public static function substituteAliases(TypeNode $node, array $aliases): TypeNo return $node; } -} +} \ No newline at end of file diff --git a/tests/Fixtures/Shopware/Exception/BaseShopwareExceptionFixture.php b/tests/Fixtures/Shopware/Exception/BaseShopwareExceptionFixture.php new file mode 100644 index 0000000..f8cad6b --- /dev/null +++ b/tests/Fixtures/Shopware/Exception/BaseShopwareExceptionFixture.php @@ -0,0 +1,21 @@ + $parameters + * @param \Throwable|null $e + */ + public function __construct( + string $message, + array $parameters = [], + ?\Throwable $e = null + ) { + parent::__construct($message, 0, $e); + } +} \ No newline at end of file diff --git a/tests/Fixtures/Shopware/Exception/TableHelperExceptionFixture.php b/tests/Fixtures/Shopware/Exception/TableHelperExceptionFixture.php new file mode 100644 index 0000000..93fce90 --- /dev/null +++ b/tests/Fixtures/Shopware/Exception/TableHelperExceptionFixture.php @@ -0,0 +1,15 @@ +toBeInstanceOf(TableHelperExceptionFixture::class) + ->and($exception->getPrevious())->toBe($previous); + }); +}); \ No newline at end of file