Skip to content

Commit f302c90

Browse files
committed
Remove unneded abstraction
1 parent e75996b commit f302c90

8 files changed

+34
-251
lines changed

Diff for: src/Reflection/Native/NativeMethodReflection.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
namespace PHPStan\Reflection\Native;
44

5+
use PHPStan\BetterReflection\Reflection\Adapter\ReflectionMethod;
56
use PHPStan\Reflection\Assertions;
67
use PHPStan\Reflection\ClassMemberReflection;
78
use PHPStan\Reflection\ClassReflection;
89
use PHPStan\Reflection\ExtendedMethodReflection;
910
use PHPStan\Reflection\MethodPrototypeReflection;
1011
use PHPStan\Reflection\ParametersAcceptorWithPhpDocs;
11-
use PHPStan\Reflection\Php\BuiltinMethodReflection;
1212
use PHPStan\Reflection\ReflectionProvider;
1313
use PHPStan\ShouldNotHappenException;
1414
use PHPStan\TrinaryLogic;
@@ -28,7 +28,7 @@ final class NativeMethodReflection implements ExtendedMethodReflection
2828
public function __construct(
2929
private ReflectionProvider $reflectionProvider,
3030
private ClassReflection $declaringClass,
31-
private BuiltinMethodReflection $reflection,
31+
private ReflectionMethod $reflection,
3232
private array $variants,
3333
private ?array $namedArgumentsVariants,
3434
private TrinaryLogic $hasSideEffects,
@@ -133,7 +133,7 @@ public function getDeprecatedDescription(): ?string
133133

134134
public function isDeprecated(): TrinaryLogic
135135
{
136-
return $this->reflection->isDeprecated();
136+
return TrinaryLogic::createFromBoolean($this->reflection->isDeprecated());
137137
}
138138

139139
public function isInternal(): TrinaryLogic
@@ -212,7 +212,7 @@ public function getSelfOutType(): ?Type
212212

213213
public function returnsByReference(): TrinaryLogic
214214
{
215-
return $this->reflection->returnsByReference();
215+
return TrinaryLogic::createFromBoolean($this->reflection->returnsReference());
216216
}
217217

218218
}

Diff for: src/Reflection/Php/BuiltinMethodReflection.php

-60
This file was deleted.

Diff for: src/Reflection/Php/NativeBuiltinMethodReflection.php

-148
This file was deleted.

Diff for: src/Reflection/Php/PhpClassReflectionExtension.php

+22-31
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use PHPStan\Analyser\NodeScopeResolver;
1111
use PHPStan\Analyser\ScopeContext;
1212
use PHPStan\Analyser\ScopeFactory;
13+
use PHPStan\BetterReflection\Reflection\Adapter\ReflectionMethod;
1314
use PHPStan\BetterReflection\Reflection\Adapter\ReflectionParameter;
1415
use PHPStan\BetterReflection\Reflection\Adapter\ReflectionProperty;
1516
use PHPStan\Parser\Parser;
@@ -384,7 +385,7 @@ public function getMethod(ClassReflection $classReflection, string $methodName):
384385
return $this->methodsIncludingAnnotations[$classReflection->getCacheKey()][$methodName];
385386
}
386387

