Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/Contract/ContractParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,7 @@ private static function parseMethodHierarchyDocs(
$baseParamNames = [];
$baseParamSet = [];
$baseParamVariadic = [];
$isConstructor = ($ref->getName() === '__construct');

foreach ($baseParams as $idx => $p) {
$baseParamNames[$idx] = $p->getName();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -782,4 +794,4 @@ public static function substituteAliases(TypeNode $node, array $aliases): TypeNo

return $node;
}
}
}
21 changes: 21 additions & 0 deletions tests/Fixtures/Shopware/Exception/BaseShopwareExceptionFixture.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace TypePHP\Tests\Fixtures\Shopware\Exception;

abstract class BaseShopwareExceptionFixture extends \Exception
{
/**
* @param string $message
* @param array<string, mixed> $parameters
* @param \Throwable|null $e
*/
public function __construct(
string $message,
array $parameters = [],
?\Throwable $e = null
) {
parent::__construct($message, 0, $e);
}
}
15 changes: 15 additions & 0 deletions tests/Fixtures/Shopware/Exception/TableHelperExceptionFixture.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace TypePHP\Tests\Fixtures\Shopware\Exception;

class TableHelperExceptionFixture extends BaseShopwareExceptionFixture
{
public function __construct(
string $message,
?\Throwable $previousException = null
) {
parent::__construct($message, [], $previousException);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

use TypePHP\Tests\Fixtures\Shopware\Exception\TableHelperExceptionFixture;

describe('Constructor Parameter Inheritance Mismatch (Shopware TableHelperException)', function () {
test('child constructor with different parameter names does not inherit parent constructor docblocks by positional index', function () {
$previous = new \Exception('Underlying DB error');

$exception = new TableHelperExceptionFixture('Table missing', $previous);

expect($exception)->toBeInstanceOf(TableHelperExceptionFixture::class)
->and($exception->getPrevious())->toBe($previous);
});
});
Loading