Skip to content

Commit

Permalink
Updated Rector to commit 8ed98c17688300b3aa85d978fefc24c88a51f1f3
Browse files Browse the repository at this point in the history
rectorphp/rector-src@8ed98c1 [DX] Use Param->isPromoted() over param->flags !== 0 check on promotion property check (#6646)
  • Loading branch information
TomasVotruba committed Jan 5, 2025
1 parent 71e2e85 commit 934bc26
Show file tree
Hide file tree
Showing 13 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ private function isPromotedProperty(Class_ $class, string $propertyName) : bool
$constructClassMethod = $class->getMethod(MethodName::CONSTRUCT);
if ($constructClassMethod instanceof ClassMethod) {
foreach ($constructClassMethod->params as $param) {
if (!$param->flags) {
if (!$param->isPromoted()) {
continue;
}
$paramName = $this->getName($param->var);
Expand Down
2 changes: 1 addition & 1 deletion rules/DeadCode/NodeCollector/UnusedParameterResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function resolve(ClassMethod $classMethod) : array
foreach ($classMethod->params as $i => $param) {
// skip property promotion
/** @var Param $param */
if ($param->flags !== 0) {
if ($param->isPromoted()) {
continue;
}
if ($this->paramAnalyzer->isParamUsedInClassMethod($classMethod, $param)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function getNodeTypes() : array
public function refactor(Node $node) : ?Node
{
// for param, only on property promotion
if ($node instanceof Param && $node->flags === 0) {
if ($node instanceof Param && !$node->isPromoted()) {
return null;
}
if (!$this->visibilityManipulator->isReadonly($node)) {
Expand Down
2 changes: 1 addition & 1 deletion rules/Naming/PropertyRenamer/PropertyPromotionRenamer.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function renamePropertyPromotion($classLike) : bool
// resolve possible and existing param names
$blockingParamNames = $this->resolveBlockingParamNames($constructClassMethod);
foreach ($constructClassMethod->params as $param) {
if ($param->flags === 0) {
if (!$param->isPromoted()) {
continue;
}
// promoted property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,6 @@ private function shouldSkipParam(Param $param, string $expectedName, $classMetho
if (!$this->isName($classMethod, MethodName::CONSTRUCT)) {
return \false;
}
return $param->flags !== 0;
return $param->isPromoted();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private function isParamUsedBeforeAssign(Variable $variable, array $firstParamAs
private function shouldSkipParam(Param $matchedParam, Variable $assignedVariable, array $firstParamAsVariable) : bool
{
// already promoted
if ($matchedParam->flags !== 0) {
if ($matchedParam->isPromoted()) {
return \true;
}
return $this->isParamUsedBeforeAssign($assignedVariable, $firstParamAsVariable);
Expand Down
2 changes: 1 addition & 1 deletion rules/Php80/NodeAnalyzer/PromotedPropertyResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function resolveFromClass(Class_ $class) : array
}
$promotedPropertyParams = [];
foreach ($constructClassMethod->getParams() as $param) {
if ($param->flags === 0) {
if (!$param->isPromoted()) {
continue;
}
$promotedPropertyParams[] = $param;
Expand Down
4 changes: 2 additions & 2 deletions rules/Php81/Rector/Property/ReadOnlyPropertyRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ private function refactorParam(Class_ $class, ClassMethod $classMethod, Param $p
return null;
}
// early check not property promotion and already readonly
if ($param->flags === 0 || $this->visibilityManipulator->isReadonly($param)) {
if (!$param->isPromoted() || $this->visibilityManipulator->isReadonly($param)) {
return null;
}
if ($this->propertyManipulator->isPropertyChangeableExceptConstructor($class, $param, $scope)) {
Expand Down Expand Up @@ -243,7 +243,7 @@ private function isPromotedPropertyAssigned(Class_ $class, Param $param) : bool
if (!$constructClassMethod instanceof ClassMethod) {
return \false;
}
if ($param->flags === 0) {
if (!$param->isPromoted()) {
return \false;
}
$propertyFetch = new PropertyFetch(new Variable('this'), $this->getName($param));
Expand Down
2 changes: 1 addition & 1 deletion rules/Php82/Rector/Class_/ReadOnlyClassRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ private function shouldSkipParams(array $params) : bool
{
foreach ($params as $param) {
// has non-readonly property promotion
if (!$this->visibilityManipulator->hasVisibility($param, Visibility::READONLY) && $param->flags !== 0) {
if (!$this->visibilityManipulator->hasVisibility($param, Visibility::READONLY) && $param->isPromoted()) {
return \true;
}
// type is missing, invalid syntax
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function refactor(Node $node) : ?Node
$construct = $node->getMethod(MethodName::CONSTRUCT);
if ($construct instanceof ClassMethod) {
foreach ($construct->params as $param) {
if ($param->flags === 0) {
if (!$param->isPromoted()) {
continue;
}
if (!$this->visibilityManipulator->hasVisibility($param, Visibility::PROTECTED)) {
Expand Down
4 changes: 2 additions & 2 deletions src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '3f5a86eacf0e245bb683a32afe422901dee44006';
public const PACKAGE_VERSION = '8ed98c17688300b3aa85d978fefc24c88a51f1f3';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2025-01-05 00:35:03';
public const RELEASE_DATE = '2025-01-05 11:09:27';
/**
* @var int
*/
Expand Down
2 changes: 1 addition & 1 deletion src/NodeAnalyzer/ParamAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function isParamUsedInClassMethod(ClassMethod $classMethod, Param $param)
public function hasPropertyPromotion(array $params) : bool
{
foreach ($params as $param) {
if ($param->flags !== 0) {
if ($param->isPromoted()) {
return \true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/PhpParser/AstResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ private function findPromotedPropertyByName(array $stmts, string $desiredClassNa
return \false;
}
foreach ($constructClassMethod->getParams() as $param) {
if ($param->flags === 0) {
if (!$param->isPromoted()) {
continue;
}
if ($this->nodeNameResolver->isName($param, $desiredPropertyName)) {
Expand Down

0 comments on commit 934bc26

Please sign in to comment.