File: make_compatible_with_phpunit9.php

package info (click to toggle)
php-phpseclib 2.0.42-1%2Bdeb12u2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 4,416 kB
  • sloc: php: 11,867; sh: 66; xml: 49; makefile: 25
file content (35 lines) | stat: -rw-r--r-- 1,706 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php

/** @var iterable<SplFileInfo> $files */
$files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(__DIR__));
foreach ($files as $file) {
    if ($file->getExtension() === 'php' && $file->getPathname() !== __FILE__) {
        $fileContents = file_get_contents($file->getPathname());
        if ($fileContents === false) {
            throw new \RuntimeException('file_get_contents() failed: ' . $file->getPathname());
        }
        $patternToReplacementMap = array(
            '~n setUpBeforeClass\(\)~' => 'n setUpBeforeClass(): void',
            '~n setUp\(\)~' => 'n setUp(): void',
            '~n tearDown\(\)~' => 'n tearDown(): void',
            '~(n assertIsArray\([^\)]*\))~' => '$1: void',
            '~(n assertIsString\([^\)]*\))~' => '$1: void',
            '~(n assertStringContainsString\([^\)]*\))~' => '$1: void',
            '~(n assertStringNotContainsString\([^\)]*\))~' => '$1: void',
            '~^class Unit_Crypt_(AES|Hash|RSA)_~m' => 'class ',
            '~^class Unit_File_X509_~m' => 'class ',
            '~^class Unit_Math_BigInteger_~m' => 'class ',
            '~^class Unit_(Crypt|File|Math|Net)_~m' => 'class ',
            '~^class Functional_Net__~m' => 'class ',
            '~extends Unit_Crypt_Hash_(SHA512Test|SHA256Test)~' => 'extends $1'
        );
        $updatedFileContents = preg_replace(
            array_keys($patternToReplacementMap),
            array_values($patternToReplacementMap),
            $fileContents
        );
        if (file_put_contents($file->getPathname(), $updatedFileContents) === false) {
            throw new \RuntimeException('file_put_contents() failed: ' . $file->getPathname());
        }
    }
}