Skip to content

Commit ad6703d

Browse files
committed
Remove unneded abstraction
1 parent 6ba24ff commit ad6703d

File tree

6 files changed

+30
-247
lines changed

6 files changed

+30
-247
lines changed

src/Reflection/Native/NativeMethodReflection.php

Lines changed: 4 additions & 4 deletions
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\TrinaryLogic;
1414
use PHPStan\Type\Type;
@@ -26,7 +26,7 @@ class NativeMethodReflection implements ExtendedMethodReflection
2626
public function __construct(
2727
private ReflectionProvider $reflectionProvider,
2828
private ClassReflection $declaringClass,
29-
private BuiltinMethodReflection $reflection,
29+
private ReflectionMethod $reflection,
3030
private array $variants,
3131
private ?array $namedArgumentsVariants,
3232
private TrinaryLogic $hasSideEffects,
@@ -116,7 +116,7 @@ public function getDeprecatedDescription(): ?string
116116

117117
public function isDeprecated(): TrinaryLogic
118118
{
119-
return $this->reflection->isDeprecated();
119+
return TrinaryLogic::createFromBoolean($this->reflection->isDeprecated());
120120
}
121121

122122
public function isInternal(): TrinaryLogic
@@ -181,7 +181,7 @@ public function getSelfOutType(): ?Type
181181

182182
public function returnsByReference(): TrinaryLogic
183183
{
184-
return $this->reflection->returnsByReference();
184+
return TrinaryLogic::createFromBoolean($this->reflection->returnsReference());
185185
}
186186

187187
}

src/Reflection/Php/BuiltinMethodReflection.php

Lines changed: 0 additions & 60 deletions
This file was deleted.

src/Reflection/Php/NativeBuiltinMethodReflection.php

Lines changed: 0 additions & 149 deletions
This file was deleted.

src/Reflection/Php/PhpClassReflectionExtension.php

Lines changed: 20 additions & 30 deletions
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;
@@ -380,7 +381,7 @@ public function getMethod(ClassReflection $classReflection, string $methodName):
380381
return $this->methodsIncludingAnnotations[$classReflection->getCacheKey()][$methodName];
381382
}
382383

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

410-
$nativeMethodReflection = new NativeBuiltinMethodReflection(
411-
$classReflection->getNativeReflection()->getMethod($methodName),
412-
);
411+
$nativeMethodReflection = $classReflection->getNativeReflection()->getMethod($methodName);
413412

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

