Skip to content

Commit 4b1adaa

Browse files
committed
Allow *bin2hex and *bin2base64 functions to keep non-empty-string type
Those functions should not return a string when they receive a non-empty-string in input. The following example is expected to work: ```php <?php /** * @param non-empty-string $i */ function takesNonEmptyString(string $i): void { echo $i; } takesNonEmptyString(bin2hex("a")); takesNonEmptyString(base64_encode("a")); ```
1 parent 0b790e0 commit 4b1adaa

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

stubs/CoreGenericFunctions.phpstub

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,22 @@ function fclose(&$stream) : bool
334334
{
335335
}
336336

337+
/**
338+
* @psalm-pure
339+
* @template T as string
340+
* @param T $string
341+
* @return (T is non-empty-string ? non-empty-string : string)
342+
*/
343+
function sodium_bin2base64(string $string, int $id): string
344+
345+
/**
346+
* @psalm-pure
347+
* @template T as string
348+
* @param T $string
349+
* @return (T is non-empty-string ? non-empty-string : string)
350+
*/
351+
function sodium_bin2hex(string $string): string {}
352+
337353
/**
338354
* @param string $string
339355
* @param-out null $string
@@ -1308,9 +1324,21 @@ function base64_decode(string $string, bool $strict = false) {}
13081324
* @psalm-pure
13091325
*
13101326
* @psalm-flow ($string) -> return
1327+
* @template T as string
1328+
* @param T $string
1329+
* @return (T is non-empty-string ? non-empty-string : string)
13111330
*/
13121331
function base64_encode(string $string) : string {}
13131332

1333+
/**
1334+
* @psalm-pure
1335+
*
1336+
* @template T as string
1337+
* @param T $string
1338+
* @return (T is non-empty-string ? non-empty-string : string)
1339+
*/
1340+
function bin2hex(string $string): string {}
1341+
13141342
/**
13151343
* @psalm-pure
13161344
*

0 commit comments

Comments
 (0)