387-
$nativeMethodReflection = new NativeBuiltinMethodReflection($classReflection->getNativeReflection()->getMethod($methodName));
388+
$nativeMethodReflection = $classReflection->getNativeReflection()->getMethod($methodName);
388389
if (!isset($this->methodsIncludingAnnotations[$classReflection->getCacheKey()][$nativeMethodReflection->getName()])) {
389390
$method = $this->createMethod($classReflection, $nativeMethodReflection, true);
390391
$this->methodsIncludingAnnotations[$classReflection->getCacheKey()][$nativeMethodReflection->getName()] = $method;
@@ -411,8 +412,7 @@ public function getNativeMethod(ClassReflection $classReflection, string $method
411412
throw new ShouldNotHappenException();
412413
}
413414

414-
$reflectionMethod = $classReflection->getNativeReflection()->getMethod($methodName);
415-
$nativeMethodReflection = new NativeBuiltinMethodReflection($reflectionMethod);
415+
$nativeMethodReflection = $classReflection->getNativeReflection()->getMethod($methodName);
416416

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

425425
private function createMethod(
426426
ClassReflection $classReflection,
427-
BuiltinMethodReflection $methodReflection,
427+
ReflectionMethod $methodReflection,
428428
bool $includingAnnotations,
429429
): ExtendedMethodReflection
430430
{
@@ -642,27 +642,25 @@ private function createMethod(
642642
);
643643
}
644644

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

651-
if ($methodReflection->getReflection() !== null) {
652-
$methodDeclaringClass = $methodReflection->getReflection()->getBetterReflection()->getDeclaringClass();
653-
654-
if ($stubPhpDocPair === null && $methodDeclaringClass->isTrait()) {
655-
if (! $methodReflection->getDeclaringClass()->isTrait() || $methodDeclaringClass->getName() !== $methodReflection->getDeclaringClass()->getName()) {
656-
$stubPhpDocPair = $this->findMethodPhpDocIncludingAncestors(
657-
$this->reflectionProviderProvider->getReflectionProvider()->getClass($methodDeclaringClass->getName()),
658-
$this->reflectionProviderProvider->getReflectionProvider()->getClass($methodReflection->getDeclaringClass()->getName()),
659-
$methodReflection->getName(),
660-
array_map(
661-
static fn (ReflectionParameter $parameter): string => $parameter->getName(),
662-
$methodReflection->getParameters(),
663-
),
664-
);
665-
}
651+
$methodDeclaringClass = $methodReflection->getBetterReflection()->getDeclaringClass();
652+
653+
if ($stubPhpDocPair === null && $methodDeclaringClass->isTrait()) {
654+
if (! $methodReflection->getDeclaringClass()->isTrait() || $methodDeclaringClass->getName() !== $methodReflection->getDeclaringClass()->getName()) {
655+
$stubPhpDocPair = $this->findMethodPhpDocIncludingAncestors(
656+
$this->reflectionProviderProvider->getReflectionProvider()->getClass($methodDeclaringClass->getName()),
657+
$this->reflectionProviderProvider->getReflectionProvider()->getClass($methodReflection->getDeclaringClass()->getName()),
658+
$methodReflection->getName(),
659+
array_map(
660+
static fn (ReflectionParameter $parameter): string => $parameter->getName(),
661+
$methodReflection->getParameters(),
662+
),
663+
);
666664
}
667665
}
668666

@@ -671,7 +669,7 @@ public function createUserlandMethodReflection(ClassReflection $fileDeclaringCla
671669
}
672670

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

677675
$resolvedPhpDoc = $this->phpDocInheritanceResolver->resolvePhpDocForMethod(
@@ -694,10 +692,7 @@ public function createUserlandMethodReflection(ClassReflection $fileDeclaringCla
694692
}
695693

696694
$phpDocParameterTypes = [];
697-
if (
698-
$methodReflection instanceof NativeBuiltinMethodReflection
699-
&& $methodReflection->isConstructor()
700-
) {
695+
if ($methodReflection->isConstructor()) {
701696
foreach ($methodReflection->getParameters() as $parameter) {
702697
if (!$parameter->isPromoted()) {
703698
continue;
@@ -922,14 +917,10 @@ private function findPropertyTrait(ReflectionProperty $propertyReflection): ?str
922917
}
923918

924919
private function findMethodTrait(
925-
BuiltinMethodReflection $methodReflection,
920+
ReflectionMethod $methodReflection,
926921
): ?string
927922
{
928-
if ($methodReflection->getReflection() === null) {
929-
return null;
930-
}
931-
932-
$declaringClass = $methodReflection->getReflection()->getBetterReflection()->getDeclaringClass();
923+
$declaringClass = $methodReflection->getBetterReflection()->getDeclaringClass();
933924
if ($declaringClass->isTrait()) {
934925
if ($methodReflection->getDeclaringClass()->isTrait() && $declaringClass->getName() === $methodReflection->getDeclaringClass()->getName()) {
935926
return null;

0 commit comments

Comments
 (0)