Skip to content

Commit

Permalink
InClassMethodNode - add getClassReflection()
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jan 25, 2023
1 parent a79ad03 commit c4ee0b8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/Analyser/NodeScopeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,10 @@ private function processStmtNode(
$phpDocParameterOutTypes,
);

if (!$scope->isInClass()) {
throw new ShouldNotHappenException();
}

if ($stmt->name->toLowerString() === '__construct') {
foreach ($stmt->params as $param) {
if ($param->flags === 0) {
Expand All @@ -521,9 +525,6 @@ private function processStmtNode(
if ($param->getDocComment() !== null) {
$phpDoc = $param->getDocComment()->getText();
}
if (!$scope->isInClass()) {
throw new ShouldNotHappenException();
}
$nodeCallback(new ClassPropertyNode(
$param->var->name,
$param->flags,
Expand All @@ -546,7 +547,7 @@ private function processStmtNode(
if (!$methodReflection instanceof ExtendedMethodReflection) {
throw new ShouldNotHappenException();
}
$nodeCallback(new InClassMethodNode($methodReflection, $stmt), $methodScope);
$nodeCallback(new InClassMethodNode($scope->getClassReflection(), $methodReflection, $stmt), $methodScope);
}

if ($stmt->stmts !== null) {
Expand Down
7 changes: 7 additions & 0 deletions src/Node/InClassMethodNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,27 @@
namespace PHPStan\Node;

use PhpParser\Node;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\ExtendedMethodReflection;

/** @api */
class InClassMethodNode extends Node\Stmt implements VirtualNode
{

public function __construct(
private ClassReflection $classReflection,
private ExtendedMethodReflection $methodReflection,
private Node\Stmt\ClassMethod $originalNode,
)
{
parent::__construct($originalNode->getAttributes());
}

public function getClassReflection(): ClassReflection
{
return $this->classReflection;
}

public function getMethodReflection(): ExtendedMethodReflection
{
return $this->methodReflection;
Expand Down

0 comments on commit c4ee0b8

Please sign in to comment.