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,22 @@
<?php

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\AddParamFromDimFetchKeyUseRector\Fixture;

use Rector\Tests\TypeDeclaration\Rector\ClassMethod\AddParamFromDimFetchKeyUseRector\Source\SomeObjectValidation;

class SkipWithIsArray
{
/**
* @param SomeObjectValidation $object
* @param array<int, int|string>|string $key
*/
public function __construct($object, $key)
{
if (\is_array($key) && (string) $object->{$key[1]} !== '') {
}

if (isset($object->validation_errors[$key])) {
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\AddParamFromDimFetchKeyUseRector\Source;

class SomeObjectValidation {
/**
* Array of validation error text messages.
*
* @var array<string, string>
*/
public $validation_errors = [];
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
namespace Rector\TypeDeclaration\Rector\ClassMethod;

use PhpParser\Node;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt\Class_;
use PHPStan\Type\ArrayType;
use PHPStan\Type\Constant\ConstantArrayType;
use PHPStan\Type\UnionType;
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
use Rector\Rector\AbstractRector;
use Rector\StaticTypeMapper\StaticTypeMapper;
Expand Down Expand Up @@ -113,6 +115,13 @@ public function refactor(Node $node): ?Node
continue;
}

if ($dimFetch->dim instanceof Variable) {
$type = $this->nodeTypeResolver->getType($dimFetch->dim);
if ($type instanceof UnionType) {
continue;
}
}

$paramTypeNode = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode(
$dimFetchType->getKeyType(),
TypeKind::PARAM
Expand Down