Skip to content

Commit

Permalink
Introducing ParameterReflection::isPassedByReference()
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Oct 16, 2016
1 parent 741f43a commit 424eb9d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/Analyser/NodeScopeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -683,21 +683,21 @@ private function hasStatementEarlyTermination(Node $statement, Scope $scope): bo
/**
* @param \PhpParser\Node\Expr $functionCall
* @param \PHPStan\Analyser\Scope $scope
* @return null|\ReflectionParameter[]
* @return null|\PHPStan\Reflection\ParameterReflection[]
*/
private function findParametersInFunctionCall(Expr $functionCall, Scope $scope)
{
if ($functionCall instanceof FuncCall && $functionCall->name instanceof Name) {
if ($this->broker->hasFunction($functionCall->name, $scope)) {
return $this->broker->getFunction($functionCall->name, $scope)->getNativeReflection()->getParameters();
return $this->broker->getFunction($functionCall->name, $scope)->getParameters();
}
} elseif ($functionCall instanceof MethodCall && is_string($functionCall->name)) {
$type = $scope->getType($functionCall->var);
if ($type->getClass() !== null && $this->broker->hasClass($type->getClass())) {
$classReflection = $this->broker->getClass($type->getClass())->getNativeReflection();
$classReflection = $this->broker->getClass($type->getClass());
$methodName = $functionCall->name;
if ($classReflection->hasMethod($methodName)) {
return $classReflection->getMethod($methodName)->getParameters();
if ($classReflection->hasMethod((string) $methodName)) {
return $classReflection->getMethod((string) $methodName)->getParameters();
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/Reflection/ParameterReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ public function isOptional(): bool;

public function getType(): Type;

public function isPassedByReference(): bool;

}
11 changes: 10 additions & 1 deletion src/Reflection/Php/DummyOptionalParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ class DummyOptionalParameter implements ParameterReflection
/** @var \PHPStan\Type\Type */
private $type;

public function __construct(string $name, Type $type)
/** @var bool */
private $passedByReference;

public function __construct(string $name, Type $type, bool $passedByReference = false)
{
$this->name = $name;
$this->type = $type;
$this->passedByReference = $passedByReference;
}

public function getName(): string
Expand All @@ -35,4 +39,9 @@ public function getType(): Type
return $this->type;
}

public function isPassedByReference(): bool
{
return $this->passedByReference;
}

}
5 changes: 5 additions & 0 deletions src/Reflection/Php/PhpParameterReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,9 @@ public function getType(): Type
return $this->type;
}

public function isPassedByReference(): bool
{
return $this->reflection->isPassedByReference();
}

}

0 comments on commit 424eb9d

Please sign in to comment.