Skip to content

Commit 2be04b5

Browse files
committed
[ci-review] Rector Rectify
1 parent 31a5c9e commit 2be04b5

5 files changed

Lines changed: 25 additions & 22 deletions

File tree

rules-tests/Transform/Rector/FuncCall/WrapFuncCallWithPhpVersionIdCheckerRector/WrapFuncCallWithPhpVersionIdCheckerRectorTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Rector\Tests\Transform\Rector\FuncCall\WrapFuncCallWithPhpVersionIdCheckerRector;
46

57
use Iterator;

rules/Php84/Rector/Class_/DeprecatedAnnotationToDeprecatedAttributeRector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
final class DeprecatedAnnotationToDeprecatedAttributeRector extends AbstractRector implements MinPhpVersionInterface
2222
{
2323
public function __construct(
24-
private readonly DeprecatedAnnotationToDeprecatedAttributeConverter $converter,
24+
private readonly DeprecatedAnnotationToDeprecatedAttributeConverter $deprecatedAnnotationToDeprecatedAttributeConverter,
2525
) {
2626
}
2727

@@ -75,7 +75,7 @@ public function getNodeTypes(): array
7575
*/
7676
public function refactor(Node $node): ?Node
7777
{
78-
return $this->converter->convert($node);
78+
return $this->deprecatedAnnotationToDeprecatedAttributeConverter->convert($node);
7979
}
8080

8181
public function provideMinPhpVersion(): int

rules/Php85/Rector/Const_/DeprecatedAnnotationToDeprecatedAttributeRector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
final class DeprecatedAnnotationToDeprecatedAttributeRector extends AbstractRector implements MinPhpVersionInterface
2020
{
2121
public function __construct(
22-
private readonly DeprecatedAnnotationToDeprecatedAttributeConverter $converter,
22+
private readonly DeprecatedAnnotationToDeprecatedAttributeConverter $deprecatedAnnotationToDeprecatedAttributeConverter,
2323
) {
2424
}
2525

@@ -52,7 +52,7 @@ public function getNodeTypes(): array
5252
*/
5353
public function refactor(Node $node): ?Node
5454
{
55-
return $this->converter->convert($node);
55+
return $this->deprecatedAnnotationToDeprecatedAttributeConverter->convert($node);
5656
}
5757

5858
public function provideMinPhpVersion(): int

rules/Transform/Rector/FuncCall/WrapFuncCallWithPhpVersionIdCheckerRector.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,12 @@ public function refactor(Node $node): null|Node|int
8181

8282
$hasChanged = false;
8383
foreach ($node->stmts as $key => $stmt) {
84-
if (! $stmt instanceof Expression || ! $stmt->expr instanceof FuncCall) {
84+
if (! $stmt instanceof Expression) {
85+
continue;
86+
}
87+
if (! $stmt->expr instanceof FuncCall) {
8588
continue;
8689
}
87-
8890
$funcCall = $stmt->expr;
8991

9092
foreach ($this->wrapFuncCallWithPhpVersionIdCheckers as $wrapFuncCallWithPhpVersionIdChecker) {
@@ -121,35 +123,34 @@ public function configure(array $configuration): void
121123
$this->wrapFuncCallWithPhpVersionIdCheckers = $configuration;
122124
}
123125

124-
private function isWrappedFuncCall(StmtsAwareInterface $node): bool
126+
private function isWrappedFuncCall(StmtsAwareInterface $stmtsAware): bool
125127
{
126-
if (! $node instanceof If_) {
128+
if (! $stmtsAware instanceof If_) {
127129
return false;
128130
}
129131

130-
$phpVersionId = $this->getPhpVersionId($node->cond);
131-
if ($phpVersionId === null) {
132+
$phpVersionId = $this->getPhpVersionId($stmtsAware->cond);
133+
if (!$phpVersionId instanceof Int_) {
132134
return false;
133135
}
134136

135-
if (count($node->stmts) !== 1) {
137+
if (count($stmtsAware->stmts) !== 1) {
136138
return false;
137139
}
138140

139-
$childStmt = $node->stmts[0];
141+
$childStmt = $stmtsAware->stmts[0];
140142

141143
if (! $childStmt instanceof Expression || ! $childStmt->expr instanceof FuncCall) {
142144
return false;
143145
}
144146

145147
foreach ($this->wrapFuncCallWithPhpVersionIdCheckers as $wrapFuncCallWithPhpVersionIdChecker) {
146-
if (
147-
$this->getName($childStmt->expr) !== $wrapFuncCallWithPhpVersionIdChecker->getFunctionName()
148-
|| $phpVersionId->value !== $wrapFuncCallWithPhpVersionIdChecker->getPhpVersionId()
149-
) {
148+
if ($this->getName($childStmt->expr) !== $wrapFuncCallWithPhpVersionIdChecker->getFunctionName()) {
149+
continue;
150+
}
151+
if ($phpVersionId->value !== $wrapFuncCallWithPhpVersionIdChecker->getPhpVersionId()) {
150152
continue;
151153
}
152-
153154
return true;
154155
}
155156

src/PhpAttribute/DeprecatedAnnotationToDeprecatedAttributeConverter.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
use Rector\NodeTypeResolver\Node\AttributeKey;
2626
use Rector\PhpAttribute\NodeFactory\PhpAttributeGroupFactory;
2727

28-
final class DeprecatedAnnotationToDeprecatedAttributeConverter
28+
final readonly class DeprecatedAnnotationToDeprecatedAttributeConverter
2929
{
3030
/**
3131
* @see https://regex101.com/r/qNytVk/1
@@ -40,10 +40,10 @@ final class DeprecatedAnnotationToDeprecatedAttributeConverter
4040
private const START_STAR_SPACED_REGEX = '#^ *\*#ms';
4141

4242
public function __construct(
43-
private readonly PhpDocTagRemover $phpDocTagRemover,
44-
private readonly PhpAttributeGroupFactory $phpAttributeGroupFactory,
45-
private readonly DocBlockUpdater $docBlockUpdater,
46-
private readonly PhpDocInfoFactory $phpDocInfoFactory,
43+
private PhpDocTagRemover $phpDocTagRemover,
44+
private PhpAttributeGroupFactory $phpAttributeGroupFactory,
45+
private DocBlockUpdater $docBlockUpdater,
46+
private PhpDocInfoFactory $phpDocInfoFactory,
4747
) {
4848
}
4949

0 commit comments

Comments
 (0)