-
-
Notifications
You must be signed in to change notification settings - Fork 703
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rectorphp/rector-src@75c0b27 [types] Add HasPropertyTypeMapepr and HasMethodTypeMapper (#1731)
- Loading branch information
1 parent
f25b52c
commit 625848e
Showing
9 changed files
with
120 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
packages/PHPStanStaticTypeMapper/TypeMapper/HasMethodTypeMapper.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 \Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface | ||
{ | ||
/** | ||
* @readonly | ||
* @var \Rector\PHPStanStaticTypeMapper\TypeMapper\ObjectWithoutClassTypeMapper | ||
*/ | ||
private $objectWithoutClassTypeMapper; | ||
public function __construct(\Rector\PHPStanStaticTypeMapper\TypeMapper\ObjectWithoutClassTypeMapper $objectWithoutClassTypeMapper) | ||
{ | ||
$this->objectWithoutClassTypeMapper = $objectWithoutClassTypeMapper; | ||
} | ||
/** | ||
* @return class-string<Type> | ||
*/ | ||
public function getNodeClass() : string | ||
{ | ||
return \PHPStan\Type\Accessory\HasMethodType::class; | ||
} | ||
/** | ||
* @param HasMethodType $type | ||
*/ | ||
public function mapToPHPStanPhpDocTypeNode(\PHPStan\Type\Type $type, \Rector\PHPStanStaticTypeMapper\Enum\TypeKind $typeKind) : \PHPStan\PhpDocParser\Ast\Type\TypeNode | ||
{ | ||
return new \PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode('object'); | ||
} | ||
/** | ||
* @param HasMethodType $type | ||
*/ | ||
public function mapToPhpParserNode(\PHPStan\Type\Type $type, \Rector\PHPStanStaticTypeMapper\Enum\TypeKind $typeKind) : ?\PhpParser\Node | ||
{ | ||
return $this->objectWithoutClassTypeMapper->mapToPhpParserNode($type, $typeKind); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
packages/PHPStanStaticTypeMapper/TypeMapper/HasPropertyTypeMapper.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 \Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface | ||
{ | ||
/** | ||
* @readonly | ||
* @var \Rector\PHPStanStaticTypeMapper\TypeMapper\ObjectWithoutClassTypeMapper | ||
*/ | ||
private $objectWithoutClassTypeMapper; | ||
public function __construct(\Rector\PHPStanStaticTypeMapper\TypeMapper\ObjectWithoutClassTypeMapper $objectWithoutClassTypeMapper) | ||
{ | ||
$this->objectWithoutClassTypeMapper = $objectWithoutClassTypeMapper; | ||
} | ||
/** | ||
* @return class-string<Type> | ||
*/ | ||
public function getNodeClass() : string | ||
{ | ||
return \PHPStan\Type\Accessory\HasPropertyType::class; | ||
} | ||
/** | ||
* @param HasPropertyType $type | ||
*/ | ||
public function mapToPHPStanPhpDocTypeNode(\PHPStan\Type\Type $type, \Rector\PHPStanStaticTypeMapper\Enum\TypeKind $typeKind) : \PHPStan\PhpDocParser\Ast\Type\TypeNode | ||
{ | ||
return new \PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode('object'); | ||
} | ||
/** | ||
* @param HasPropertyType $type | ||
*/ | ||
public function mapToPhpParserNode(\PHPStan\Type\Type $type, \Rector\PHPStanStaticTypeMapper\Enum\TypeKind $typeKind) : ?\PhpParser\Node | ||
{ | ||
return $this->objectWithoutClassTypeMapper->mapToPhpParserNode($type, $typeKind); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters