Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function getNodeTypes(): array
public function refactor(Node $node): ?Node
{
throw new ShouldNotHappenException(sprintf(
'%s is deprecated as opinonated and group size depends on context. Cannot be automated. Use manually where needed instead',
'"%s" is deprecated as opinionated and group size depends on context. Cannot be automated. Use manually where needed instead',
self::class
));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,21 @@
namespace Rector\TypeDeclaration\Rector\StmtsAwareInterface;

use PhpParser\Node;
use PhpParser\Node\DeclareItem;
use PhpParser\Node\Identifier;
use PhpParser\Node\Scalar\Int_;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Declare_;
use PhpParser\Node\Stmt\Nop;
use Rector\ChangesReporting\ValueObject\RectorWithLineChange;
use Rector\Configuration\Deprecation\Contract\DeprecatedInterface;
use Rector\Contract\Rector\ConfigurableRectorInterface;
use Rector\Exception\ShouldNotHappenException;
use Rector\PhpParser\Enum\NodeGroup;
use Rector\PhpParser\Node\CustomNode\FileWithoutNamespace;
use Rector\Rector\AbstractRector;
use Rector\TypeDeclaration\NodeAnalyzer\DeclareStrictTypeFinder;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use Webmozart\Assert\Assert;

/**
* @see \Rector\Tests\TypeDeclaration\Rector\StmtsAwareInterface\IncreaseDeclareStrictTypesRector\IncreaseDeclareStrictTypesRectorTest
* @deprecated As keeps changing files randomly on every run. Not deterministic. Use more reliable @see \Rector\TypeDeclaration\Rector\StmtsAwareInterface\DeclareStrictTypesRector instead on specific paths.
*/
final class IncreaseDeclareStrictTypesRector extends AbstractRector implements ConfigurableRectorInterface
final class IncreaseDeclareStrictTypesRector extends AbstractRector implements ConfigurableRectorInterface, DeprecatedInterface
{
public const LIMIT = 'limit';

private int $limit = 10;

private int $changedItemCount = 0;

public function __construct(
private readonly DeclareStrictTypeFinder $declareStrictTypeFinder
) {
}

public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition(
Expand Down Expand Up @@ -65,45 +48,6 @@ function someFunction()
);
}

/**
* @param Stmt[] $nodes
* @return Stmt[]|null
*/
public function beforeTraverse(array $nodes): ?array
{
parent::beforeTraverse($nodes);

if ($nodes === []) {
return null;
}

$rootStmt = \current($nodes);
$stmt = $rootStmt;

// skip classes without namespace for safety reasons
if ($rootStmt instanceof FileWithoutNamespace) {
return null;
}

if ($this->declareStrictTypeFinder->hasDeclareStrictTypes($stmt)) {
return null;
}

// keep change within a limit
if ($this->changedItemCount >= $this->limit) {
return null;
}

++$this->changedItemCount;

$strictTypesDeclare = $this->creteStrictTypesDeclare();

$rectorWithLineChange = new RectorWithLineChange(self::class, $stmt->getStartLine());
$this->file->addRectorClassWithLine($rectorWithLineChange);

return \array_merge([$strictTypesDeclare, new Nop()], $nodes);
}

/**
* @return array<class-string<Node>>
*/
Expand All @@ -117,22 +61,17 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
// workaround, as Rector now only hooks to specific nodes, not arrays
return null;
throw new ShouldNotHappenException(sprintf(
'"%s" is deprecated as changes strict types randomly on each run.. Use "%s" Rector on specific paths instead.',
self::class,
DeclareStrictTypesRector::class
));
}

/**
* @param array<string, mixed> $configuration
*/
public function configure(array $configuration): void
{
Assert::keyExists($configuration, self::LIMIT);
$this->limit = (int) $configuration[self::LIMIT];
}

private function creteStrictTypesDeclare(): Declare_
{
$declareItem = new DeclareItem(new Identifier('strict_types'), new Int_(1));
return new Declare_([$declareItem]);
}
}
28 changes: 0 additions & 28 deletions tests/Issues/DoubleDeclare/DoubleDeclareTest.php

This file was deleted.

19 changes: 0 additions & 19 deletions tests/Issues/DoubleDeclare/Fixture/fixture.php.inc

This file was deleted.

11 changes: 0 additions & 11 deletions tests/Issues/DoubleDeclare/config/configured_rule.php

This file was deleted.