Skip to content

Commit

Permalink
[DowngradePhp81] Downgrade hash algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
malteschlueter committed Oct 17, 2023
1 parent 850b492 commit be3b498
Show file tree
Hide file tree
Showing 13 changed files with 448 additions and 1 deletion.
4 changes: 3 additions & 1 deletion config/set/downgrade-php81.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

declare(strict_types=1);

use Rector\DowngradePhp81\Rector\FuncCall\DowngradeHashAlgorithmXxHashRector;
use Rector\DowngradePhp81\Rector\LNumber\DowngradeOctalNumberRector;
use Rector\DowngradePhp81\Rector\MethodCall\DowngradeIsEnumRector;
use Rector\Config\RectorConfig;
Expand Down Expand Up @@ -35,7 +36,8 @@
DowngradeArrayIsListRector::class,
DowngradeSetAccessibleReflectionPropertyRector::class,
DowngradeIsEnumRector::class,
DowngradeOctalNumberRector::class
DowngradeOctalNumberRector::class,
DowngradeHashAlgorithmXxHashRector::class,
]);

// @see https://php.watch/versions/8.1/internal-method-return-types#reflection
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

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

use Iterator;
use PHPUnit\Framework\Attributes\DataProvider;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;

final class DowngradeHashAlgorithmXxHashRectorTest extends AbstractRectorTestCase
{
#[DataProvider('provideData')]
public function test(string $filePath): void
{
$this->doTestFile($filePath);
}

public static function provideData(): Iterator
{
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
}

public function provideConfigFilePath(): string
{
return __DIR__ . '/config/configured_rule.php';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

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

class Fixture
{
public function run()
{
return hash('xxh3', 'some-data-to-hash');
}
}

?>
-----
<?php

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

class Fixture
{
public function run()
{
return hash('sha1', 'some-data-to-hash');
}
}

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

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

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

?>
-----
<?php

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

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

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

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

class Fixture
{
public function run()
{
return hash(algo: 'xxh128', data: 'some-data-to-hash');
}
}

?>
-----
<?php

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

class Fixture
{
public function run()
{
return hash(algo: 'md5', data: 'some-data-to-hash');
}
}

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

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

class Fixture
{
public function run()
{
return hash(data: 'some-data-to-hash', algo: 'xxh128');
}
}

?>
-----
<?php

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

class Fixture
{
public function run()
{
return hash(data: 'some-data-to-hash', algo: 'md5');
}
}

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

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

class Fixture
{
public function run()
{
return hash('xxh128', 'some-data-to-hash');
}
}

?>
-----
<?php

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

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

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

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

class Fixture
{
public function run()
{
return hash('xxh32', 'some-data-to-hash');
}
}

?>
-----
<?php

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

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

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

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

class Fixture
{
public function run()
{
return hash('xxh64', 'some-data-to-hash');
}
}

?>
-----
<?php

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

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

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

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

class SkipDifferentFuncCall
{
public function run(string $data)
{
return strlen($data);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

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

class SkipHasAllowedAlgorithm
{
public function run()
{
return hash('sha1', 'some-data-to-hash');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\DowngradePhp81\Rector\FuncCall\DowngradeHashAlgorithmXxHashRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->ruleWithConfiguration(DowngradeHashAlgorithmXxHashRector::class, [
'xxh3' => 'sha1',
]);
};
Loading

0 comments on commit be3b498

Please sign in to comment.