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
3 changes: 3 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ parameters:
# phpstan class constant value
- identifier: phpstanApi.classConstant

# phpstan class construction
- identifier: phpstanApi.constructor

# phpstan instanceof
- identifier: phpstanApi.instanceofAssumption

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Rector\Tests\TypeDeclaration\Rector\StmtsAwareInterface\SafeDeclareStrictTypesRector\Fixture;

function skip_mixed_passed_to_round(array $data): float
{
return round($data['value'], 2);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use PHPStan\Reflection\Php\PhpPropertyReflection;
use PHPStan\Type\MixedType;
use PHPStan\Type\NeverType;
use PHPStan\Type\StrictMixedType;
use PHPStan\Type\Type;
use Rector\NodeTypeResolver\NodeTypeResolver;
use Rector\NodeTypeResolver\PHPStan\ParametersAcceptorSelectorVariantsWrapper;
Expand Down Expand Up @@ -197,6 +198,11 @@ private function isPropertyAssignSafe(Assign $assign): bool

private function isTypeSafeForStrictMode(Type $declaredType, Type $valueType): bool
{
// need to be strict with mixed to avoid false positives
if ($valueType instanceof MixedType) {
$valueType = new StrictMixedType();
}

return $declaredType->accepts($valueType, strictTypes: true)
->yes();
}
Expand Down