422421
private function createMethod(
423422
ClassReflection $classReflection,
424-
BuiltinMethodReflection $methodReflection,
423+
ReflectionMethod $methodReflection,
425424
bool $includingAnnotations,
426425
): ExtendedMethodReflection
427426
{
@@ -624,20 +623,18 @@ private function createMethod(
624623
$stubPhpDocPair = $this->findMethodPhpDocIncludingAncestors($declaringClass, $methodReflection->getName(), array_map(static fn (ReflectionParameter $parameter): string => $parameter->getName(), $methodReflection->getParameters()));
625624
$phpDocBlockClassReflection = $declaringClass;
626625

627-
if ($methodReflection->getReflection() !== null) {
628-
$methodDeclaringClass = $methodReflection->getReflection()->getBetterReflection()->getDeclaringClass();
629-
630-
if ($stubPhpDocPair === null && $methodDeclaringClass->isTrait()) {
631-
if (! $methodReflection->getDeclaringClass()->isTrait() || $methodDeclaringClass->getName() !== $methodReflection->getDeclaringClass()->getName()) {
632-
$stubPhpDocPair = $this->findMethodPhpDocIncludingAncestors(
633-
$this->reflectionProviderProvider->getReflectionProvider()->getClass($methodDeclaringClass->getName()),
634-
$methodReflection->getName(),
635-
array_map(
636-
static fn (ReflectionParameter $parameter): string => $parameter->getName(),
637-
$methodReflection->getParameters(),
638-
),
639-
);
640-
}
626+
$methodDeclaringClass = $methodReflection->getBetterReflection()->getDeclaringClass();
627+
628+
if ($stubPhpDocPair === null && $methodDeclaringClass->isTrait()) {
629+
if (! $methodReflection->getDeclaringClass()->isTrait() || $methodDeclaringClass->getName() !== $methodReflection->getDeclaringClass()->getName()) {
630+
$stubPhpDocPair = $this->findMethodPhpDocIncludingAncestors(
631+
$this->reflectionProviderProvider->getReflectionProvider()->getClass($methodDeclaringClass->getName()),
632+
$methodReflection->getName(),
633+
array_map(
634+
static fn (ReflectionParameter $parameter): string => $parameter->getName(),
635+
$methodReflection->getParameters(),
636+
),
637+
);
641638
}
642639
}
643640

@@ -646,7 +643,7 @@ private function createMethod(
646643
}
647644

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

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

671668
$phpDocParameterTypes = [];
672-
if (
673-
$methodReflection instanceof NativeBuiltinMethodReflection
674-
&& $methodReflection->isConstructor()
675-
) {
669+
if ($methodReflection->isConstructor()) {
676670
foreach ($methodReflection->getParameters() as $parameter) {
677671
if (!$parameter->isPromoted()) {
678672
continue;
@@ -863,14 +857,10 @@ private function findPropertyTrait(ReflectionProperty $propertyReflection): ?str
863857
}
864858

865859
private function findMethodTrait(
866-
BuiltinMethodReflection $methodReflection,
860+
ReflectionMethod $methodReflection,
867861
): ?string
868862
{
869-
if ($methodReflection->getReflection() === null) {
870-
return null;
871-
}
872-
873-
$declaringClass = $methodReflection->getReflection()->getBetterReflection()->getDeclaringClass();
863+
$declaringClass = $methodReflection->getBetterReflection()->getDeclaringClass();
874864
if ($declaringClass->isTrait()) {
875865
if ($methodReflection->getDeclaringClass()->isTrait() && $declaringClass->getName() === $methodReflection->getDeclaringClass()->getName()) {
876866
return null;

src/Reflection/Php/PhpMethodReflection.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PhpParser\Node\Stmt\Declare_;
88
use PhpParser\Node\Stmt\Function_;
99
use PhpParser\Node\Stmt\Namespace_;
10+
use PHPStan\BetterReflection\Reflection\Adapter\ReflectionMethod;
1011
use PHPStan\BetterReflection\Reflection\Adapter\ReflectionParameter;
1112
use PHPStan\Cache\Cache;
1213
use PHPStan\Parser\FunctionCallStatementFinder;
@@ -66,7 +67,7 @@ public function __construct(
6667
private InitializerExprTypeResolver $initializerExprTypeResolver,
6768
private ClassReflection $declaringClass,
6869
private ?ClassReflection $declaringTrait,
69-
private BuiltinMethodReflection $reflection,
70+
private ReflectionMethod $reflection,
7071
private ReflectionProvider $reflectionProvider,
7172
private Parser $parser,
7273
private FunctionCallStatementFinder $functionCallStatementFinder,
@@ -390,7 +391,7 @@ public function isDeprecated(): TrinaryLogic
390391
return TrinaryLogic::createYes();
391392
}
392393

393-
return $this->reflection->isDeprecated();
394+
return TrinaryLogic::createFromBoolean($this->reflection->isDeprecated());
394395
}
395396

396397
public function isInternal(): TrinaryLogic
@@ -450,7 +451,7 @@ public function getDocComment(): ?string
450451

451452
public function returnsByReference(): TrinaryLogic
452453
{
453-
return $this->reflection->returnsByReference();
454+
return TrinaryLogic::createFromBoolean($this->reflection->returnsReference());
454455
}
455456

456457
}

0 commit comments

Comments
 (0)