Skip to content

Commit 6e73d64

Browse files
committed
Fix problem with NameScope
1 parent e16d1d3 commit 6e73d64

File tree

4 files changed

+27
-19
lines changed

4 files changed

+27
-19
lines changed

build/baseline-7.4.neon

-5
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,6 @@ parameters:
5151
count: 1
5252
path: ../src/PhpDoc/ResolvedPhpDocBlock.php
5353

54-
-
55-
message: "#^Class PHPStan\\\\PhpDoc\\\\ResolvedPhpDocBlock has an uninitialized property \\$nameScope\\. Give it default value or assign it in the constructor\\.$#"
56-
count: 1
57-
path: ../src/PhpDoc/ResolvedPhpDocBlock.php
58-
5954
-
6055
message: "#^Class PHPStan\\\\PhpDoc\\\\ResolvedPhpDocBlock has an uninitialized property \\$templateTypeMap\\. Give it default value or assign it in the constructor\\.$#"
6156
count: 1

phpstan-baseline.neon

+5
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ parameters:
6060
count: 1
6161
path: src/PhpDoc/PhpDocBlock.php
6262

63+
-
64+
message: "#^Method PHPStan\\\\PhpDoc\\\\ResolvedPhpDocBlock\\:\\:getNameScope\\(\\) should return PHPStan\\\\Analyser\\\\NameScope but returns PHPStan\\\\Analyser\\\\NameScope\\|null\\.$#"
65+
count: 1
66+
path: src/PhpDoc/ResolvedPhpDocBlock.php
67+
6368
-
6469
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\\(\\)$#"
6570
count: 1

src/Dependency/ExportedNodeResolver.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,10 @@ private function exportPhpDocNode(
308308
$text
309309
);
310310

311-
$nameScope = $resolvedPhpDocBlock->getNameScope();
311+
$nameScope = $resolvedPhpDocBlock->getNullableNameScope();
312+
if ($nameScope === null) {
313+
return null;
314+
}
312315

313316
return new ExportedPhpDocNode($text, $nameScope->getNamespace(), $nameScope->getUses());
314317
}

src/PhpDoc/ResolvedPhpDocBlock.php

+18-13
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class ResolvedPhpDocBlock
2222

2323
private ?string $filename;
2424

25-
private NameScope $nameScope;
25+
private ?NameScope $nameScope = null;
2626

2727
private TemplateTypeMap $templateTypeMap;
2828

@@ -218,7 +218,12 @@ public function getFilename(): ?string
218218
return $this->filename;
219219
}
220220

221-
public function getNameScope(): NameScope
221+
private function getNameScope(): NameScope
222+
{
223+
return $this->nameScope;
224+
}
225+
226+
public function getNullableNameScope(): ?NameScope
222227
{
223228
return $this->nameScope;
224229
}
@@ -231,7 +236,7 @@ public function getVarTags(): array
231236
if ($this->varTags === false) {
232237
$this->varTags = $this->phpDocNodeResolver->resolveVarTags(
233238
$this->phpDocNode,
234-
$this->nameScope
239+
$this->getNameScope()
235240
);
236241
}
237242
return $this->varTags;
@@ -245,7 +250,7 @@ public function getMethodTags(): array
245250
if ($this->methodTags === false) {
246251
$this->methodTags = $this->phpDocNodeResolver->resolveMethodTags(
247252
$this->phpDocNode,
248-
$this->nameScope
253+
$this->getNameScope()
249254
);
250255
}
251256
return $this->methodTags;
@@ -259,7 +264,7 @@ public function getPropertyTags(): array
259264
if ($this->propertyTags === false) {
260265
$this->propertyTags = $this->phpDocNodeResolver->resolvePropertyTags(
261266
$this->phpDocNode,
262-
$this->nameScope
267+
$this->getNameScope()
263268
);
264269
}
265270
return $this->propertyTags;
@@ -281,7 +286,7 @@ public function getExtendsTags(): array
281286
if ($this->extendsTags === false) {
282287
$this->extendsTags = $this->phpDocNodeResolver->resolveExtendsTags(
283288
$this->phpDocNode,
284-
$this->nameScope
289+
$this->getNameScope()
285290
);
286291
}
287292
return $this->extendsTags;
@@ -295,7 +300,7 @@ public function getImplementsTags(): array
295300
if ($this->implementsTags === false) {
296301
$this->implementsTags = $this->phpDocNodeResolver->resolveImplementsTags(
297302
$this->phpDocNode,
298-
$this->nameScope
303+
$this->getNameScope()
299304
);
300305
}
301306
return $this->implementsTags;
@@ -309,7 +314,7 @@ public function getUsesTags(): array
309314
if ($this->usesTags === false) {
310315
$this->usesTags = $this->phpDocNodeResolver->resolveUsesTags(
311316
$this->phpDocNode,
312-
$this->nameScope
317+
$this->getNameScope()
313318
);
314319
}
315320
return $this->usesTags;
@@ -323,7 +328,7 @@ public function getParamTags(): array
323328
if ($this->paramTags === false) {
324329
$this->paramTags = $this->phpDocNodeResolver->resolveParamTags(
325330
$this->phpDocNode,
326-
$this->nameScope
331+
$this->getNameScope()
327332
);
328333
}
329334
return $this->paramTags;
@@ -334,7 +339,7 @@ public function getReturnTag(): ?\PHPStan\PhpDoc\Tag\ReturnTag
334339
if ($this->returnTag === false) {
335340
$this->returnTag = $this->phpDocNodeResolver->resolveReturnTag(
336341
$this->phpDocNode,
337-
$this->nameScope
342+
$this->getNameScope()
338343
);
339344
}
340345
return $this->returnTag;
@@ -345,7 +350,7 @@ public function getThrowsTag(): ?\PHPStan\PhpDoc\Tag\ThrowsTag
345350
if ($this->throwsTag === false) {
346351
$this->throwsTag = $this->phpDocNodeResolver->resolveThrowsTags(
347352
$this->phpDocNode,
348-
$this->nameScope
353+
$this->getNameScope()
349354
);
350355
}
351356
return $this->throwsTag;
@@ -359,7 +364,7 @@ public function getMixinTags(): array
359364
if ($this->mixinTags === false) {
360365
$this->mixinTags = $this->phpDocNodeResolver->resolveMixinTags(
361366
$this->phpDocNode,
362-
$this->nameScope
367+
$this->getNameScope()
363368
);
364369
}
365370

@@ -371,7 +376,7 @@ public function getDeprecatedTag(): ?\PHPStan\PhpDoc\Tag\DeprecatedTag
371376
if ($this->deprecatedTag === false) {
372377
$this->deprecatedTag = $this->phpDocNodeResolver->resolveDeprecatedTag(
373378
$this->phpDocNode,
374-
$this->nameScope
379+
$this->getNameScope()
375380
);
376381
}
377382
return $this->deprecatedTag;

0 commit comments

Comments
 (0)