|
19 | 19 | 'setup.php', |
20 | 20 | ]; |
21 | 21 |
|
22 | | - it('does not use str_contains (PHP 8.0)', function () use ($files) { |
23 | | - foreach ($files as $relativeFile) { |
24 | | - $path = realpath(__DIR__ . '/../../' . $relativeFile); |
| 22 | + $readRequiredFile = function (string $relativeFile): string { |
| 23 | + $path = realpath(__DIR__ . '/../../' . $relativeFile); |
| 24 | + |
| 25 | + if ($path === false) { |
| 26 | + throw new RuntimeException("Unable to resolve required file: {$relativeFile}"); |
| 27 | + } |
| 28 | + |
| 29 | + $contents = file_get_contents($path); |
25 | 30 |
|
26 | | - if ($path === false) { |
27 | | - continue; |
28 | | - } |
| 31 | + if ($contents === false) { |
| 32 | + throw new RuntimeException("Unable to read required file: {$relativeFile}"); |
| 33 | + } |
29 | 34 |
|
30 | | - $contents = file_get_contents($path); |
| 35 | + return $contents; |
| 36 | + }; |
31 | 37 |
|
32 | | - if ($contents === false) { |
33 | | - continue; |
34 | | - } |
| 38 | + it('does not use str_contains (PHP 8.0)', function () use ($files, $readRequiredFile) { |
| 39 | + foreach ($files as $relativeFile) { |
| 40 | + $contents = $readRequiredFile($relativeFile); |
35 | 41 |
|
36 | 42 | expect(preg_match('/\bstr_contains\s*\(/', $contents))->toBe(0, |
37 | 43 | "{$relativeFile} uses str_contains() which requires PHP 8.0" |
38 | 44 | ); |
39 | 45 | } |
40 | 46 | }); |
41 | 47 |
|
42 | | - it('does not use str_starts_with (PHP 8.0)', function () use ($files) { |
| 48 | + it('does not use str_starts_with (PHP 8.0)', function () use ($files, $readRequiredFile) { |
43 | 49 | foreach ($files as $relativeFile) { |
44 | | - $path = realpath(__DIR__ . '/../../' . $relativeFile); |
45 | | - |
46 | | - if ($path === false) { |
47 | | - continue; |
48 | | - } |
49 | | - |
50 | | - $contents = file_get_contents($path); |
51 | | - |
52 | | - if ($contents === false) { |
53 | | - continue; |
54 | | - } |
| 50 | + $contents = $readRequiredFile($relativeFile); |
55 | 51 |
|
56 | 52 | expect(preg_match('/\bstr_starts_with\s*\(/', $contents))->toBe(0, |
57 | 53 | "{$relativeFile} uses str_starts_with() which requires PHP 8.0" |
58 | 54 | ); |
59 | 55 | } |
60 | 56 | }); |
61 | 57 |
|
62 | | - it('does not use str_ends_with (PHP 8.0)', function () use ($files) { |
| 58 | + it('does not use str_ends_with (PHP 8.0)', function () use ($files, $readRequiredFile) { |
63 | 59 | foreach ($files as $relativeFile) { |
64 | | - $path = realpath(__DIR__ . '/../../' . $relativeFile); |
65 | | - |
66 | | - if ($path === false) { |
67 | | - continue; |
68 | | - } |
69 | | - |
70 | | - $contents = file_get_contents($path); |
71 | | - |
72 | | - if ($contents === false) { |
73 | | - continue; |
74 | | - } |
| 60 | + $contents = $readRequiredFile($relativeFile); |
75 | 61 |
|
76 | 62 | expect(preg_match('/\bstr_ends_with\s*\(/', $contents))->toBe(0, |
77 | 63 | "{$relativeFile} uses str_ends_with() which requires PHP 8.0" |
78 | 64 | ); |
79 | 65 | } |
80 | 66 | }); |
81 | 67 |
|
82 | | - it('does not use nullsafe operator (PHP 8.0)', function () use ($files) { |
| 68 | + it('does not use nullsafe operator (PHP 8.0)', function () use ($files, $readRequiredFile) { |
83 | 69 | foreach ($files as $relativeFile) { |
84 | | - $path = realpath(__DIR__ . '/../../' . $relativeFile); |
85 | | - |
86 | | - if ($path === false) { |
87 | | - continue; |
88 | | - } |
89 | | - |
90 | | - $contents = file_get_contents($path); |
91 | | - |
92 | | - if ($contents === false) { |
93 | | - continue; |
94 | | - } |
| 70 | + $contents = $readRequiredFile($relativeFile); |
95 | 71 |
|
96 | 72 | expect(preg_match('/\?->/', $contents))->toBe(0, |
97 | 73 | "{$relativeFile} uses nullsafe operator which requires PHP 8.0" |
|
0 commit comments