Skip to content

Commit

Permalink
Remove unneded abstraction
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Nov 19, 2023
1 parent 6ba24ff commit ad6703d
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 247 deletions.
8 changes: 4 additions & 4 deletions src/Reflection/Native/NativeMethodReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace PHPStan\Reflection\Native;

use PHPStan\BetterReflection\Reflection\Adapter\ReflectionMethod;
use PHPStan\Reflection\Assertions;
use PHPStan\Reflection\ClassMemberReflection;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\ExtendedMethodReflection;
use PHPStan\Reflection\MethodPrototypeReflection;
use PHPStan\Reflection\ParametersAcceptorWithPhpDocs;
use PHPStan\Reflection\Php\BuiltinMethodReflection;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\TrinaryLogic;
use PHPStan\Type\Type;
Expand All @@ -26,7 +26,7 @@ class NativeMethodReflection implements ExtendedMethodReflection
public function __construct(
private ReflectionProvider $reflectionProvider,
private ClassReflection $declaringClass,
private BuiltinMethodReflection $reflection,
private ReflectionMethod $reflection,
private array $variants,
private ?array $namedArgumentsVariants,
private TrinaryLogic $hasSideEffects,
Expand Down Expand Up @@ -116,7 +116,7 @@ public function getDeprecatedDescription(): ?string

public function isDeprecated(): TrinaryLogic
{
return $this->reflection->isDeprecated();
return TrinaryLogic::createFromBoolean($this->reflection->isDeprecated());
}

public function isInternal(): TrinaryLogic
Expand Down Expand Up @@ -181,7 +181,7 @@ public function getSelfOutType(): ?Type

public function returnsByReference(): TrinaryLogic
{
return $this->reflection->returnsByReference();
return TrinaryLogic::createFromBoolean($this->reflection->returnsReference());
}

}
60 changes: 0 additions & 60 deletions src/Reflection/Php/BuiltinMethodReflection.php

This file was deleted.

149 changes: 0 additions & 149 deletions src/Reflection/Php/NativeBuiltinMethodReflection.php

This file was deleted.

50 changes: 20 additions & 30 deletions src/Reflection/Php/PhpClassReflectionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use PHPStan\Analyser\NodeScopeResolver;
use PHPStan\Analyser\ScopeContext;
use PHPStan\Analyser\ScopeFactory;
use PHPStan\BetterReflection\Reflection\Adapter\ReflectionMethod;
use PHPStan\BetterReflection\Reflection\Adapter\ReflectionParameter;
use PHPStan\BetterReflection\Reflection\Adapter\ReflectionProperty;
use PHPStan\Parser\Parser;
Expand Down Expand Up @@ -380,7 +381,7 @@ public function getMethod(ClassReflection $classReflection, string $methodName):
return $this->methodsIncludingAnnotations[$classReflection->getCacheKey()][$methodName];
}

