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
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Rector\Tests\TypeDeclarationDocblocks\Rector\Class_\ClassMethodArrayDocblockParamFromLocalCallsRector\Fixture;

class MixedFromUnserialize
{
public function run(string $param)
{
$this->doStuff(unserialize($param));
}

private function doStuff(array $value)
{
// do stuff with value
}
}

?>
-----
<?php

namespace Rector\Tests\TypeDeclarationDocblocks\Rector\Class_\ClassMethodArrayDocblockParamFromLocalCallsRector\Fixture;

class MixedFromUnserialize
{
public function run(string $param)
{
$this->doStuff(unserialize($param));
}

/**
* @param mixed[] $value
*/
private function doStuff(array $value)
{
// do stuff with value
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Rector\TypeDeclaration\NodeAnalyzer\ReturnTypeAnalyzer;

use PHPStan\Type\ObjectWithoutClassType;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\New_;
Expand Down Expand Up @@ -53,7 +54,7 @@ public function matchAlwaysReturnVariableNew(ClassMethod|Function_ $functionLike
}

$returnType = $this->nodeTypeResolver->getNativeType($return->expr);
if ($returnType instanceof \PHPStan\Type\ObjectWithoutClassType) {
if ($returnType instanceof ObjectWithoutClassType) {
$alwaysReturnedClassNames[] = 'object';
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use PhpParser\Node;
use PhpParser\Node\Stmt\Class_;
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
use PHPStan\PhpDocParser\Ast\Type\ArrayTypeNode;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use PHPStan\Type\ArrayType;
use PHPStan\Type\IntegerType;
use PHPStan\Type\MixedType;
Expand Down Expand Up @@ -132,6 +134,10 @@ public function refactor(Node $node): ?Node
$normalizedResolvedParameterType
);

if ($arrayDocTypeNode instanceof IdentifierTypeNode && $arrayDocTypeNode->name === 'mixed') {
$arrayDocTypeNode = new ArrayTypeNode($arrayDocTypeNode);
}

$paramTagValueNode = new ParamTagValueNode($arrayDocTypeNode, false, '$' . $parameterName, '', false);
$classMethodPhpDocInfo->addTagValueNode($paramTagValueNode);

Expand Down
Loading