Skip to content

Commit

Permalink
Fix problem with NameScope
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Sep 2, 2020
1 parent e16d1d3 commit 6e73d64
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 19 deletions.
5 changes: 0 additions & 5 deletions build/baseline-7.4.neon
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@ parameters:
count: 1
path: ../src/PhpDoc/ResolvedPhpDocBlock.php

-
message: "#^Class PHPStan\\\\PhpDoc\\\\ResolvedPhpDocBlock has an uninitialized property \\$nameScope\\. Give it default value or assign it in the constructor\\.$#"
count: 1
path: ../src/PhpDoc/ResolvedPhpDocBlock.php

-
message: "#^Class PHPStan\\\\PhpDoc\\\\ResolvedPhpDocBlock has an uninitialized property \\$templateTypeMap\\. Give it default value or assign it in the constructor\\.$#"
count: 1
Expand Down
5 changes: 5 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ parameters:
count: 1
path: src/PhpDoc/PhpDocBlock.php

-
message: "#^Method PHPStan\\\\PhpDoc\\\\ResolvedPhpDocBlock\\:\\:getNameScope\\(\\) should return PHPStan\\\\Analyser\\\\NameScope but returns PHPStan\\\\Analyser\\\\NameScope\\|null\\.$#"
count: 1
path: src/PhpDoc/ResolvedPhpDocBlock.php

-
message: "#^Return type \\(PHPStan\\\\PhpDoc\\\\Tag\\\\ParamTag\\) of method PHPStan\\\\PhpDoc\\\\Tag\\\\ParamTag\\:\\:withType\\(\\) should be covariant with return type \\(static\\(PHPStan\\\\PhpDoc\\\\Tag\\\\TypedTag\\)\\) of method PHPStan\\\\PhpDoc\\\\Tag\\\\TypedTag\\:\\:withType\\(\\)$#"
count: 1
Expand Down
5 changes: 4 additions & 1 deletion src/Dependency/ExportedNodeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,10 @@ private function exportPhpDocNode(
$text
);

$nameScope = $resolvedPhpDocBlock->getNameScope();
$nameScope = $resolvedPhpDocBlock->getNullableNameScope();
if ($nameScope === null) {
return null;
}

return new ExportedPhpDocNode($text, $nameScope->getNamespace(), $nameScope->getUses());
}
Expand Down
31 changes: 18 additions & 13 deletions src/PhpDoc/ResolvedPhpDocBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ResolvedPhpDocBlock

private ?string $filename;

private NameScope $nameScope;
private ?NameScope $nameScope = null;

private TemplateTypeMap $templateTypeMap;

Expand Down Expand Up @@ -218,7 +218,12 @@ public function getFilename(): ?string
return $this->filename;
}

public function getNameScope(): NameScope
private function getNameScope(): NameScope
{
return $this->nameScope;
}

public function getNullableNameScope(): ?NameScope
{
return $this->nameScope;
}
Expand All @@ -231,7 +236,7 @@ public function getVarTags(): array
if ($this->varTags === false) {
$this->varTags = $this->phpDocNodeResolver->resolveVarTags(
$this->phpDocNode,
$this->nameScope
$this->getNameScope()
);
}
return $this->varTags;
Expand All @@ -245,7 +250,7 @@ public function getMethodTags(): array
if ($this->methodTags === false) {
$this->methodTags = $this->phpDocNodeResolver->resolveMethodTags(
$this->phpDocNode,
$this->nameScope
$this->getNameScope()
);
}
return $this->methodTags;
Expand All @@ -259,7 +264,7 @@ public function getPropertyTags(): array
if ($this->propertyTags === false) {
$this->propertyTags = $this->phpDocNodeResolver->resolvePropertyTags(
$this->phpDocNode,
$this->nameScope
$this->getNameScope()
);
}
return $this->propertyTags;
Expand All @@ -281,7 +286,7 @@ public function getExtendsTags(): array
if ($this->extendsTags === false) {
$this->extendsTags = $this->phpDocNodeResolver->resolveExtendsTags(
$this->phpDocNode,
$this->nameScope
$this->getNameScope()
);
}
return $this->extendsTags;
Expand All @@ -295,7 +300,7 @@ public function getImplementsTags(): array
if ($this->implementsTags === false) {
$this->implementsTags = $this->phpDocNodeResolver->resolveImplementsTags(
$this->phpDocNode,
$this->nameScope
$this->getNameScope()
);
}
return $this->implementsTags;
Expand All @@ -309,7 +314,7 @@ public function getUsesTags(): array
if ($this->usesTags === false) {
$this->usesTags = $this->phpDocNodeResolver->resolveUsesTags(
$this->phpDocNode,
$this->nameScope
$this->getNameScope()
);
}
return $this->usesTags;
Expand All @@ -323,7 +328,7 @@ public function getParamTags(): array
if ($this->paramTags === false) {
$this->paramTags = $this->phpDocNodeResolver->resolveParamTags(
$this->phpDocNode,
$this->nameScope
$this->getNameScope()
);
}
return $this->paramTags;
Expand All @@ -334,7 +339,7 @@ public function getReturnTag(): ?\PHPStan\PhpDoc\Tag\ReturnTag
if ($this->returnTag === false) {
$this->returnTag = $this->phpDocNodeResolver->resolveReturnTag(
$this->phpDocNode,
$this->nameScope
$this->getNameScope()
);
}
return $this->returnTag;
Expand All @@ -345,7 +350,7 @@ public function getThrowsTag(): ?\PHPStan\PhpDoc\Tag\ThrowsTag
if ($this->throwsTag === false) {
$this->throwsTag = $this->phpDocNodeResolver->resolveThrowsTags(
$this->phpDocNode,
$this->nameScope
$this->getNameScope()
);
}
return $this->throwsTag;
Expand All @@ -359,7 +364,7 @@ public function getMixinTags(): array
if ($this->mixinTags === false) {
$this->mixinTags = $this->phpDocNodeResolver->resolveMixinTags(
$this->phpDocNode,
$this->nameScope
$this->getNameScope()
);
}

Expand All @@ -371,7 +376,7 @@ public function getDeprecatedTag(): ?\PHPStan\PhpDoc\Tag\DeprecatedTag
if ($this->deprecatedTag === false) {
$this->deprecatedTag = $this->phpDocNodeResolver->resolveDeprecatedTag(
$this->phpDocNode,
$this->nameScope
$this->getNameScope()
);
}
return $this->deprecatedTag;
Expand Down

0 comments on commit 6e73d64

Please sign in to comment.