-
-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[types] Add HasPropertyTypeMapepr and HasMethodTypeMapper (#1731)
* Add HasPropertyTypeMapper * add has Method type mapper
- Loading branch information
1 parent
a26c59a
commit 75c0b27
Showing
6 changed files
with
127 additions
and
2 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
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 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); | ||
} | ||
} |
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 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); | ||
} | ||
} |
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
26 changes: 26 additions & 0 deletions
26
...lassMethod/AddMethodCallBasedStrictParamTypeRector/Fixture/skip_has_property_type.php.inc
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,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) | ||
{ | ||
} | ||
} |