Skip to content

Commit c4ee0b8

Browse files
committed
InClassMethodNode - add getClassReflection()
1 parent a79ad03 commit c4ee0b8

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/Analyser/NodeScopeResolver.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,10 @@ private function processStmtNode(
508508
$phpDocParameterOutTypes,
509509
);
510510

511+
if (!$scope->isInClass()) {
512+
throw new ShouldNotHappenException();
513+
}
514+
511515
if ($stmt->name->toLowerString() === '__construct') {
512516
foreach ($stmt->params as $param) {
513517
if ($param->flags === 0) {
@@ -521,9 +525,6 @@ private function processStmtNode(
521525
if ($param->getDocComment() !== null) {
522526
$phpDoc = $param->getDocComment()->getText();
523527
}
524-
if (!$scope->isInClass()) {
525-
throw new ShouldNotHappenException();
526-
}
527528
$nodeCallback(new ClassPropertyNode(
528529
$param->var->name,
529530
$param->flags,
@@ -546,7 +547,7 @@ private function processStmtNode(
546547
if (!$methodReflection instanceof ExtendedMethodReflection) {
547548
throw new ShouldNotHappenException();
548549
}
549-
$nodeCallback(new InClassMethodNode($methodReflection, $stmt), $methodScope);
550+
$nodeCallback(new InClassMethodNode($scope->getClassReflection(), $methodReflection, $stmt), $methodScope);
550551
}
551552

552553
if ($stmt->stmts !== null) {

src/Node/InClassMethodNode.php

+7
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,27 @@
33
namespace PHPStan\Node;
44

55
use PhpParser\Node;
6+
use PHPStan\Reflection\ClassReflection;
67
use PHPStan\Reflection\ExtendedMethodReflection;
78

89
/** @api */
910
class InClassMethodNode extends Node\Stmt implements VirtualNode
1011
{
1112

1213
public function __construct(
14+
private ClassReflection $classReflection,
1315
private ExtendedMethodReflection $methodReflection,
1416
private Node\Stmt\ClassMethod $originalNode,
1517
)
1618
{
1719
parent::__construct($originalNode->getAttributes());
1820
}
1921

22+
public function getClassReflection(): ClassReflection
23+
{
24+
return $this->classReflection;
25+
}
26+
2027
public function getMethodReflection(): ExtendedMethodReflection
2128
{
2229
return $this->methodReflection;

0 commit comments

Comments
 (0)