Skip to content

Commit

Permalink
Allow *bin2hex and *bin2base64 functions to keep non-empty-string type
Browse files Browse the repository at this point in the history
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"));
```
  • Loading branch information
LeSuisse committed Aug 23, 2022
1 parent 0b790e0 commit 4b1adaa
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions stubs/CoreGenericFunctions.phpstub
Expand Up @@ -334,6 +334,22 @@ function fclose(&$stream) : bool
{
}

/**
* @psalm-pure
* @template T as string
* @param T $string
* @return (T is non-empty-string ? non-empty-string : string)
*/
function sodium_bin2base64(string $string, int $id): string

/**
* @psalm-pure
* @template T as string
* @param T $string
* @return (T is non-empty-string ? non-empty-string : string)
*/
function sodium_bin2hex(string $string): string {}

/**
* @param string $string
* @param-out null $string
Expand Down Expand Up @@ -1308,9 +1324,21 @@ function base64_decode(string $string, bool $strict = false) {}
* @psalm-pure
*
* @psalm-flow ($string) -> return
* @template T as string
* @param T $string
* @return (T is non-empty-string ? non-empty-string : string)
*/
function base64_encode(string $string) : string {}

/**
* @psalm-pure
*
* @template T as string
* @param T $string
* @return (T is non-empty-string ? non-empty-string : string)
*/
function bin2hex(string $string): string {}

/**
* @psalm-pure
*
Expand Down

0 comments on commit 4b1adaa

Please sign in to comment.