Skip to content

Commit 629ccf6

Browse files
committed
[BCB] Changed return types of various methods that had |false to |null
1 parent a321a3e commit 629ccf6

39 files changed

+110
-145
lines changed

composer.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Analyser/FileAnalyser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public function analyseFile(
108108
$metadata = [];
109109
if ($scope->isInTrait()) {
110110
$traitReflection = $scope->getTraitReflection();
111-
if ($traitReflection->getFileName() !== false) {
111+
if ($traitReflection->getFileName() !== null) {
112112
$traitFilePath = $traitReflection->getFileName();
113113
}
114114
}

src/Analyser/MutatingScope.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ public function getFileDescription(): string
292292
}
293293

294294
$traitReflection = $this->context->getTraitReflection();
295-
if ($traitReflection->getFileName() === false) {
295+
if ($traitReflection->getFileName() === null) {
296296
throw new \PHPStan\ShouldNotHappenException();
297297
}
298298

@@ -2588,7 +2588,7 @@ private function resolveExactName(Name $name): ?string
25882588
return null;
25892589
}
25902590
$currentClassReflection = $this->getClassReflection();
2591-
if ($currentClassReflection->getParentClass() !== false) {
2591+
if ($currentClassReflection->getParentClass() !== null) {
25922592
return $currentClassReflection->getParentClass()->getName();
25932593
}
25942594
return null;
@@ -2614,7 +2614,7 @@ public function resolveName(Name $name): string
26142614
return $this->getClassReflection()->getName();
26152615
} elseif ($originalClass === 'parent') {
26162616
$currentClassReflection = $this->getClassReflection();
2617-
if ($currentClassReflection->getParentClass() !== false) {
2617+
if ($currentClassReflection->getParentClass() !== null) {
26182618
return $currentClassReflection->getParentClass()->getName();
26192619
}
26202620
}
@@ -3385,7 +3385,7 @@ public function getFunctionType($type, bool $isNullable, bool $isVariadic): Type
33853385
$className = (string) $type;
33863386
$lowercasedClassName = strtolower($className);
33873387
if ($lowercasedClassName === 'parent') {
3388-
if ($this->isInClass() && $this->getClassReflection()->getParentClass() !== false) {
3388+
if ($this->isInClass() && $this->getClassReflection()->getParentClass() !== null) {
33893389
return new ObjectType($this->getClassReflection()->getParentClass()->getName());
33903390
}
33913391

src/Analyser/NodeScopeResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3663,7 +3663,7 @@ private function processTraitUse(Node\Stmt\TraitUse $node, MutatingScope $classS
36633663
}
36643664
$traitReflection = $this->reflectionProvider->getClass($traitName);
36653665
$traitFileName = $traitReflection->getFileName();
3666-
if ($traitFileName === false) {
3666+
if ($traitFileName === null) {
36673667
continue; // trait from eval or from PHP itself
36683668
}
36693669
$fileName = $this->fileHelper->normalizePath($traitFileName);

src/Analyser/ResultCache/ResultCacheManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ private function getProjectExtensionFiles(?array $projectConfig, array $dependen
633633

634634
$classReflection = $this->reflectionProvider->getClass($class);
635635
$fileName = $classReflection->getFileName();
636-
if ($fileName === false) {
636+
if ($fileName === null) {
637637
continue;
638638
}
639639

src/Analyser/TypeSpecifier.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public function specifyTypesInCondition(
123123
} elseif ($lowercasedClassName === 'parent') {
124124
if (
125125
$scope->isInClass()
126-
&& $scope->getClassReflection()->getParentClass() !== false
126+
&& $scope->getClassReflection()->getParentClass() !== null
127127
) {
128128
$type = new ObjectType($scope->getClassReflection()->getParentClass()->getName());
129129
} else {

src/Dependency/DependencyResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ private function addClassToDependencies(string $className, array &$dependenciesR
230230
}
231231

232232
$classReflection = $classReflection->getParentClass();
233-
} while ($classReflection !== false);
233+
} while ($classReflection !== null);
234234
}
235235

236236
private function getFunctionReflection(\PhpParser\Node\Name $nameNode, ?Scope $scope): ReflectionWithFilename

src/Dependency/NodeDependencies.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function getFileDependencies(string $currentFile, array $analysedFiles):
4141

4242
foreach ($this->reflections as $dependencyReflection) {
4343
$dependencyFile = $dependencyReflection->getFileName();
44-
if ($dependencyFile === false) {
44+
if ($dependencyFile === null) {
4545
continue;
4646
}
4747
$dependencyFile = $this->fileHelper->normalizePath($dependencyFile);

src/PhpDoc/PhpDocBlock.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ private static function getParentReflections(ClassReflection $classReflection):
341341
$result = [];
342342

343343
$parent = $classReflection->getParentClass();
344-
if ($parent !== false) {
344+
if ($parent !== null) {
345345
$result[] = $parent;
346346
}
347347

src/PhpDoc/TypeNodeResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ private function resolveIdentifierTypeNode(IdentifierTypeNode $typeNode, NameSco
310310
case 'parent':
311311
if ($this->getReflectionProvider()->hasClass($nameScope->getClassName())) {
312312
$classReflection = $this->getReflectionProvider()->getClass($nameScope->getClassName());
313-
if ($classReflection->getParentClass() !== false) {
313+
if ($classReflection->getParentClass() !== null) {
314314
return new ObjectType($classReflection->getParentClass()->getName());
315315
}
316316
}
@@ -681,7 +681,7 @@ private function resolveConstTypeNode(ConstTypeNode $typeNode, NameScope $nameSc
681681
case 'parent':
682682
if ($this->getReflectionProvider()->hasClass($nameScope->getClassName())) {
683683
$classReflection = $this->getReflectionProvider()->getClass($nameScope->getClassName());
684-
if ($classReflection->getParentClass() === false) {
684+
if ($classReflection->getParentClass() === null) {
685685
return new ErrorType();
686686

687687
}

src/Reflection/BetterReflection/BetterReflectionProvider.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ public function getAnonymousClassReflection(\PhpParser\Node\Stmt\Class_ $classNo
210210
$scopeFile = $scope->getFile();
211211
} else {
212212
$scopeFile = $scope->getTraitReflection()->getFileName();
213-
if ($scopeFile === false) {
213+
if ($scopeFile === null) {
214214
$scopeFile = $scope->getFile();
215215
}
216216
}
@@ -297,9 +297,8 @@ private function getCustomFunction(string $functionName): \PHPStan\Reflection\Ph
297297
return $parameter->getName();
298298
}, $reflectionFunction->getParameters()));
299299
if ($resolvedPhpDoc === null && $reflectionFunction->getFileName() !== false && $reflectionFunction->getDocComment() !== false) {
300-
$fileName = $reflectionFunction->getFileName();
301300
$docComment = $reflectionFunction->getDocComment();
302-
$resolvedPhpDoc = $this->fileTypeMapper->getResolvedPhpDoc($fileName, null, null, $reflectionFunction->getName(), $docComment);
301+
$resolvedPhpDoc = $this->fileTypeMapper->getResolvedPhpDoc($reflectionFunction->getFileName(), null, null, $reflectionFunction->getName(), $docComment);
303302
}
304303

305304
if ($resolvedPhpDoc !== null) {
@@ -326,7 +325,7 @@ private function getCustomFunction(string $functionName): \PHPStan\Reflection\Ph
326325
$isDeprecated,
327326
$isInternal,
328327
$isFinal,
329-
$reflectionFunction->getFileName(),
328+
$reflectionFunction->getFileName() !== false ? $reflectionFunction->getFileName() : null,
330329
$isPure
331330
);
332331
}

src/Reflection/ClassConstantReflection.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,7 @@ public function getName(): string
5353

5454
public function getFileName(): ?string
5555
{
56-
$fileName = $this->declaringClass->getFileName();
57-
if ($fileName === false) {
58-
return null;
59-
}
60-
61-
return $fileName;
56+
return $this->declaringClass->getFileName();
6257
}
6358

6459
/**

src/Reflection/ClassReflection.php

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,16 @@ class ClassReflection implements ReflectionWithFilename
9797
private array $subclasses = [];
9898

9999
/** @var string|false|null */
100-
private $filename;
100+
private $filename = false;
101101

102102
/** @var string|false|null */
103-
private $reflectionDocComment;
103+
private $reflectionDocComment = false;
104104

105105
/** @var \PHPStan\Reflection\ClassReflection[]|null */
106106
private ?array $cachedInterfaces = null;
107107

108108
/** @var \PHPStan\Reflection\ClassReflection|false|null */
109-
private $cachedParentClass = null;
109+
private $cachedParentClass = false;
110110

111111
/** @var array<string, TypeAlias>|null */
112112
private ?array $typeAliases = null;
@@ -161,12 +161,9 @@ public function getNativeReflection(): \ReflectionClass
161161
return $this->reflection;
162162
}
163163

164-
/**
165-
* @return string|false
166-
*/
167-
public function getFileName()
164+
public function getFileName(): ?string
168165
{
169-
if (isset($this->filename)) {
166+
if ($this->filename !== false) {
170167
return $this->filename;
171168
}
172169

@@ -175,11 +172,11 @@ public function getFileName()
175172
}
176173
$fileName = $this->reflection->getFileName();
177174
if ($fileName === false) {
178-
return $this->filename = false;
175+
return $this->filename = null;
179176
}
180177

181178
if (!file_exists($fileName)) {
182-
return $this->filename = false;
179+
return $this->filename = null;
183180
}
184181

185182
return $this->filename = $fileName;
@@ -191,27 +188,19 @@ public function getFileNameWithPhpDocs(): ?string
191188
return $this->stubPhpDocBlock->getFilename();
192189
}
193190

194-
$filename = $this->getFileName();
195-
if ($filename === false) {
196-
return null;
197-
}
198-
199-
return $filename;
191+
return $this->getFileName();
200192
}
201193

202-
/**
203-
* @return false|\PHPStan\Reflection\ClassReflection
204-
*/
205-
public function getParentClass()
194+
public function getParentClass(): ?ClassReflection
206195
{
207-
if ($this->cachedParentClass !== null) {
196+
if ($this->cachedParentClass !== false) {
208197
return $this->cachedParentClass;
209198
}
210199

211200
$parentClass = $this->reflection->getParentClass();
212201

213202
if ($parentClass === false) {
214-
return $this->cachedParentClass = false;
203+
return $this->cachedParentClass = null;
215204
}
216205

217206
$extendsTag = $this->getFirstExtendsTag();
@@ -575,7 +564,7 @@ public function getParents(): array
575564
{
576565
$parents = [];
577566
$parent = $this->getParentClass();
578-
while ($parent !== false) {
567+
while ($parent !== null) {
579568
$parents[] = $parent;
580569
$parent = $parent->getParentClass();
581570
}
@@ -595,7 +584,7 @@ public function getInterfaces(): array
595584
$interfaces = $this->getImmediateInterfaces();
596585
$immediateInterfaces = $interfaces;
597586
$parent = $this->getParentClass();
598-
while ($parent !== false) {
587+
while ($parent !== null) {
599588
foreach ($parent->getImmediateInterfaces() as $parentInterface) {
600589
$interfaces[$parentInterface->getName()] = $parentInterface;
601590
foreach ($this->collectInterfaces($parentInterface) as $parentInterfaceInterface) {
@@ -640,7 +629,7 @@ public function getImmediateInterfaces(): array
640629
{
641630
$indirectInterfaceNames = [];
642631
$parent = $this->getParentClass();
643-
while ($parent !== false) {
632+
while ($parent !== null) {
644633
foreach ($parent->getNativeReflection()->getInterfaceNames() as $parentInterfaceName) {
645634
$indirectInterfaceNames[] = $parentInterfaceName;
646635
}
@@ -740,7 +729,7 @@ public function getParentClassesNames(): array
740729
{
741730
$parentNames = [];
742731
$currentClassReflection = $this;
743-
while ($currentClassReflection->getParentClass() !== false) {
732+
while ($currentClassReflection->getParentClass() !== null) {
744733
$parentNames[] = $currentClassReflection->getParentClass()->getName();
745734
$currentClassReflection = $currentClassReflection->getParentClass();
746735
}
@@ -780,7 +769,7 @@ public function getConstant(string $name): ConstantReflection
780769
$declaringClass->getName(),
781770
$name
782771
);
783-
if ($resolvedPhpDoc === null && $fileName !== false) {
772+
if ($resolvedPhpDoc === null && $fileName !== null) {
784773
$docComment = null;
785774
if ($reflectionConstant->getDocComment() !== false) {
786775
$docComment = $reflectionConstant->getDocComment();
@@ -1097,15 +1086,16 @@ public function getResolvedPhpDoc(): ?ResolvedPhpDocBlock
10971086
}
10981087

10991088
$fileName = $this->getFileName();
1100-
if ($fileName === false) {
1089+
if ($fileName === null) {
11011090
return null;
11021091
}
11031092

1104-
if ($this->reflectionDocComment === null) {
1105-
$this->reflectionDocComment = $this->reflection->getDocComment();
1093+
if ($this->reflectionDocComment === false) {
1094+
$docComment = $this->reflection->getDocComment();
1095+
$this->reflectionDocComment = $docComment !== false ? $docComment : null;
11061096
}
11071097

1108-
if ($this->reflectionDocComment === false) {
1098+
if ($this->reflectionDocComment === null) {
11091099
return null;
11101100
}
11111101

@@ -1189,7 +1179,7 @@ public function getAncestors(): array
11891179
}
11901180

11911181
$parent = $this->getParentClass();
1192-
if ($parent !== false) {
1182+
if ($parent !== null) {
11931183
$addToAncestors($parent->getName(), $parent);
11941184
foreach ($parent->getAncestors() as $name => $ancestor) {
11951185
$addToAncestors($name, $ancestor);

src/Reflection/FunctionReflectionFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ interface FunctionReflectionFactory
1919
* @param bool $isDeprecated
2020
* @param bool $isInternal
2121
* @param bool $isFinal
22-
* @param string|false $filename
22+
* @param string|null $filename
2323
* @param bool|null $isPure
2424
* @return PhpFunctionReflection
2525
*/
@@ -33,7 +33,7 @@ public function create(
3333
bool $isDeprecated,
3434
bool $isInternal,
3535
bool $isFinal,
36-
$filename,
36+
?string $filename,
3737
?bool $isPure = null
3838
): PhpFunctionReflection;
3939

src/Reflection/Php/BuiltinMethodReflection.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,13 @@ public function getName(): string;
1111

1212
public function getReflection(): ?\ReflectionMethod;
1313

14-
/**
15-
* @return string|false
16-
*/
17-
public function getFileName();
14+
public function getFileName(): ?string;
1815

1916
public function getDeclaringClass(): \ReflectionClass;
2017

21-
/**
22-
* @return int|false
23-
*/
24-
public function getStartLine();
18+
public function getStartLine(): ?int;
2519

26-
/**
27-
* @return int|false
28-
*/
29-
public function getEndLine();
20+
public function getEndLine(): ?int;
3021

3122
public function getDocComment(): ?string;
3223

0 commit comments

Comments
 (0)