mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-17 21:38:22 +01:00
fix offset type (#5119)
* fix offset type * skip ChangeGlobalVariablesToPropertiesRector if empty
This commit is contained in:
parent
2cf2ee3f41
commit
7d441c1806
@ -5,6 +5,8 @@ declare(strict_types=1);
|
||||
namespace Rector\PHPStanStaticTypeMapper\TypeMapper;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PHPStan\PhpDocParser\Ast\Type\ArrayTypeNode;
|
||||
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
|
||||
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
|
||||
use PHPStan\Type\Accessory\HasOffsetType;
|
||||
use PHPStan\Type\Type;
|
||||
@ -23,7 +25,7 @@ final class HasOffsetTypeMapper implements TypeMapperInterface
|
||||
*/
|
||||
public function mapToPHPStanPhpDocTypeNode(Type $type): TypeNode
|
||||
{
|
||||
throw new ShouldNotHappenException();
|
||||
return new ArrayTypeNode(new IdentifierTypeNode('mixed'));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -39,6 +41,6 @@ final class HasOffsetTypeMapper implements TypeMapperInterface
|
||||
*/
|
||||
public function mapToDocString(Type $type, ?Type $parentType = null): string
|
||||
{
|
||||
return 'hasOfset()';
|
||||
return 'mixed[]';
|
||||
}
|
||||
}
|
||||
|
@ -91,6 +91,10 @@ CODE_SAMPLE
|
||||
|
||||
$this->collectGlobalVariableNamesAndRefactorToPropertyFetch($node);
|
||||
|
||||
if ($this->globalVariableNames === []) {
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach ($this->globalVariableNames as $globalVariableName) {
|
||||
$this->addPropertyToClass($classLike, null, $globalVariableName);
|
||||
}
|
||||
|
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddArrayReturnDocTypeRector\Fixture;
|
||||
|
||||
final class HasOffset
|
||||
{
|
||||
private function convertArguments($service)
|
||||
{
|
||||
if (! is_array($service)) {
|
||||
return $service;
|
||||
}
|
||||
|
||||
if (! isset($service['arguments'])) {
|
||||
return $service;
|
||||
}
|
||||
|
||||
return $service;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddArrayReturnDocTypeRector\Fixture;
|
||||
|
||||
final class HasOffset
|
||||
{
|
||||
/**
|
||||
* @return mixed|mixed[]
|
||||
*/
|
||||
private function convertArguments($service)
|
||||
{
|
||||
if (! is_array($service)) {
|
||||
return $service;
|
||||
}
|
||||
|
||||
if (! isset($service['arguments'])) {
|
||||
return $service;
|
||||
}
|
||||
|
||||
return $service;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user