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
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Rector\Tests\Arguments\Rector\ClassMethod\ReplaceArgumentDefaultValueRector\Fixture;

class FromOtherBaseClass
{
public const PATH = 'path';

public static function test1(string $path)
{
\Mage::getStoreConfig(self::PATH);
}
}

?>
-----
<?php

namespace Rector\Tests\Arguments\Rector\ClassMethod\ReplaceArgumentDefaultValueRector\Fixture;

class FromOtherBaseClass
{
public const PATH = 'path';

public static function test1(string $path)
{
\Mage::getStoreConfig(\Rector\Tests\Arguments\Rector\ClassMethod\ReplaceArgumentDefaultValueRector\Fixture\SomeBase::PATH);
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Rector\Tests\Arguments\Rector\ClassMethod\ReplaceArgumentDefaultValueRector\Fixture;

class SomeBase
{
public const PATH = 'path';

public static function test1(string $path)
{
\Mage::getStoreConfig(self::PATH);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,7 @@
1,
4
),

new ReplaceArgumentDefaultValue(Mage::class, 'getStoreConfig', 0, 'path', 'Rector\Tests\Arguments\Rector\ClassMethod\ReplaceArgumentDefaultValueRector\Fixture\SomeBase::PATH'),
]);
};
24 changes: 23 additions & 1 deletion rules/Arguments/ArgumentDefaultValueReplacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@
use PhpParser\Node\Expr\New_;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt\ClassMethod;
use Rector\Arguments\Contract\ReplaceArgumentDefaultValueInterface;
use Rector\Arguments\ValueObject\ReplaceArgumentDefaultValue;
use Rector\NodeAnalyzer\ArgsAnalyzer;
use Rector\NodeTypeResolver\NodeTypeResolver;
use Rector\PhpParser\AstResolver;
use Rector\PhpParser\Node\NodeFactory;
use Rector\PhpParser\Node\Value\ValueResolver;
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;

final readonly class ArgumentDefaultValueReplacer
{
Expand All @@ -28,6 +32,7 @@ public function __construct(
private ValueResolver $valueResolver,
private ArgsAnalyzer $argsAnalyzer,
private AstResolver $astResolver,
private NodeTypeResolver $nodeTypeResolver
) {
}

Expand Down Expand Up @@ -153,7 +158,24 @@ private function processArgs(
if (is_scalar(
$replaceArgumentDefaultValue->getValueBefore()
) && $argValue === $replaceArgumentDefaultValue->getValueBefore()) {
$particularArg->value = $this->normalizeValue($replaceArgumentDefaultValue->getValueAfter());
$normalizedValueAfter = $this->normalizeValue($replaceArgumentDefaultValue->getValueAfter());
if ($particularArg->value instanceof ClassConstFetch
&& $particularArg->value->class instanceof Name
&& $particularArg->value->class->isSpecialClassName()
&& $normalizedValueAfter instanceof ClassConstFetch
&& is_string($replaceArgumentDefaultValue->getValueAfter())
&& str_contains($replaceArgumentDefaultValue->getValueAfter(), '::')) {
[$targetClass, $targetConstant] = explode('::', $replaceArgumentDefaultValue->getValueAfter());
$type = $this->nodeTypeResolver->getType($particularArg->value->class);
if ($type instanceof FullyQualifiedObjectType
&& $type->getClassName() === $targetClass
&& $particularArg->value->name instanceof Identifier
&& $particularArg->value->name->toString() === $targetConstant) {
return null;
}
}

$particularArg->value = $normalizedValueAfter;
return $expr;
}

Expand Down
8 changes: 4 additions & 4 deletions src/Caching/Config/FileHashComputer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
/**
* Inspired by https://github.com/symplify/easy-coding-standard/blob/e598ab54686e416788f28fcfe007fd08e0f371d9/packages/changed-files-detector/src/FileHashComputer.php
*/
final class FileHashComputer
final readonly class FileHashComputer
{
/**
* @param CacheMetaExtensionInterface[] $cacheMetaExtensions
*/
public function __construct(
private readonly array $cacheMetaExtensions = []
private array $cacheMetaExtensions = []
) {
}

Expand All @@ -34,8 +34,8 @@ public function compute(string $filePath): string
private function computeExtensionHash(): string
{
$extensionHash = '';
foreach ($this->cacheMetaExtensions as $cacheMetaExtension) {
$extensionHash .= $cacheMetaExtension->getKey() . ':' . $cacheMetaExtension->getHash();
foreach ($this->cacheMetaExtensions as $cacheMetumExtension) {
$extensionHash .= $cacheMetumExtension->getKey() . ':' . $cacheMetumExtension->getHash();
}

return $extensionHash;
Expand Down
4 changes: 2 additions & 2 deletions src/Configuration/RectorConfigBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,8 @@ public function __invoke(RectorConfig $rectorConfig): void
$rectorConfig->containerCacheDirectory($this->containerCacheDirectory);
}

foreach ($this->cacheMetaExtensions as $cacheMetaExtensionClass) {
$rectorConfig->cacheMetaExtension($cacheMetaExtensionClass);
foreach ($this->cacheMetaExtensions as $cacheMetumExtension) {
$rectorConfig->cacheMetaExtension($cacheMetumExtension);
}

if ($this->importNames || $this->importDocBlockNames) {
Expand Down
Loading