mirror of
https://github.com/rectorphp/rector.git
synced 2024-05-28 23:10:51 +00:00
[types] Add HasPropertyTypeMapepr and HasMethodTypeMapper (#1731)
* Add HasPropertyTypeMapper * add has Method type mapper
This commit is contained in:
parent
a26c59a7e9
commit
75c0b27d37
|
@ -7,7 +7,7 @@
|
|||
],
|
||||
"require": {
|
||||
"php": "^7.1|^8.0",
|
||||
"phpstan/phpstan": "^1.4"
|
||||
"phpstan/phpstan": "^1.4.2"
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
"nette/utils": "^3.2",
|
||||
"nikic/php-parser": "^4.13.2",
|
||||
"phpstan/phpdoc-parser": "^1.2",
|
||||
"phpstan/phpstan": "^1.4",
|
||||
"phpstan/phpstan": "^1.4.2",
|
||||
"phpstan/phpstan-phpunit": "^1.0",
|
||||
"psr/log": "^2.0",
|
||||
"react/child-process": "^0.6.4",
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\PHPStanStaticTypeMapper\TypeMapper;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
|
||||
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
|
||||
use PHPStan\Type\Accessory\HasMethodType;
|
||||
use PHPStan\Type\Type;
|
||||
use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface;
|
||||
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
|
||||
|
||||
/**
|
||||
* @implements TypeMapperInterface<HasMethodType>
|
||||
*/
|
||||
final class HasMethodTypeMapper implements TypeMapperInterface
|
||||
{
|
||||
public function __construct(
|
||||
private readonly ObjectWithoutClassTypeMapper $objectWithoutClassTypeMapper
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return class-string<Type>
|
||||
*/
|
||||
public function getNodeClass(): string
|
||||
{
|
||||
return HasMethodType::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param HasMethodType $type
|
||||
*/
|
||||
public function mapToPHPStanPhpDocTypeNode(Type $type, TypeKind $typeKind): TypeNode
|
||||
{
|
||||
return new IdentifierTypeNode('object');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param HasMethodType $type
|
||||
*/
|
||||
public function mapToPhpParserNode(Type $type, TypeKind $typeKind): ?Node
|
||||
{
|
||||
return $this->objectWithoutClassTypeMapper->mapToPhpParserNode($type, $typeKind);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\PHPStanStaticTypeMapper\TypeMapper;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
|
||||
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
|
||||
use PHPStan\Type\Accessory\HasPropertyType;
|
||||
use PHPStan\Type\Type;
|
||||
use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface;
|
||||
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
|
||||
|
||||
/**
|
||||
* @implements TypeMapperInterface<HasPropertyType>
|
||||
*/
|
||||
final class HasPropertyTypeMapper implements TypeMapperInterface
|
||||
{
|
||||
public function __construct(
|
||||
private readonly ObjectWithoutClassTypeMapper $objectWithoutClassTypeMapper
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return class-string<Type>
|
||||
*/
|
||||
public function getNodeClass(): string
|
||||
{
|
||||
return HasPropertyType::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param HasPropertyType $type
|
||||
*/
|
||||
public function mapToPHPStanPhpDocTypeNode(Type $type, TypeKind $typeKind): TypeNode
|
||||
{
|
||||
return new IdentifierTypeNode('object');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param HasPropertyType $type
|
||||
*/
|
||||
public function mapToPhpParserNode(Type $type, TypeKind $typeKind): ?Node
|
||||
{
|
||||
return $this->objectWithoutClassTypeMapper->mapToPhpParserNode($type, $typeKind);
|
||||
}
|
||||
}
|
|
@ -612,3 +612,6 @@ parameters:
|
|||
-
|
||||
path: src/Bootstrap/ExtensionConfigResolver.php
|
||||
message: '#Offset (.*?)includes(.*?) always exists and is not nullable#'
|
||||
|
||||
# mapper re-use
|
||||
- '#Parameter \#1 \$type of method Rector\\PHPStanStaticTypeMapper\\TypeMapper\\ObjectWithoutClassTypeMapper\:\:mapToPhpParserNode\(\) expects PHPStan\\Type\\ObjectWithoutClassType, PHPStan\\Type\\Accessory\\Has(Property|Method)Type given#'
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedStrictParamTypeRector\Fixture;
|
||||
|
||||
final class SkipHasPropertyType
|
||||
{
|
||||
/**
|
||||
* @param mixed $data
|
||||
*/
|
||||
public function run($data)
|
||||
{
|
||||
if (! isset($data->type)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($data->type === 'value') {
|
||||
$this->runData($data);
|
||||
}
|
||||
}
|
||||
|
||||
private function runData($data)
|
||||
{
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user