Skip to content
Closed
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
16 changes: 12 additions & 4 deletions src/Analyser/ExprHandler/MethodCallHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,27 +288,35 @@
{
if ($expr->name instanceof Identifier) {
if ($scope->nativeTypesPromoted) {
$nativeType = $scope->getNativeType($expr->var);
$methodReflection = $scope->getMethodReflection(
$scope->getNativeType($expr->var),
$nativeType,
$expr->name->name,
);
if ($methodReflection === null) {
$returnType = new ErrorType();
$nativeObjectType = $nativeType->getObjectTypeOrClassStringObjectType();
$returnType = $nativeObjectType->isObject()->yes() && $nativeObjectType->getObjectClassNames() === []

Check warning on line 298 in src/Analyser/ExprHandler/MethodCallHandler.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.4, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ ); if ($methodReflection === null) { $nativeObjectType = $nativeType->getObjectTypeOrClassStringObjectType(); - $returnType = $nativeObjectType->isObject()->yes() && $nativeObjectType->getObjectClassNames() === [] + $returnType = !$nativeObjectType->isObject()->no() && $nativeObjectType->getObjectClassNames() === [] ? new MixedType() : new ErrorType(); } else {

Check warning on line 298 in src/Analyser/ExprHandler/MethodCallHandler.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.3, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ ); if ($methodReflection === null) { $nativeObjectType = $nativeType->getObjectTypeOrClassStringObjectType(); - $returnType = $nativeObjectType->isObject()->yes() && $nativeObjectType->getObjectClassNames() === [] + $returnType = !$nativeObjectType->isObject()->no() && $nativeObjectType->getObjectClassNames() === [] ? new MixedType() : new ErrorType(); } else {
? new MixedType()
: new ErrorType();
} else {
$returnType = ParametersAcceptorSelector::combineAcceptors($methodReflection->getVariants())->getNativeReturnType();
}

return NullsafeShortCircuitingHelper::getType($scope, $expr->var, $returnType);
}

$calledOnType = $scope->getType($expr->var);
$returnType = $this->methodCallReturnTypeHelper->methodCallReturnType(
$scope,
$scope->getType($expr->var),
$calledOnType,
$expr->name->name,
$expr,
);
if ($returnType === null) {
$returnType = new ErrorType();
$objectType = $calledOnType->getObjectTypeOrClassStringObjectType();
$returnType = $objectType->isObject()->yes() && $objectType->getObjectClassNames() === []

Check warning on line 317 in src/Analyser/ExprHandler/MethodCallHandler.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.4, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ ); if ($returnType === null) { $objectType = $calledOnType->getObjectTypeOrClassStringObjectType(); - $returnType = $objectType->isObject()->yes() && $objectType->getObjectClassNames() === [] + $returnType = !$objectType->isObject()->no() && $objectType->getObjectClassNames() === [] ? new MixedType() : new ErrorType(); }

Check warning on line 317 in src/Analyser/ExprHandler/MethodCallHandler.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.3, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ ); if ($returnType === null) { $objectType = $calledOnType->getObjectTypeOrClassStringObjectType(); - $returnType = $objectType->isObject()->yes() && $objectType->getObjectClassNames() === [] + $returnType = !$objectType->isObject()->no() && $objectType->getObjectClassNames() === [] ? new MixedType() : new ErrorType(); }
? new MixedType()
: new ErrorType();
}
return NullsafeShortCircuitingHelper::getType($scope, $expr->var, $returnType);
}
Expand Down
7 changes: 5 additions & 2 deletions src/Analyser/ExprHandler/StaticCallHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,14 +335,17 @@
$staticMethodCalledOnType = TypeCombinator::removeNull($scope->getType($expr->class))->getObjectTypeOrClassStringObjectType();
}

$methodName = $expr->name->toString();
$callType = $this->methodCallReturnTypeHelper->methodCallReturnType(
$scope,
$staticMethodCalledOnType,
$expr->name->toString(),
$methodName,
$expr,
);
if ($callType === null) {
$callType = new ErrorType();
$callType = $staticMethodCalledOnType->isObject()->yes() && $staticMethodCalledOnType->getObjectClassNames() === []

Check warning on line 346 in src/Analyser/ExprHandler/StaticCallHandler.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.4, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ $expr, ); if ($callType === null) { - $callType = $staticMethodCalledOnType->isObject()->yes() && $staticMethodCalledOnType->getObjectClassNames() === [] + $callType = !$staticMethodCalledOnType->isObject()->no() && $staticMethodCalledOnType->getObjectClassNames() === [] ? new MixedType() : new ErrorType(); }

Check warning on line 346 in src/Analyser/ExprHandler/StaticCallHandler.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.3, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ $expr, ); if ($callType === null) { - $callType = $staticMethodCalledOnType->isObject()->yes() && $staticMethodCalledOnType->getObjectClassNames() === [] + $callType = !$staticMethodCalledOnType->isObject()->no() && $staticMethodCalledOnType->getObjectClassNames() === [] ? new MixedType() : new ErrorType(); }
? new MixedType()
: new ErrorType();
}

if ($expr->class instanceof Expr) {
Expand Down
22 changes: 22 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-9844.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php declare(strict_types = 1);

namespace Bug9844;

use function PHPStan\Testing\assertType;

class HelloWorld
{

/**
* @param class-string $class
*/
public function sayHello(string $class, string $method, string $property): void
{
assertType('mixed', $class::foo());
assertType('mixed', $class->foo());
assertType('mixed', $class?->foo());
assertType('mixed', $class::$method());
assertType('mixed', $class->$property);
assertType('mixed', $class?->$property);
}
}
Loading