Skip to content

Commit 9fb5952

Browse files
[DowngradePhp81] Downgrade hash algorithm (#197)
1 parent 3e960af commit 9fb5952

File tree

12 files changed

+375
-1
lines changed

12 files changed

+375
-1
lines changed

config/set/downgrade-php81.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
declare(strict_types=1);
44

5+
use Rector\DowngradePhp81\Rector\FuncCall\DowngradeHashAlgorithmXxHashRector;
56
use Rector\DowngradePhp81\Rector\LNumber\DowngradeOctalNumberRector;
67
use Rector\DowngradePhp81\Rector\MethodCall\DowngradeIsEnumRector;
78
use Rector\Config\RectorConfig;
@@ -35,7 +36,8 @@
3536
DowngradeArrayIsListRector::class,
3637
DowngradeSetAccessibleReflectionPropertyRector::class,
3738
DowngradeIsEnumRector::class,
38-
DowngradeOctalNumberRector::class
39+
DowngradeOctalNumberRector::class,
40+
DowngradeHashAlgorithmXxHashRector::class,
3941
]);
4042

4143
// @see https://php.watch/versions/8.1/internal-method-return-types#reflection
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\DowngradePhp81\Rector\FuncCall\DowngradeHashAlgorithmXxHash;
6+
7+
use Iterator;
8+
use PHPUnit\Framework\Attributes\DataProvider;
9+
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
10+
11+
final class DowngradeHashAlgorithmXxHashRectorTest extends AbstractRectorTestCase
12+
{
13+
#[DataProvider('provideData')]
14+
public function test(string $filePath): void
15+
{
16+
$this->doTestFile($filePath);
17+
}
18+
19+
public static function provideData(): Iterator
20+
{
21+
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
22+
}
23+
24+
public function provideConfigFilePath(): string
25+
{
26+
return __DIR__ . '/config/configured_rule.php';
27+
}
28+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Rector\Tests\DowngradePhp81\Rector\FuncCall\DowngradeHashAlgorithmXxHash\Fixture;
4+
5+
class Fixture
6+
{
7+
public function run()
8+
{
9+
return hash(MHASH_XXH128, 'some-data-to-hash');
10+
}
11+
}
12+
13+
?>
14+
-----
15+
<?php
16+
17+
namespace Rector\Tests\DowngradePhp81\Rector\FuncCall\DowngradeHashAlgorithmXxHash\Fixture;
18+
19+
class Fixture
20+
{
21+
public function run()
22+
{
23+
return hash('md5', 'some-data-to-hash');
24+
}
25+
}
26+
27+
?>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Rector\Tests\DowngradePhp81\Rector\FuncCall\DowngradeHashAlgorithmXxHash\Fixture;
4+
5+
class Fixture
6+
{
7+
public function run()
8+
{
9+
return hash(algo: 'xxh128', data: 'some-data-to-hash');
10+
}
11+
}
12+
13+
?>
14+
-----
15+
<?php
16+
17+
namespace Rector\Tests\DowngradePhp81\Rector\FuncCall\DowngradeHashAlgorithmXxHash\Fixture;
18+
19+
class Fixture
20+
{
21+
public function run()
22+
{
23+
return hash(algo: 'md5', data: 'some-data-to-hash');
24+
}
25+
}
26+
27+
?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Rector\Tests\DowngradePhp81\Rector\FuncCall\DowngradeHashAlgorithmXxHash\Fixture;
4+
5+
class Fixture
6+
{
7+
public function run()
8+
{
9+
return hash(data: 'some-data-to-hash', algo: 'xxh128');
10+
}
11+
}
12+
13+
?>
14+
-----
15+
<?php
16+
17+
namespace Rector\Tests\DowngradePhp81\Rector\FuncCall\DowngradeHashAlgorithmXxHash\Fixture;
18+
19+
class Fixture
20+
{
21+
public function run()
22+
{
23+
return hash(data: 'some-data-to-hash', algo: 'md5');
24+
}
25+
}
26+
27+
?>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Rector\Tests\DowngradePhp81\Rector\FuncCall\DowngradeHashAlgorithmXxHash\Fixture;
4+
5+
class Fixture
6+
{
7+
public function run()
8+
{
9+
return hash('xxh128', 'some-data-to-hash');
10+
}
11+
}
12+
13+
?>
14+
-----
15+
<?php
16+
17+
namespace Rector\Tests\DowngradePhp81\Rector\FuncCall\DowngradeHashAlgorithmXxHash\Fixture;
18+
19+
class Fixture
20+
{
21+
public function run()
22+
{
23+
return hash('md5', 'some-data-to-hash');
24+
}
25+
}
26+
27+
?>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Rector\Tests\DowngradePhp81\Rector\FuncCall\DowngradeHashAlgorithmXxHash\Fixture;
4+
5+
class Fixture
6+
{
7+
public function run()
8+
{
9+
return hash('xxh32', 'some-data-to-hash');
10+
}
11+
}
12+
13+
?>
14+
-----
15+
<?php
16+
17+
namespace Rector\Tests\DowngradePhp81\Rector\FuncCall\DowngradeHashAlgorithmXxHash\Fixture;
18+
19+
class Fixture
20+
{
21+
public function run()
22+
{
23+
return hash('md5', 'some-data-to-hash');
24+
}
25+
}
26+
27+
?>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Rector\Tests\DowngradePhp81\Rector\FuncCall\DowngradeHashAlgorithmXxHash\Fixture;
4+
5+
class Fixture
6+
{
7+
public function run()
8+
{
9+
return hash('xxh64', 'some-data-to-hash');
10+
}
11+
}
12+
13+
?>
14+
-----
15+
<?php
16+
17+
namespace Rector\Tests\DowngradePhp81\Rector\FuncCall\DowngradeHashAlgorithmXxHash\Fixture;
18+
19+
class Fixture
20+
{
21+
public function run()
22+
{
23+
return hash('md5', 'some-data-to-hash');
24+
}
25+
}
26+
27+
?>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Rector\Tests\DowngradePhp81\Rector\FuncCall\DowngradeHashAlgorithmXxHash\Fixture;
4+
5+
class SkipDifferentFuncCall
6+
{
7+
public function run(string $data)
8+
{
9+
return strlen($data);
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Rector\Tests\DowngradePhp81\Rector\FuncCall\DowngradeHashAlgorithmXxHash\Fixture;
4+
5+
class SkipHasAllowedAlgorithm
6+
{
7+
public function run()
8+
{
9+
return hash('sha1', 'some-data-to-hash');
10+
}
11+
}

0 commit comments

Comments
 (0)