From b874b8d05a9dbea0e008de8d05f2eae1d63f3270 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 16 Jul 2024 16:46:18 +0200 Subject: [PATCH] fix --- tests/PHPStan/Analyser/nsrt/bug-11311.php | 20 +++++++++---------- .../Analyser/nsrt/preg_match_shapes.php | 16 +++++++-------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/tests/PHPStan/Analyser/nsrt/bug-11311.php b/tests/PHPStan/Analyser/nsrt/bug-11311.php index 7ed9655d22..9fbf51e74a 100644 --- a/tests/PHPStan/Analyser/nsrt/bug-11311.php +++ b/tests/PHPStan/Analyser/nsrt/bug-11311.php @@ -7,26 +7,26 @@ function doFoo(string $s) { if (1 === preg_match('/(?\d+)\.(?\d+)(?:\.(?\d+))?/', $s, $matches, PREG_UNMATCHED_AS_NULL)) { - assertType('array{0: string, major: numeric-string, 1: numeric-string, minor: numeric-string, 2: numeric-string, patch: numeric-string|null, 3: numeric-string|null}', $matches); + assertType('array{0: string, major: non-empty-string&numeric-string, 1: non-empty-string&numeric-string, minor: non-empty-string&numeric-string, 2: non-empty-string&numeric-string, patch: (non-empty-string&numeric-string)|null, 3: (non-empty-string&numeric-string)|null}', $matches); } } function doUnmatchedAsNull(string $s): void { if (preg_match('/(foo)?(bar)?(baz)?/', $s, $matches, PREG_UNMATCHED_AS_NULL)) { - assertType('array{string, string|null, string|null, string|null}', $matches); + assertType('array{string, non-empty-string|null, non-empty-string|null, non-empty-string|null}', $matches); } - assertType('array{}|array{string, string|null, string|null, string|null}', $matches); + assertType('array{}|array{string, non-empty-string|null, non-empty-string|null, non-empty-string|null}', $matches); } // see https://3v4l.org/VeDob function unmatchedAsNullWithOptionalGroup(string $s): void { if (preg_match('/Price: (£|€)?\d+/', $s, $matches, PREG_UNMATCHED_AS_NULL)) { // with PREG_UNMATCHED_AS_NULL the offset 1 will always exist. It is correct that it's nullable because it's optional though - assertType('array{string, string|null}', $matches); + assertType('array{string, non-empty-string|null}', $matches); } else { assertType('array{}', $matches); } - assertType('array{}|array{string, string|null}', $matches); + assertType('array{}|array{string, non-empty-string|null}', $matches); } function bug11331a(string $url):void { @@ -36,7 +36,7 @@ function bug11331a(string $url):void { (?.+) )? (?.+)}mix', $url, $matches, PREG_UNMATCHED_AS_NULL)) { - assertType('array{0: string, a: string|null, 1: string|null, b: string, 2: string}', $matches); + assertType('array{0: string, a: non-empty-string|null, 1: non-empty-string|null, b: non-empty-string, 2: non-empty-string}', $matches); } } @@ -46,7 +46,7 @@ function bug11331b(string $url):void { (?.+) )? (?.+)?}mix', $url, $matches, PREG_UNMATCHED_AS_NULL)) { - assertType('array{0: string, a: string|null, 1: string|null, b: string|null, 2: string|null}', $matches); + assertType('array{0: string, a: non-empty-string|null, 1: non-empty-string|null, b: non-empty-string|null, 2: non-empty-string|null}', $matches); } } @@ -62,20 +62,20 @@ function bug11331c(string $url):void { ([^/]+?) (?:\.git|/)? $}x', $url, $matches, PREG_UNMATCHED_AS_NULL)) { - assertType('array{string, string|null, string|null, string, string}', $matches); + assertType('array{string, non-empty-string|null, non-empty-string|null, non-empty-string, non-empty-string}', $matches); } } class UnmatchedAsNullWithTopLevelAlternation { function doFoo(string $s): void { if (preg_match('/Price: (?:(£)|(€))\d+/', $s, $matches, PREG_UNMATCHED_AS_NULL)) { - assertType('array{string, string|null, string|null}', $matches); // could be array{0: string, 1: null, 2: string}|array{0: string, 1: string, 2: null} + assertType('array{string, non-empty-string|null, non-empty-string|null}', $matches); // could be array{0: string, 1: null, 2: string}|array{0: string, 1: string, 2: null} } } function doBar(string $s): void { if (preg_match('/Price: (?:(£)|(€))?\d+/', $s, $matches, PREG_UNMATCHED_AS_NULL)) { - assertType('array{string, string|null, string|null}', $matches); + assertType('array{string, non-empty-string|null, non-empty-string|null}', $matches); } } } diff --git a/tests/PHPStan/Analyser/nsrt/preg_match_shapes.php b/tests/PHPStan/Analyser/nsrt/preg_match_shapes.php index e324f8e3a2..40903e80ae 100644 --- a/tests/PHPStan/Analyser/nsrt/preg_match_shapes.php +++ b/tests/PHPStan/Analyser/nsrt/preg_match_shapes.php @@ -259,7 +259,7 @@ function doFoo2(string $row): void return; } - assertType('array{0: string, 1: string, branchCode: numeric-string, 2: numeric-string, accountNumber: numeric-string, 3: numeric-string, bankCode: numeric-string, 4: numeric-string}', $matches); + assertType('array{0: string, 1: non-empty-string&numeric-string, branchCode: non-empty-string&numeric-string, 2: non-empty-string&numeric-string, accountNumber: non-empty-string&numeric-string, 3: non-empty-string&numeric-string, bankCode: non-empty-string&numeric-string, 4: non-empty-string&numeric-string}', $matches); } function doFoo3(string $row): void @@ -289,7 +289,7 @@ function (string $size): void { if (preg_match('~^a\.b(c(\d+)?)d~', $size, $matches) !== 1) { throw new InvalidArgumentException(sprintf('Invalid size "%s"', $size)); } - assertType('array{0: string, 1: string, 2?: numeric-string}', $matches); + assertType('array{0: string, 1: non-empty-string, 2?: non-empty-string&numeric-string}', $matches); }; function (string $size): void { @@ -303,7 +303,7 @@ function (string $size): void { if (preg_match('~^a\.b(c(\d+))d~', $size, $matches) !== 1) { throw new InvalidArgumentException(sprintf('Invalid size "%s"', $size)); } - assertType('array{string, string, numeric-string}', $matches); + assertType('array{string, non-empty-string, non-empty-string&numeric-string}', $matches); }; function (string $size): void { @@ -376,7 +376,7 @@ function bug11323a(string $s): void } else { assertType('array{}', $matches); } - assertType('array{}|array{0: string, currency: string, 1: string}', $matches); + assertType('array{}|array{0: string, currency: non-empty-string, 1: non-empty-string}', $matches); } function bug11323b(string $s): void @@ -447,21 +447,21 @@ function (string $size): void { if (preg_match('/ab(\d){2,4}xx([0-9])?e?/', $size, $matches) !== 1) { throw new InvalidArgumentException(sprintf('Invalid size "%s"', $size)); } - assertType('array{0: string, 1: non-empty-string&numeric-string, 2?: non-empty-string}', $matches); + assertType('array{0: string, 1: non-empty-string&numeric-string, 2?: non-empty-string&numeric-string}', $matches); }; function (string $size): void { if (preg_match('/a(\dAB){2}b(\d){2,4}([1-5])([1-5a-z])e?/', $size, $matches) !== 1) { throw new InvalidArgumentException(sprintf('Invalid size "%s"', $size)); } - assertType('array{string, string, numeric-string, numeric-string, string}', $matches); + assertType('array{string, non-empty-string, non-empty-string&numeric-string, non-empty-string&numeric-string, non-empty-string}', $matches); }; function (string $size): void { if (preg_match('/ab(ab(\d)){2,4}xx([0-9][a-c])?e?/', $size, $matches) !== 1) { throw new InvalidArgumentException(sprintf('Invalid size "%s"', $size)); } - assertType('array{0: string, 1: string, 2: numeric-string, 3?: string}', $matches); + assertType('array{0: string, 1: non-empty-string, 2: non-empty-string&numeric-string, 3?: non-empty-string}', $matches); }; function (string $size): void { @@ -475,7 +475,7 @@ function (string $size): void { if (preg_match('/ab(?P\d+)e?/', $size, $matches) !== 1) { throw new InvalidArgumentException(sprintf('Invalid size "%s"', $size)); } - assertType('array{0: string, num: numeric-string, 1: numeric-string}', $matches); + assertType('array{0: string, num: non-empty-string&numeric-string, 1: non-empty-string&numeric-string}', $matches); }; function (string $size): void {