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,27 @@
<?php

namespace Rector\Tests\DowngradePhp81\Rector\FuncCall\DowngradeHashAlgorithmXxHash\Fixture;

final class FixtureFullyQualifiedConstant
{
public function run()
{
return hash(\MHASH_XXH128, 'some-data-to-hash');
}
}

?>
-----
<?php

namespace Rector\Tests\DowngradePhp81\Rector\FuncCall\DowngradeHashAlgorithmXxHash\Fixture;

final class FixtureFullyQualifiedConstant
{
public function run()
{
return hash('md5', 'some-data-to-hash');
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@
final class DowngradeHashAlgorithmXxHashRector extends AbstractRector
{
/**
* @var array<string, int>
* Constants are referenced by name, as the MHASH_* constants are deprecated since PHP 8.5
*
* @var array<string, string>
*/
private const array HASH_ALGORITHMS_TO_DOWNGRADE = [
'xxh32' => MHASH_XXH32,
'xxh64' => MHASH_XXH64,
'xxh3' => MHASH_XXH3,
'xxh128' => MHASH_XXH128,
'xxh32' => 'MHASH_XXH32',
'xxh64' => 'MHASH_XXH64',
'xxh3' => 'MHASH_XXH3',
'xxh128' => 'MHASH_XXH128',
];

private const string REPLACEMENT_ALGORITHM = 'md5';
Expand Down Expand Up @@ -167,7 +169,7 @@ private function getHashAlgorithm(array $args): ?string

private function mapConstantToString(string $constant): string
{
$mappedConstant = array_search(constant($constant), self::HASH_ALGORITHMS_TO_DOWNGRADE, true);
$mappedConstant = array_search(ltrim($constant, '\\'), self::HASH_ALGORITHMS_TO_DOWNGRADE, true);

return $mappedConstant !== false ? $mappedConstant : $constant;
}
Expand Down
Loading