From 969c7a098be545cf453687ed86a68899d9a3781c Mon Sep 17 00:00:00 2001 From: Semyon <7ionmail@gmail.com> Date: Fri, 2 Sep 2022 17:37:10 +0300 Subject: [PATCH] Make ctype_digit and ctype_lower work as assertions --- .../Statements/Expression/AssertionFinder.php | 2 + tests/TypeReconciliation/ConditionalTest.php | 52 +++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php b/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php index 0fa53eaf5e5..1dcc97346a9 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php @@ -103,6 +103,8 @@ class AssertionFinder 'is_scalar' => ['scalar', [Type::class, 'getScalar']], 'is_iterable' => ['iterable'], 'is_countable' => ['countable'], + 'ctype_digit' => ['numeric-string', [Type::class, 'getNumericString']], + 'ctype_lower' => ['non-empty-lowercase-string', [Type::class, 'getNonEmptyLowercaseString']], ]; /** diff --git a/tests/TypeReconciliation/ConditionalTest.php b/tests/TypeReconciliation/ConditionalTest.php index ac5ee27f322..295597be4a3 100644 --- a/tests/TypeReconciliation/ConditionalTest.php +++ b/tests/TypeReconciliation/ConditionalTest.php @@ -2848,6 +2848,58 @@ function matches(string $value): bool { return true; }' ], + 'ctypeDigitMakesStringNumeric' => [ + ' [ + ' [ + '$int' => 'int<48, 57>|int<256, 1000>' + ] + ], + 'ctypeLowerMakesStringLowercase' => [ + ' [ + ' [ + '$int' => 'int<97, 122>' + ] + ], ]; }