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
4 changes: 0 additions & 4 deletions config/set/coding-style.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
foreach (CodingStyleLevel::RULES_WITH_CONFIGURATION as $rectorClass => $configuration) {
$rectorConfig->ruleWithConfiguration($rectorClass, $configuration);
}

// the rule order matters, as its used in withCodingStyleLevel() method
// place the safest rules first, follow by more complex ones
$rectorConfig->rules(CodingStyleLevel::RULES);
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

33 changes: 8 additions & 25 deletions rules/Transform/Rector/FuncCall/FuncCallToConstFetchRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,19 @@
namespace Rector\Transform\Rector\FuncCall;

use PhpParser\Node;
use PhpParser\Node\Expr\ConstFetch;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Name;
use Rector\Configuration\Deprecation\Contract\DeprecatedInterface;
use Rector\Contract\Rector\ConfigurableRectorInterface;
use Rector\Exception\ShouldNotHappenException;
use Rector\Rector\AbstractRector;
use Rector\RuleDoc\CodeSample\ConfiguredCodeSample;
use Rector\RuleDoc\RuleDefinition;
use Webmozart\Assert\Assert;

/**
* @see \Rector\Tests\Transform\Rector\FuncCall\FuncCallToConstFetchRector\FunctionCallToConstantRectorTest
* @deprecated This rule is deprecated, as converted functions are valid and not deprecated. Write a custom rule for the exact project case instead.
*/
final class FuncCallToConstFetchRector extends AbstractRector implements ConfigurableRectorInterface
final class FuncCallToConstFetchRector extends AbstractRector implements ConfigurableRectorInterface, DeprecatedInterface
{
/**
* @var string[]
*/
private array $functionsToConstants = [];

public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition('Changes use of function calls to use constants', [
Expand Down Expand Up @@ -69,27 +63,16 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
$functionName = $this->getName($node);
if (! is_string($functionName)) {
return null;
}

if (! array_key_exists($functionName, $this->functionsToConstants)) {
return null;
}

return new ConstFetch(new Name($this->functionsToConstants[$functionName]));
throw new ShouldNotHappenException(sprintf(
'"%s" rule is deprecated, as converted functions are valid and not deprecated; write a custom rule for the exact project case instead',
self::class
));
}

/**
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
Assert::allString($configuration);
Assert::allString(array_keys($configuration));

/** @var array<string, string> $configuration */
$this->functionsToConstants = $configuration;
}
}
11 changes: 0 additions & 11 deletions src/Config/Level/CodingStyleLevel.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
use Rector\CodingStyle\Rector\Use_\SeparateMultiUseImportsRector;
use Rector\Contract\Rector\RectorInterface;
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
use Rector\Transform\Rector\FuncCall\FuncCallToConstFetchRector;

/**
* Key 0 = level 0
Expand Down Expand Up @@ -70,14 +69,4 @@ final class CodingStyleLevel
SplitGroupedClassConstantsRector::class,
RemoveUselessAliasInUseStatementRector::class,
];

/**
* @var array<class-string<RectorInterface>, mixed[]>
*/
public const array RULES_WITH_CONFIGURATION = [
FuncCallToConstFetchRector::class => [
'php_sapi_name' => 'PHP_SAPI',
'pi' => 'M_PI',
],
];
}
4 changes: 0 additions & 4 deletions src/Configuration/RectorConfigBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1014,10 +1014,6 @@ public function withCodingStyleLevel(int $level): self
{
$this->addLevelRules('withCodingStyleLevel', $level, CodingStyleLevel::RULES, 'codingStyle', 'CODING_STYLE');

foreach (CodingStyleLevel::RULES_WITH_CONFIGURATION as $rectorClass => $configuration) {
$this->rulesWithConfigurations[$rectorClass][] = $configuration;
}

return $this;
}

Expand Down
Loading