Skip to content

Commit 7764a8d

Browse files
committed
Updated Rector to commit 7188ba60120f5a561746893436390c24bc08d44a
rectorphp/rector-src@7188ba6 [depre] Deprecate IncreaseDeclareStrictTypesRector as adds declares randomly on consequent run, use DeclareStrictTypesRector instead (#7726)
1 parent 1c9ed16 commit 7764a8d

File tree

3 files changed

+8
-63
lines changed

3 files changed

+8
-63
lines changed

rules/Php74/Rector/LNumber/AddLiteralSeparatorToNumberRector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function getNodeTypes(): array
6969
*/
7070
public function refactor(Node $node): ?Node
7171
{
72-
throw new ShouldNotHappenException(sprintf('%s is deprecated as opinonated and group size depends on context. Cannot be automated. Use manually where needed instead', self::class));
72+
throw new ShouldNotHappenException(sprintf('"%s" is deprecated as opinionated and group size depends on context. Cannot be automated. Use manually where needed instead', self::class));
7373
}
7474
public function provideMinPhpVersion(): int
7575
{

rules/TypeDeclaration/Rector/StmtsAwareInterface/IncreaseDeclareStrictTypesRector.php

Lines changed: 5 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,19 @@
44
namespace Rector\TypeDeclaration\Rector\StmtsAwareInterface;
55

66
use PhpParser\Node;
7-
use PhpParser\Node\DeclareItem;
8-
use PhpParser\Node\Identifier;
9-
use PhpParser\Node\Scalar\Int_;
10-
use PhpParser\Node\Stmt;
11-
use PhpParser\Node\Stmt\Declare_;
12-
use PhpParser\Node\Stmt\Nop;
13-
use Rector\ChangesReporting\ValueObject\RectorWithLineChange;
7+
use Rector\Configuration\Deprecation\Contract\DeprecatedInterface;
148
use Rector\Contract\Rector\ConfigurableRectorInterface;
9+
use Rector\Exception\ShouldNotHappenException;
1510
use Rector\PhpParser\Enum\NodeGroup;
16-
use Rector\PhpParser\Node\CustomNode\FileWithoutNamespace;
1711
use Rector\Rector\AbstractRector;
18-
use Rector\TypeDeclaration\NodeAnalyzer\DeclareStrictTypeFinder;
1912
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
2013
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
21-
use RectorPrefix202512\Webmozart\Assert\Assert;
2214
/**
23-
* @see \Rector\Tests\TypeDeclaration\Rector\StmtsAwareInterface\IncreaseDeclareStrictTypesRector\IncreaseDeclareStrictTypesRectorTest
15+
* @deprecated As keeps changing files randomly on every run. Not deterministic. Use more reliable @see \Rector\TypeDeclaration\Rector\StmtsAwareInterface\DeclareStrictTypesRector instead on specific paths.
2416
*/
25-
final class IncreaseDeclareStrictTypesRector extends AbstractRector implements ConfigurableRectorInterface
17+
final class IncreaseDeclareStrictTypesRector extends AbstractRector implements ConfigurableRectorInterface, DeprecatedInterface
2618
{
27-
/**
28-
* @readonly
29-
*/
30-
private DeclareStrictTypeFinder $declareStrictTypeFinder;
3119
public const LIMIT = 'limit';
32-
private int $limit = 10;
33-
private int $changedItemCount = 0;
34-
public function __construct(DeclareStrictTypeFinder $declareStrictTypeFinder)
35-
{
36-
$this->declareStrictTypeFinder = $declareStrictTypeFinder;
37-
}
3820
public function getRuleDefinition(): RuleDefinition
3921
{
4022
return new RuleDefinition('Add declare strict types to a limited amount of classes at a time, to try out in the wild and increase level gradually', [new ConfiguredCodeSample(<<<'CODE_SAMPLE'
@@ -51,35 +33,6 @@ function someFunction()
5133
CODE_SAMPLE
5234
, [self::LIMIT => 10])]);
5335
}
54-
/**
55-
* @param Stmt[] $nodes
56-
* @return Stmt[]|null
57-
*/
58-
public function beforeTraverse(array $nodes): ?array
59-
{
60-
parent::beforeTraverse($nodes);
61-
if ($nodes === []) {
62-
return null;
63-
}
64-
$rootStmt = \current($nodes);
65-
$stmt = $rootStmt;
66-
// skip classes without namespace for safety reasons
67-
if ($rootStmt instanceof FileWithoutNamespace) {
68-
return null;
69-
}
70-
if ($this->declareStrictTypeFinder->hasDeclareStrictTypes($stmt)) {
71-
return null;
72-
}
73-
// keep change within a limit
74-
if ($this->changedItemCount >= $this->limit) {
75-
return null;
76-
}
77-
++$this->changedItemCount;
78-
$strictTypesDeclare = $this->creteStrictTypesDeclare();
79-
$rectorWithLineChange = new RectorWithLineChange(self::class, $stmt->getStartLine());
80-
$this->file->addRectorClassWithLine($rectorWithLineChange);
81-
return \array_merge([$strictTypesDeclare, new Nop()], $nodes);
82-
}
8336
/**
8437
* @return array<class-string<Node>>
8538
*/
@@ -92,20 +45,12 @@ public function getNodeTypes(): array
9245
*/
9346
public function refactor(Node $node): ?Node
9447
{
95-
// workaround, as Rector now only hooks to specific nodes, not arrays
96-
return null;
48+
throw new ShouldNotHappenException(sprintf('"%s" is deprecated as changes strict types randomly on each run.. Use "%s" Rector on specific paths instead.', self::class, \Rector\TypeDeclaration\Rector\StmtsAwareInterface\DeclareStrictTypesRector::class));
9749
}
9850
/**
9951
* @param array<string, mixed> $configuration
10052
*/
10153
public function configure(array $configuration): void
10254
{
103-
Assert::keyExists($configuration, self::LIMIT);
104-
$this->limit = (int) $configuration[self::LIMIT];
105-
}
106-
private function creteStrictTypesDeclare(): Declare_
107-
{
108-
$declareItem = new DeclareItem(new Identifier('strict_types'), new Int_(1));
109-
return new Declare_([$declareItem]);
11055
}
11156
}

src/Application/VersionResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ final class VersionResolver
1919
* @api
2020
* @var string
2121
*/
22-
public const PACKAGE_VERSION = 'c793b8458bde59edfd7b458e61915ab160428a8f';
22+
public const PACKAGE_VERSION = '7188ba60120f5a561746893436390c24bc08d44a';
2323
/**
2424
* @api
2525
* @var string
2626
*/
27-
public const RELEASE_DATE = '2025-12-06 20:30:35';
27+
public const RELEASE_DATE = '2025-12-07 00:01:44';
2828
/**
2929
* @var int
3030
*/

0 commit comments

Comments
 (0)