Skip to content

Commit

Permalink
Refactoring of PhpDocBlock that will enable a bugfix down the road
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jan 24, 2025
1 parent 2f74584 commit ebcb5da
Showing 1 changed file with 32 additions and 53 deletions.
85 changes: 32 additions & 53 deletions src/PhpDoc/PhpDocBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,24 @@ public static function resolvePhpDocBlockForProperty(
array $newPositionalParameterNames, // unused
): self
{
return self::resolvePhpDocBlockTree(
$docComment,
$classReflection,
$trait,
$docBlocksFromParents = self::resolveParentPhpDocBlocks(
self::getParentReflections($classReflection),
$propertyName,
$file,
'hasNativeProperty',
'getNativeProperty',
__FUNCTION__,
$explicit,
[],
[],
$explicit ?? $docComment !== null,
$newPositionalParameterNames,
);

return new self(
$docComment ?? ResolvedPhpDocBlock::EMPTY_DOC_STRING,
$file,
$classReflection,
$trait,
$explicit ?? true,
self::remapParameterNames($originalPositionalParameterNames, $newPositionalParameterNames),
$docBlocksFromParents,
);
}

Expand All @@ -158,18 +164,24 @@ public static function resolvePhpDocBlockForConstant(
array $newPositionalParameterNames, // unused
): self
{
return self::resolvePhpDocBlockTree(
$docComment,
$classReflection,
null,
$docBlocksFromParents = self::resolveParentPhpDocBlocks(
self::getParentReflections($classReflection),
$constantName,
$file,
'hasConstant',
'getConstant',
__FUNCTION__,
$explicit,
[],
[],
$explicit ?? $docComment !== null,
$newPositionalParameterNames,
);

return new self(
$docComment ?? ResolvedPhpDocBlock::EMPTY_DOC_STRING,
$file,
$classReflection,
$trait,
$explicit ?? true,
self::remapParameterNames($originalPositionalParameterNames, $newPositionalParameterNames),
$docBlocksFromParents,
);
}

Expand All @@ -188,45 +200,12 @@ public static function resolvePhpDocBlockForMethod(
array $newPositionalParameterNames,
): self
{
return self::resolvePhpDocBlockTree(
$docComment,
$classReflection,
$trait,
$docBlocksFromParents = self::resolveParentPhpDocBlocks(
self::getParentReflections($classReflection),
$methodName,
$file,
'hasNativeMethod',
'getNativeMethod',
__FUNCTION__,
$explicit,
$originalPositionalParameterNames,
$newPositionalParameterNames,
);
}

/**
* @param array<int, string> $originalPositionalParameterNames
* @param array<int, string> $newPositionalParameterNames
*/
private static function resolvePhpDocBlockTree(
?string $docComment,
ClassReflection $classReflection,
?string $trait,
string $name,
?string $file,
string $hasMethodName,
string $getMethodName,
string $resolveMethodName,
?bool $explicit,
array $originalPositionalParameterNames,
array $newPositionalParameterNames,
): self
{
$docBlocksFromParents = self::resolveParentPhpDocBlocks(
$classReflection,
$name,
$hasMethodName,
$getMethodName,
$resolveMethodName,
$explicit ?? $docComment !== null,
$newPositionalParameterNames,
);
Expand Down Expand Up @@ -264,11 +243,12 @@ private static function remapParameterNames(
}

/**
* @param array<int, ClassReflection> $parentReflections
* @param array<int, string> $positionalParameterNames
* @return array<int, self>
*/
private static function resolveParentPhpDocBlocks(
ClassReflection $classReflection,
array $parentReflections,
string $name,
string $hasMethodName,
string $getMethodName,
Expand All @@ -278,7 +258,6 @@ private static function resolveParentPhpDocBlocks(
): array
{
$result = [];
$parentReflections = self::getParentReflections($classReflection);

foreach ($parentReflections as $parentReflection) {
$oneResult = self::resolvePhpDocBlockFromClass(
Expand Down

0 comments on commit ebcb5da

Please sign in to comment.