Skip to content

Commit

Permalink
[BCB] Removed ReflectionWithFilename, use ClassReflection|FunctionRef…
Browse files Browse the repository at this point in the history
…lection instead
  • Loading branch information
ondrejmirtes committed Oct 31, 2021
1 parent 5ddca42 commit 3738fcd
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 32 deletions.
18 changes: 7 additions & 11 deletions src/Dependency/DependencyResolver.php
Expand Up @@ -11,10 +11,11 @@
use PHPStan\File\FileHelper;
use PHPStan\Node\InClassMethodNode;
use PHPStan\Node\InFunctionNode;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\FunctionReflection;
use PHPStan\Reflection\ParametersAcceptorSelector;
use PHPStan\Reflection\ParametersAcceptorWithPhpDocs;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Reflection\ReflectionWithFilename;
use PHPStan\Type\ClosureType;
use PHPStan\Type\Constant\ConstantStringType;
use PHPStan\Type\Type;
Expand Down Expand Up @@ -208,7 +209,7 @@ private function considerArrayForCallableTest(Scope $scope, Array_ $arrayNode):

/**
* @param string $className
* @param array<int, ReflectionWithFilename> $dependenciesReflections
* @param array<int, ClassReflection|FunctionReflection> $dependenciesReflections
*/
private function addClassToDependencies(string $className, array &$dependenciesReflections): void
{
Expand All @@ -233,19 +234,14 @@ private function addClassToDependencies(string $className, array &$dependenciesR
} while ($classReflection !== null);
}

private function getFunctionReflection(\PhpParser\Node\Name $nameNode, ?Scope $scope): ReflectionWithFilename
private function getFunctionReflection(\PhpParser\Node\Name $nameNode, ?Scope $scope): FunctionReflection
{
$reflection = $this->reflectionProvider->getFunction($nameNode, $scope);
if (!$reflection instanceof ReflectionWithFilename) {
throw new \PHPStan\Broker\FunctionNotFoundException((string) $nameNode);
}

return $reflection;
return $this->reflectionProvider->getFunction($nameNode, $scope);
}

/**
* @param ParametersAcceptorWithPhpDocs $parametersAcceptor
* @param ReflectionWithFilename[] $dependenciesReflections
* @param array<ClassReflection|FunctionReflection> $dependenciesReflections
*/
private function extractFromParametersAcceptor(
ParametersAcceptorWithPhpDocs $parametersAcceptor,
Expand Down Expand Up @@ -274,7 +270,7 @@ private function extractFromParametersAcceptor(

/**
* @param Type|null $throwType
* @param ReflectionWithFilename[] $dependenciesReflections
* @param array<ClassReflection|FunctionReflection> $dependenciesReflections
*/
private function extractThrowType(
?Type $throwType,
Expand Down
7 changes: 4 additions & 3 deletions src/Dependency/NodeDependencies.php
Expand Up @@ -3,21 +3,22 @@
namespace PHPStan\Dependency;

use PHPStan\File\FileHelper;
use PHPStan\Reflection\ReflectionWithFilename;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\FunctionReflection;

class NodeDependencies
{

private FileHelper $fileHelper;

/** @var array<int, ReflectionWithFilename> */
/** @var array<int, ClassReflection|FunctionReflection> */
private array $reflections;

private ?ExportedNode $exportedNode;

/**
* @param FileHelper $fileHelper
* @param array<int, ReflectionWithFilename> $reflections
* @param array<int, ClassReflection|FunctionReflection> $reflections
*/
public function __construct(
FileHelper $fileHelper,
Expand Down
2 changes: 1 addition & 1 deletion src/Reflection/ClassReflection.php
Expand Up @@ -31,7 +31,7 @@
use ReflectionMethod;

/** @api */
class ClassReflection implements ReflectionWithFilename
class ClassReflection
{

private \PHPStan\Reflection\ReflectionProvider $reflectionProvider;
Expand Down
3 changes: 1 addition & 2 deletions src/Reflection/Php/PhpFunctionReflection.php
Expand Up @@ -13,15 +13,14 @@
use PHPStan\Reflection\FunctionVariantWithPhpDocs;
use PHPStan\Reflection\ParametersAcceptor;
use PHPStan\Reflection\ParametersAcceptorWithPhpDocs;
use PHPStan\Reflection\ReflectionWithFilename;
use PHPStan\TrinaryLogic;
use PHPStan\Type\Generic\TemplateTypeMap;
use PHPStan\Type\MixedType;
use PHPStan\Type\Type;
use PHPStan\Type\TypehintHelper;
use PHPStan\Type\VoidType;

class PhpFunctionReflection implements FunctionReflection, ReflectionWithFilename
class PhpFunctionReflection implements FunctionReflection
{

private \ReflectionFunction $reflection;
Expand Down
Expand Up @@ -9,7 +9,6 @@
use PHPStan\Reflection\FunctionReflection;
use PHPStan\Reflection\GlobalConstantReflection;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Reflection\ReflectionWithFilename;

class ClassBlacklistReflectionProvider implements ReflectionProvider
{
Expand Down Expand Up @@ -138,9 +137,6 @@ public function hasFunction(\PhpParser\Node\Name $nameNode, ?Scope $scope): bool
}

$functionReflection = $this->reflectionProvider->getFunction($nameNode, $scope);
if (!$functionReflection instanceof ReflectionWithFilename) {
return true;
}

return $functionReflection->getFileName() !== $this->singleReflectionInsteadOfFile;
}
Expand Down
11 changes: 0 additions & 11 deletions src/Reflection/ReflectionWithFilename.php

This file was deleted.

0 comments on commit 3738fcd

Please sign in to comment.