$nativeMethodReflection = new NativeBuiltinMethodReflection($classReflection->getNativeReflection()->getMethod($methodName));
$nativeMethodReflection = $classReflection->getNativeReflection()->getMethod($methodName);
if (!isset($this->methodsIncludingAnnotations[$classReflection->getCacheKey()][$nativeMethodReflection->getName()])) {
$method = $this->createMethod($classReflection, $nativeMethodReflection, true);
$this->methodsIncludingAnnotations[$classReflection->getCacheKey()][$nativeMethodReflection->getName()] = $method;
Expand All @@ -407,9 +408,7 @@ public function getNativeMethod(ClassReflection $classReflection, string $method
throw new ShouldNotHappenException();
}

$nativeMethodReflection = new NativeBuiltinMethodReflection(
$classReflection->getNativeReflection()->getMethod($methodName),
);
$nativeMethodReflection = $classReflection->getNativeReflection()->getMethod($methodName);

if (!isset($this->nativeMethods[$classReflection->getCacheKey()][$nativeMethodReflection->getName()])) {
$method = $this->createMethod($classReflection, $nativeMethodReflection, false);
Expand All @@ -421,7 +420,7 @@ public function getNativeMethod(ClassReflection $classReflection, string $method

private function createMethod(
ClassReflection $classReflection,
BuiltinMethodReflection $methodReflection,
ReflectionMethod $methodReflection,
bool $includingAnnotations,
): ExtendedMethodReflection
{
Expand Down Expand Up @@ -624,20 +623,18 @@ private function createMethod(
$stubPhpDocPair = $this->findMethodPhpDocIncludingAncestors($declaringClass, $methodReflection->getName(), array_map(static fn (ReflectionParameter $parameter): string => $parameter->getName(), $methodReflection->getParameters()));
$phpDocBlockClassReflection = $declaringClass;

if ($methodReflection->getReflection() !== null) {
$methodDeclaringClass = $methodReflection->getReflection()->getBetterReflection()->getDeclaringClass();

if ($stubPhpDocPair === null && $methodDeclaringClass->isTrait()) {
if (! $methodReflection->getDeclaringClass()->isTrait() || $methodDeclaringClass->getName() !== $methodReflection->getDeclaringClass()->getName()) {
$stubPhpDocPair = $this->findMethodPhpDocIncludingAncestors(
$this->reflectionProviderProvider->getReflectionProvider()->getClass($methodDeclaringClass->getName()),
$methodReflection->getName(),
array_map(
static fn (ReflectionParameter $parameter): string => $parameter->getName(),
$methodReflection->getParameters(),
),
);
}
$methodDeclaringClass = $methodReflection->getBetterReflection()->getDeclaringClass();

if ($stubPhpDocPair === null && $methodDeclaringClass->isTrait()) {
if (! $methodReflection->getDeclaringClass()->isTrait() || $methodDeclaringClass->getName() !== $methodReflection->getDeclaringClass()->getName()) {
$stubPhpDocPair = $this->findMethodPhpDocIncludingAncestors(
$this->reflectionProviderProvider->getReflectionProvider()->getClass($methodDeclaringClass->getName()),
$methodReflection->getName(),
array_map(
static fn (ReflectionParameter $parameter): string => $parameter->getName(),
$methodReflection->getParameters(),
),
);
}
}

Expand All @@ -646,7 +643,7 @@ private function createMethod(
}

if ($resolvedPhpDoc === null) {
$docComment = $methodReflection->getDocComment();
$docComment = $methodReflection->getDocComment() !== false ? $methodReflection->getDocComment() : null;
$positionalParameterNames = array_map(static fn (ReflectionParameter $parameter): string => $parameter->getName(), $methodReflection->getParameters());

$resolvedPhpDoc = $this->phpDocInheritanceResolver->resolvePhpDocForMethod(
Expand All @@ -669,10 +666,7 @@ private function createMethod(
}

$phpDocParameterTypes = [];
if (
$methodReflection instanceof NativeBuiltinMethodReflection
&& $methodReflection->isConstructor()
) {
if ($methodReflection->isConstructor()) {
foreach ($methodReflection->getParameters() as $parameter) {
if (!$parameter->isPromoted()) {
continue;
Expand Down Expand Up @@ -863,14 +857,10 @@ private function findPropertyTrait(ReflectionProperty $propertyReflection): ?str
}

private function findMethodTrait(
BuiltinMethodReflection $methodReflection,
ReflectionMethod $methodReflection,
): ?string
{
if ($methodReflection->getReflection() === null) {
return null;
}

$declaringClass = $methodReflection->getReflection()->getBetterReflection()->getDeclaringClass();
$declaringClass = $methodReflection->getBetterReflection()->getDeclaringClass();
if ($declaringClass->isTrait()) {
if ($methodReflection->getDeclaringClass()->isTrait() && $declaringClass->getName() === $methodReflection->getDeclaringClass()->getName()) {
return null;
Expand Down
7 changes: 4 additions & 3 deletions src/Reflection/Php/PhpMethodReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PhpParser\Node\Stmt\Declare_;
use PhpParser\Node\Stmt\Function_;
use PhpParser\Node\Stmt\Namespace_;
use PHPStan\BetterReflection\Reflection\Adapter\ReflectionMethod;
use PHPStan\BetterReflection\Reflection\Adapter\ReflectionParameter;
use PHPStan\Cache\Cache;
use PHPStan\Parser\FunctionCallStatementFinder;
Expand Down Expand Up @@ -66,7 +67,7 @@ public function __construct(
private InitializerExprTypeResolver $initializerExprTypeResolver,
private ClassReflection $declaringClass,
private ?ClassReflection $declaringTrait,
private BuiltinMethodReflection $reflection,
private ReflectionMethod $reflection,
private ReflectionProvider $reflectionProvider,
private Parser $parser,
private FunctionCallStatementFinder $functionCallStatementFinder,
Expand Down Expand Up @@ -390,7 +391,7 @@ public function isDeprecated(): TrinaryLogic
return TrinaryLogic::createYes();
}

return $this->reflection->isDeprecated();
return TrinaryLogic::createFromBoolean($this->reflection->isDeprecated());
}

public function isInternal(): TrinaryLogic
Expand Down Expand Up @@ -450,7 +451,7 @@ public function getDocComment(): ?string

public function returnsByReference(): TrinaryLogic
{
return $this->reflection->returnsByReference();
return TrinaryLogic::createFromBoolean($this->reflection->returnsReference());
}

}

0 comments on commit ad6703d

Please sign in to comment.