Skip to content
Draft
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
17 changes: 10 additions & 7 deletions src/Rules/FunctionCallParametersCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ public function check(
$functionParametersMaxCount = -1;
}

if (!$scope instanceof MutatingScope) {
throw new ShouldNotHappenException();
}

/** @var array<int, array{Expr, Type|null, bool, string|null, int}> $arguments */
$arguments = [];
/** @var array<int, Node\Arg> $args */
Expand All @@ -114,6 +118,10 @@ public function check(
$argumentName = $arg->name->toString();
}

if ($arg->value instanceof Expr\Assign) {
$scope = $scope->assignExpression($arg->value->var, $scope->getType($arg->value->expr), $scope->getNativeType($arg->value->expr));
}

if ($hasNamedArguments && $arg->unpack) {
$errors[] = RuleErrorBuilder::message('Named argument cannot be followed by an unpacked (...) argument.')
->identifier('argument.unpackAfterNamed')
Expand Down Expand Up @@ -318,14 +326,9 @@ public function check(
}

if ($argumentValueType === null) {
if ($scope instanceof MutatingScope) {
$scope = $scope->pushInFunctionCall(null, $parameter);
}
$scope = $scope->pushInFunctionCall(null, $parameter);
$argumentValueType = $scope->getType($argumentValue);

if ($scope instanceof MutatingScope) {
$scope = $scope->popInFunctionCall();
}
$scope = $scope->popInFunctionCall();
}

if (!$acceptsNamedArguments->yes()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2317,4 +2317,11 @@ public function testBug12317(): void
]);
}

public function testBug12234(): void
{
$this->checkExplicitMixed = true;
$this->checkImplicitMixed = true;
$this->analyse([__DIR__ . '/data/bug-12234.php'], []);
}

}
18 changes: 18 additions & 0 deletions tests/PHPStan/Rules/Functions/data/bug-12234.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php declare(strict_types = 1);

namespace Bug12234;

class Foo {
public function getSize(): int {
return 0;
}
}

function bar(Foo $foo, int $b): true {
return true;
}

$test = bar(
$foo = new Foo(),
$foo->getSize(),
);
22 changes: 22 additions & 0 deletions tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3656,4 +3656,26 @@ public function testBug3396(): void
$this->analyse([__DIR__ . '/data/bug-3396.php'], []);
}

public function testBug12735(): void
{
$this->checkThisOnly = false;
$this->checkNullables = true;
$this->checkUnionTypes = true;
$this->checkExplicitMixed = true;
$this->checkImplicitMixed = true;

$this->analyse([__DIR__ . '/data/bug-12735.php'], []);
}

public function testBug12735b(): void
{
$this->checkThisOnly = false;
$this->checkNullables = true;
$this->checkUnionTypes = true;
$this->checkExplicitMixed = true;
$this->checkImplicitMixed = true;

$this->analyse([__DIR__ . '/data/bug-12735b.php'], []);
}

}
18 changes: 18 additions & 0 deletions tests/PHPStan/Rules/Methods/data/bug-12735.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Bug12735;

class HelloWorld
{
public function test(): void
{
$this->foo(
$now = new DateTimeImmutable(),
$now,
);

$this->foo($now, $now);
}

private function foo(DateTimeImmutable $a, DateTimeImmutable $b): void {}
}
25 changes: 25 additions & 0 deletions tests/PHPStan/Rules/Methods/data/bug-12735b.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Bug12735b;

use DateTimeImmutable;

class HelloWorld
{
public function test(): void
{
$now = null;
if (rand(0,1)) {
$now = new DateTimeImmutable();
}

$this->foo(
$now ??= new DateTimeImmutable(),
$now,
);

$this->foo($now, $now);
}

private function foo(DateTimeImmutable $a, DateTimeImmutable $b): void {}
}
Loading