-
-
Notifications
You must be signed in to change notification settings - Fork 372
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ConstExprClassNameDecorator, add PhpDocNodeDecoratorInterface
- Loading branch information
1 parent
160034e
commit 9bb09ed
Showing
11 changed files
with
212 additions
and
61 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
packages/BetterPhpDocParser/Contract/PhpDocParser/PhpDocNodeDecoratorInterface.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,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\BetterPhpDocParser\Contract\PhpDocParser; | ||
|
||
use PhpParser\Node; | ||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode; | ||
|
||
interface PhpDocNodeDecoratorInterface | ||
{ | ||
public function decorate(PhpDocNode $phpDocNode, Node $phpNode): void; | ||
} |
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
38 changes: 38 additions & 0 deletions
38
.../Php80/Rector/Class_/ConstantListClassToEnumRector/Fixture/multiple_params_change.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,38 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\Class_\ConstantListClassToEnumRector\Fixture; | ||
|
||
use Rector\Tests\Php80\Rector\Class_\ConstantListClassToEnumRector\Source\Gear; | ||
|
||
final class MultipleParamsChange | ||
{ | ||
/** | ||
* @param string $carType | ||
* @param Gear::* $gear | ||
* @param int $speed | ||
*/ | ||
public function changeGear($carType, string $gear, $speed) | ||
{ | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\Class_\ConstantListClassToEnumRector\Fixture; | ||
|
||
use Rector\Tests\Php80\Rector\Class_\ConstantListClassToEnumRector\Source\Gear; | ||
|
||
final class MultipleParamsChange | ||
{ | ||
/** | ||
* @param string $carType | ||
* @param int $speed | ||
*/ | ||
public function changeGear($carType, \Rector\Tests\Php80\Rector\Class_\ConstantListClassToEnumRector\Source\Gear $gear, $speed) | ||
{ | ||
} | ||
} | ||
|
||
?> |
13 changes: 13 additions & 0 deletions
13
...ests/Php80/Rector/Class_/ConstantListClassToEnumRector/Fixture/skip_unknown_class.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,13 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\Class_\ConstantListClassToEnumRector\Fixture; | ||
|
||
final class SkipUnknownClass | ||
{ | ||
/** | ||
* @param AnythingNonExisting::* $gear | ||
*/ | ||
public function changeGear(string $gear) | ||
{ | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Php80\NodeAnalyzer; | ||
|
||
use PHPStan\PhpDocParser\Ast\ConstExpr\ConstFetchNode; | ||
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode; | ||
use PHPStan\PhpDocParser\Ast\Type\ConstTypeNode; | ||
use PHPStan\Reflection\ParameterReflection; | ||
use PHPStan\Reflection\Php\PhpParameterReflection; | ||
use PHPStan\Reflection\ReflectionProvider; | ||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo; | ||
use Rector\BetterPhpDocParser\ValueObject\PhpDocAttributeKey; | ||
|
||
/** | ||
* Detects enum-like params, e.g. | ||
* Direction::* | ||
*/ | ||
final class EnumParamAnalyzer | ||
{ | ||
public function __construct( | ||
private readonly ReflectionProvider $reflectionProvider, | ||
) { | ||
} | ||
|
||
public function matchClassName(ParameterReflection $parameterReflection, PhpDocInfo $phpDocInfo): ?string | ||
{ | ||
if (! $parameterReflection instanceof PhpParameterReflection) { | ||
return null; | ||
} | ||
|
||
$paramTagValueNode = $phpDocInfo->getParamTagValueByName($parameterReflection->getName()); | ||
if (! $paramTagValueNode instanceof ParamTagValueNode) { | ||
return null; | ||
} | ||
|
||
if (! $paramTagValueNode->type instanceof ConstTypeNode) { | ||
return null; | ||
} | ||
|
||
$constTypeNode = $paramTagValueNode->type; | ||
if (! $constTypeNode->constExpr instanceof ConstFetchNode) { | ||
return null; | ||
} | ||
|
||
$constExpr = $constTypeNode->constExpr; | ||
$className = $constExpr->getAttribute(PhpDocAttributeKey::RESOLVED_CLASS); | ||
|
||
if (! $this->reflectionProvider->hasClass($className)) { | ||
return null; | ||
} | ||
|
||
return $className; | ||
} | ||
} |
Oops, something went wrong.