Skip to content

Commit

Permalink
Remove unneded abstraction
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Sep 29, 2024
1 parent e75996b commit f302c90
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 251 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\ShouldNotHappenException;
use PHPStan\TrinaryLogic;
Expand All @@ -28,7 +28,7 @@ final 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 @@ -133,7 +133,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 @@ -212,7 +212,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.

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

This file was deleted.

53 changes: 22 additions & 31 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 @@ -384,7 +385,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 @@ -411,8 +412,7 @@ public function getNativeMethod(ClassReflection $classReflection, string $method
throw new ShouldNotHappenException();
}

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

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

private function createMethod(
ClassReflection $classReflection,
BuiltinMethodReflection $methodReflection,
ReflectionMethod $methodReflection,
bool $includingAnnotations,
): ExtendedMethodReflection
{
Expand Down Expand Up @@ -642,27 +642,25 @@ private function createMethod(
);
}

public function createUserlandMethodReflection(ClassReflection $fileDeclaringClass, ClassReflection $actualDeclaringClass, BuiltinMethodReflection $methodReflection, ?string $declaringTraitName): PhpMethodReflection
public function createUserlandMethodReflection(ClassReflection $fileDeclaringClass, ClassReflection $actualDeclaringClass, ReflectionMethod $methodReflection, ?string $declaringTraitName): PhpMethodReflection
{
$resolvedPhpDoc = null;
$stubPhpDocPair = $this->findMethodPhpDocIncludingAncestors($fileDeclaringClass, $fileDeclaringClass, $methodReflection->getName(), array_map(static fn (ReflectionParameter $parameter): string => $parameter->getName(), $methodReflection->getParameters()));
$phpDocBlockClassReflection = $fileDeclaringClass;

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()),
$this->reflectionProviderProvider->getReflectionProvider()->getClass($methodReflection->getDeclaringClass()->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()),
$this->reflectionProviderProvider->getReflectionProvider()->getClass($methodReflection->getDeclaringClass()->getName()),
$methodReflection->getName(),
array_map(
static fn (ReflectionParameter $parameter): string => $parameter->getName(),
$methodReflection->getParameters(),
),
);
}
}

Expand All @@ -671,7 +669,7 @@ public function createUserlandMethodReflection(ClassReflection $fileDeclaringCla
}

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 @@ -694,10 +692,7 @@ public function createUserlandMethodReflection(ClassReflection $fileDeclaringCla
}

$phpDocParameterTypes = [];
if (
$methodReflection instanceof NativeBuiltinMethodReflection
&& $methodReflection->isConstructor()
) {
if ($methodReflection->isConstructor()) {
foreach ($methodReflection->getParameters() as $parameter) {
if (!$parameter->isPromoted()) {
continue;
Expand Down Expand Up @@ -922,14 +917,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
Loading

0 comments on commit f302c90

Please sign in to comment.