Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/Node/Printer/Printer.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
use PHPStan\Node\Expr\SetOffsetValueTypeExpr;
use PHPStan\Node\Expr\TypeExpr;
use PHPStan\Node\Expr\UnsetOffsetExpr;
use PHPStan\Node\FunctionCallableNode;
use PHPStan\Node\InstantiationCallableNode;
use PHPStan\Node\IssetExpr;
use PHPStan\Node\MethodCallableNode;
use PHPStan\Node\StaticMethodCallableNode;
use PHPStan\Type\VerbosityLevel;
use function sprintf;

Expand Down Expand Up @@ -134,4 +138,24 @@ protected function pPHPStan_Node_BooleanAndNode(BooleanAndNode $expr): string //
return sprintf('__phpstanBooleanAnd(%s, %s)', $this->p($expr->getOriginalNode()->left), $this->p($expr->getOriginalNode()->right));
}

protected function pPHPStan_Node_FunctionCallableNode(FunctionCallableNode $expr): string // phpcs:ignore
{
return sprintf('__phpstanFunctionCallable(%s)', $this->p($expr->getOriginalNode()));
}

protected function pPHPStan_Node_MethodCallableNode(MethodCallableNode $expr): string // phpcs:ignore
{
return sprintf('__phpstanMethodCallable(%s)', $this->p($expr->getOriginalNode()));
}

protected function pPHPStan_Node_StaticMethodCallableNode(StaticMethodCallableNode $expr): string // phpcs:ignore
{
return sprintf('__phpstanStaticMethodCallable(%s)', $this->p($expr->getOriginalNode()));
}

protected function pPHPStan_Node_InstantiationCallableNode(InstantiationCallableNode $expr): string // phpcs:ignore
{
return sprintf('__phpstanInstantiationCallable(%s)', $this->p($expr->getOriginalNode()));
}

}
10 changes: 10 additions & 0 deletions tests/PHPStan/Analyser/AnalyserIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1656,6 +1656,16 @@ public function testBug13945Two(): void
$this->assertNoErrors($errors);
}

public function testBug12246(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-12246.php');
$this->assertCount(4, $errors);
$this->assertSame('Do-while loop condition is always true.', $errors[0]->getMessage());
$this->assertSame('Do-while loop condition is always true.', $errors[1]->getMessage());
$this->assertSame('Do-while loop condition is always true.', $errors[2]->getMessage());
$this->assertSame('Cannot create callable from the new operator.', $errors[3]->getMessage());
}

public function testBigPhpdocArrayShape(): void
{
$errors = $this->runAnalyse(__DIR__ . '/nsrt/bug-14012b.php');
Expand Down
59 changes: 59 additions & 0 deletions tests/PHPStan/Analyser/data/bug-12246.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php declare(strict_types = 1);

namespace Bug12246;

final class FirstClassCallableInDo
{
public function getSubscribedEvents(): void
{
do {

} while ($this->textElement(...));
}

public function textElement(): int
{
return 1;
}
}

final class StaticFirstClassCallableInDo
{
public function getSubscribedEvents(): void
{
do {

} while (self::textElement(...));
}

static public function textElement(): int
{
return 1;
}
}

final class FunctionFirstClassCallableInDo
{
public function getSubscribedEvents(): void
{
do {

} while (doFoo(...));
}
}

function doFoo():int {
return 1;
}

final class InstationFirstClassCallableInDo
{
public function getSubscribedEvents(): void
{
do {

} while (new Foo(...));
}
}

class Foo {}
Loading