Skip to content

Commit

Permalink
Merge pull request #245 from palantirnet/feature/remove-file-default-…
Browse files Browse the repository at this point in the history
…scheme-base

Remove single use FunctionToImmutableConfigBase
  • Loading branch information
bbrala committed Aug 22, 2023
2 parents f5a5001 + f322e9e commit 37dd08f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 82 deletions.
77 changes: 0 additions & 77 deletions src/Rector/Deprecation/Base/FunctionToImmutableConfigBase.php

This file was deleted.

43 changes: 38 additions & 5 deletions src/Rector/Deprecation/FileDefaultSchemeRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

namespace DrupalRector\Rector\Deprecation;

use DrupalRector\Rector\Deprecation\Base\FunctionToImmutableConfigBase;
use PhpParser\Node;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

Expand All @@ -11,13 +12,45 @@
*
* @see https://www.drupal.org/node/3049030 for change record.
*/
final class FileDefaultSchemeRector extends FunctionToImmutableConfigBase
final class FileDefaultSchemeRector extends AbstractRector
{
protected $deprecatedFunctionName = 'file_default_scheme';
protected string $deprecatedFunctionName = 'file_default_scheme';

protected $configObject = 'system.file';
protected string $configObject = 'system.file';

protected $configName = 'default_scheme';
protected string $configName = 'default_scheme';

/**
* @inheritDoc
*/
public function getNodeTypes(): array
{
return [
Node\Expr\FuncCall::class,
];
}

/**
* @inheritDoc
*/
public function refactor(Node $node): ?Node
{
/** @var Node\Expr\FuncCall $node */
if ($this->getName($node->name) !== $this->deprecatedFunctionName) {
return null;
}
$static_function_args = [new Node\Arg(new Node\Scalar\String_($this->configObject))];

$static_function = new Node\Expr\StaticCall(new Node\Name\FullyQualified('Drupal'), 'config', $static_function_args);

$method_name = new Node\Identifier('get');
$method_args = [new Node\Arg(new Node\Scalar\String_($this->configName))];


$node = new Node\Expr\MethodCall($static_function, $method_name, $method_args);

return $node;
}

/**
* @inheritDoc
Expand Down

0 comments on commit 37dd08f

Please sign in to comment.