Skip to content

Commit f588337

Browse files
Use more specific string functions
1 parent 0ff12b5 commit f588337

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

tests/Output/Integration/UnifiedDiffOutputBuilderIntegrationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
use function preg_split;
2121
use function realpath;
2222
use function sprintf;
23-
use function strpos;
23+
use function str_contains;
2424
use function unlink;
2525
use PHPUnit\Framework\Attributes\CoversClass;
2626
use PHPUnit\Framework\Attributes\DataProvider;
@@ -49,7 +49,7 @@ public static function provideDiffWithLineNumbers(): array
4949
UnifiedDiffOutputBuilderDataProvider::provideDiffWithLineNumbers(),
5050
static function ($key)
5151
{
52-
return !is_string($key) || false === strpos($key, 'non_patch_compat');
52+
return !is_string($key) || !str_contains($key, 'non_patch_compat');
5353
},
5454
ARRAY_FILTER_USE_KEY
5555
);

tests/Utils/UnifiedDiffAssertTrait.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
use function preg_match;
1616
use function preg_split;
1717
use function sprintf;
18+
use function str_starts_with;
1819
use function strlen;
19-
use function strpos;
2020
use function substr;
2121
use RuntimeException;
2222
use UnexpectedValueException;
@@ -52,8 +52,8 @@ public function assertValidUnifiedDiffFormat(string $diff): void
5252
$this->unifiedDiffAssertLinePrefix($lines[0], 'Line 1.');
5353
$this->unifiedDiffAssertLinePrefix($lines[1], 'Line 2.');
5454

55-
if ('---' === substr($lines[0], 0, 3)) {
56-
if ('+++' !== substr($lines[1], 0, 3)) {
55+
if (str_starts_with($lines[0], '---')) {
56+
if (!str_starts_with($lines[1], '+++')) {
5757
throw new UnexpectedValueException(sprintf("Line 1 indicates a header, so line 2 must start with \"+++\".\nLine 1: \"%s\"\nLine 2: \"%s\".", $lines[0], $lines[1]));
5858
}
5959

@@ -211,7 +211,7 @@ private function unifiedDiffAssertStrLength(string $line, int $min, string $mess
211211
*/
212212
private function unifiedDiffAssertHeaderLine(string $line, string $start, string $message): void
213213
{
214-
if (0 !== strpos($line, $start)) {
214+
if (!str_starts_with($line, $start)) {
215215
throw new UnexpectedValueException(sprintf('Expected header line to start with "%s", got "%s". %s', $start . ' ', $line, $message));
216216
}
217217

0 commit comments

Comments
 (0)