Skip to content

Commit

Permalink
Assume null fileName in more places
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jun 9, 2022
1 parent 9dc6680 commit a2bad5a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 52 deletions.
4 changes: 2 additions & 2 deletions src/PhpDoc/PhpDocBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public static function resolvePhpDocBlockForProperty(
ClassReflection $classReflection,
?string $trait,
string $propertyName,
string $file,
?string $file,
?bool $explicit,
array $originalPositionalParameterNames, // unused
array $newPositionalParameterNames, // unused
Expand Down Expand Up @@ -141,7 +141,7 @@ public static function resolvePhpDocBlockForConstant(
ClassReflection $classReflection,
?string $trait, // unused
string $constantName,
string $file,
?string $file,
?bool $explicit,
array $originalPositionalParameterNames, // unused
array $newPositionalParameterNames, // unused
Expand Down
4 changes: 2 additions & 2 deletions src/PhpDoc/PhpDocInheritanceResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct(
public function resolvePhpDocForProperty(
?string $docComment,
ClassReflection $classReflection,
string $classReflectionFileName,
?string $classReflectionFileName,
?string $declaringTraitName,
string $propertyName,
): ResolvedPhpDocBlock
Expand All @@ -43,7 +43,7 @@ public function resolvePhpDocForProperty(
public function resolvePhpDocForConstant(
?string $docComment,
ClassReflection $classReflection,
string $classReflectionFileName,
?string $classReflectionFileName,
string $constantName,
): ResolvedPhpDocBlock
{
Expand Down
23 changes: 7 additions & 16 deletions src/Reflection/ClassReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -866,17 +866,14 @@ public function getConstant(string $name): ConstantReflection
throw new MissingConstantFromReflectionException($this->getName(), $name);
}

$deprecatedDescription = null;
$isDeprecated = false;
$isInternal = false;
$declaringClass = $this->reflectionProvider->getClass($reflectionConstant->getDeclaringClass()->getName());
$fileName = $declaringClass->getFileName();
$phpDocType = null;
$resolvedPhpDoc = $this->stubPhpDocProvider->findClassConstantPhpDoc(
$declaringClass->getName(),
$name,
);
if ($resolvedPhpDoc === null && $fileName !== null) {
if ($resolvedPhpDoc === null) {
$docComment = null;
if ($reflectionConstant->getDocComment() !== false) {
$docComment = $reflectionConstant->getDocComment();
Expand All @@ -889,14 +886,12 @@ public function getConstant(string $name): ConstantReflection
);
}

if ($resolvedPhpDoc !== null) {
$deprecatedDescription = $resolvedPhpDoc->getDeprecatedTag() !== null ? $resolvedPhpDoc->getDeprecatedTag()->getMessage() : null;
$isDeprecated = $resolvedPhpDoc->isDeprecated();
$isInternal = $resolvedPhpDoc->isInternal();
$varTags = $resolvedPhpDoc->getVarTags();
if (isset($varTags[0]) && count($varTags) === 1) {
$phpDocType = $varTags[0]->getType();
}
$deprecatedDescription = $resolvedPhpDoc->getDeprecatedTag() !== null ? $resolvedPhpDoc->getDeprecatedTag()->getMessage() : null;
$isDeprecated = $resolvedPhpDoc->isDeprecated();
$isInternal = $resolvedPhpDoc->isInternal();
$varTags = $resolvedPhpDoc->getVarTags();
if (isset($varTags[0]) && count($varTags) === 1) {
$phpDocType = $varTags[0]->getType();
}

$this->constants[$name] = new ClassConstantReflection(
Expand Down Expand Up @@ -1252,10 +1247,6 @@ public function getResolvedPhpDoc(): ?ResolvedPhpDocBlock
}

$fileName = $this->getFileName();
if ($fileName === null) {
return null;
}

if (is_bool($this->reflectionDocComment)) {
$docComment = $this->reflection->getDocComment();
$this->reflectionDocComment = $docComment !== false ? $docComment : null;
Expand Down
56 changes: 24 additions & 32 deletions src/Reflection/Php/PhpClassReflectionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,37 +252,34 @@ private function createProperty(
? $propertyReflection->getDocComment()
: null;

$declaringTraitName = null;
$phpDocType = null;
$resolvedPhpDoc = null;
if ($declaringClassReflection->getFileName() !== null) {
$declaringTraitName = $this->findPropertyTrait($propertyReflection);
$constructorName = null;
if ($propertyReflection->isPromoted()) {
if ($declaringClassReflection->hasConstructor()) {
$constructorName = $declaringClassReflection->getConstructor()->getName();
}
$declaringTraitName = $this->findPropertyTrait($propertyReflection);
$constructorName = null;
if ($propertyReflection->isPromoted()) {
if ($declaringClassReflection->hasConstructor()) {
$constructorName = $declaringClassReflection->getConstructor()->getName();
}
}

if ($constructorName === null) {
$resolvedPhpDoc = $this->phpDocInheritanceResolver->resolvePhpDocForProperty(
$docComment,
$declaringClassReflection,
$declaringClassReflection->getFileName(),
$declaringTraitName,
$propertyName,
);
} elseif ($docComment !== null) {
$resolvedPhpDoc = $this->fileTypeMapper->getResolvedPhpDoc(
$declaringClassReflection->getFileName(),
$declaringClassName,
$declaringTraitName,
$constructorName,
$docComment,
);
}
$phpDocBlockClassReflection = $declaringClassReflection;
if ($constructorName === null) {
$resolvedPhpDoc = $this->phpDocInheritanceResolver->resolvePhpDocForProperty(
$docComment,
$declaringClassReflection,
$declaringClassReflection->getFileName(),
$declaringTraitName,
$propertyName,
);
} elseif ($docComment !== null) {
$resolvedPhpDoc = $this->fileTypeMapper->getResolvedPhpDoc(
$declaringClassReflection->getFileName(),
$declaringClassName,
$declaringTraitName,
$constructorName,
$docComment,
);
}
$phpDocBlockClassReflection = $declaringClassReflection;

if ($resolvedPhpDoc !== null) {
$varTags = $resolvedPhpDoc->getVarTags();
Expand All @@ -292,10 +289,6 @@ private function createProperty(
$phpDocType = $varTags[$propertyName]->getType();
}

if (!isset($phpDocBlockClassReflection)) {
throw new ShouldNotHappenException();
}

$phpDocType = $phpDocType !== null ? TemplateTypeHelper::resolveTemplateTypes(
$phpDocType,
$phpDocBlockClassReflection->getActiveTemplateTypeMap(),
Expand All @@ -307,7 +300,7 @@ private function createProperty(
}

if ($phpDocType === null) {
if (isset($constructorName) && $declaringClassReflection->getFileName() !== null) {
if (isset($constructorName)) {
$constructorDocComment = $declaringClassReflection->getConstructor()->getDocComment();
$nativeClassReflection = $declaringClassReflection->getNativeReflection();
$positionalParameterNames = [];
Expand Down Expand Up @@ -649,7 +642,6 @@ private function createMethod(
if (
$methodReflection instanceof NativeBuiltinMethodReflection
&& $methodReflection->isConstructor()
&& $declaringClass->getFileName() !== null
) {
foreach ($methodReflection->getParameters() as $parameter) {
if (!$parameter->isPromoted()) {
Expand Down

0 comments on commit a2bad5a

Please sign in to comment.