Skip to content

Commit

Permalink
Add string functions from sscanf to wordwrap
Browse files Browse the repository at this point in the history
This should conclude all string functions from https://www.php.net/manual/en/book.strings.php

Continuation of vimeo#4576

Ref vimeo#3636
  • Loading branch information
LukasReschke committed Nov 21, 2020
1 parent bf873b2 commit 4629a7d
Show file tree
Hide file tree
Showing 2 changed files with 151 additions and 2 deletions.
148 changes: 146 additions & 2 deletions stubs/CoreGenericFunctions.phpstub
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,20 @@ function strtolower(string $str) : string {}
*/
function strtoupper(string $str) : string {}

/**
* @psalm-pure
*
* @param string|array<string> $string
* @param string|array<string> $replacement
* @param int|array<int> $start
* @param null|int|array<int> $length
*
* @return ($string is array<string> ? array<string> : string)
*
* @psalm-flow ($string, $replacement) -> return
*/
function substr_replace($string, $replacement, $start, $length) {}

/**
* @psalm-pure
*
Expand Down Expand Up @@ -610,6 +624,20 @@ function array_product(array $input) {}
*/
function strip_tags(string $str, ?string $allowable_tags = null) : string {}

/**
* @psalm-pure
*
* @psalm-flow ($str) -> return
*/
function stripcslashes(string $str) : string {}

/**
* @psalm-pure
*
* @psalm-flow ($str) -> return
*/
function stripslashes(string $str) : string {}

/**
* @psalm-pure
*
Expand Down Expand Up @@ -661,6 +689,104 @@ function htmlspecialchars_decode(string $string, ?int $quote_style = null) : str
*/
function str_replace($search, $replace, $subject, &$count = null) {}

/**
* @psalm-pure
*
* @param string|array<string|int|float> $search
* @param string|array<string|int|float> $replace
* @param string|array<string|int|float> $subject
* @param int $count
* @return ($subject is array ? array<string> : string)
*
* @psalm-flow ($replace, $subject) -> return
*/
function str_ireplace($search, $replace, $subject, &$count = null) {}

/**
* @psalm-pure
*
* @psalm-flow ($input, $pad_string) -> return
*/
function str_pad(string $input, int $pad_length, $pad_string = '', int $pad_type = STR_PAD_RIGHT): string {}

/**
* @psalm-pure
*
* @psalm-flow ($input) -> return
*/
function str_repeat(string $input, int $multiplier): string {}

/**
* @psalm-pure
*
* @psalm-flow ($str) -> return
*/
function str_rot13(string $str): string {}

/**
* @psalm-pure
*
* @psalm-flow ($str) -> return
*/
function str_shuffle(string $str): string {}

/**
* @psalm-pure
* @return array<string>
*
* @psalm-flow ($string) -> return
*/
function str_split(string $string, int $split_length = 1) {}

/**
* @psalm-pure
*
* @psalm-flow ($haystack) -> return
*/
function strstr(string $haystack, string $needle, bool $before_needle = false): string {}

/**
* @psalm-pure
*
* @psalm-flow ($haystack) -> return
*/
function stristr(string $haystack, string $needle, bool $before_needle = false): string {}

/**
* @psalm-pure
*
* @psalm-flow ($haystack) -> return
*/
function strchr(string $haystack, string $needle, bool $before_needle = false): string {}

/**
* @psalm-pure
*
* @psalm-flow ($haystack) -> return
*/
function strpbrk(string $haystack, string $char_list): string {}

/**
* @psalm-pure
*
* @psalm-flow ($haystack) -> return
*/
function strrchr(string $haystack, string $needle): string {}

/**
* @psalm-pure
*
* @psalm-flow ($string) -> return
*/
function strrev(string $string): string {}

/**
* @psalm-pure
*
* @psalm-flow ($string) -> return
*/
function strtok(string $str, string $token): string {}

/**
* @psalm-pure
*
Expand All @@ -681,7 +807,7 @@ function preg_filter($pattern, $replacement, $subject, int $limit = -1, &$count
* @param string|array<string|int|float> $replace
* @param string|array<string|int|float> $subject
* @param int $count
* @return ($subject is array ? array<string> : string)
* @return ($subject is array ? array<string>|null : string|null)
*
* @psalm-flow ($replace, $subject) -> return
*/
Expand All @@ -692,7 +818,7 @@ function preg_replace($search, $replace, $subject, int $limit = -1, &$count = nu
* @param callable(array<int, string>):string $replace
* @param string|array<string|int|float> $subject
* @param int $count
* @return ($subject is array ? array<string> : string)
* @return ($subject is array ? array<string>|null : string|null)
*
* @psalm-taint-specialize
* @psalm-flow ($subject) -> return
Expand Down Expand Up @@ -761,6 +887,22 @@ function preg_quote(string $str, ?string $delimiter = null) : string {}
*/
function sprintf(string $format, ...$args) : string {}

/**
* @psalm-pure
* @return string|false
*
* @psalm-flow ($format, $args) -> return
*/
function vsprintf(string $format, array $args) {}

/**
* @psalm-pure
* @return string
*
* @psalm-flow ($str) -> return
*/
function wordwrap(string $str, int $width = 75, string $break = "\n", bool $cut = false) : string {}

/**
* @psalm-pure
*
Expand Down Expand Up @@ -802,6 +944,8 @@ function strval ($var): string {}
/**
* @return ($input is non-empty-string ? non-empty-list<string> : non-empty-list<string>|array{null})
* @psalm-pure
*
* @psalm-flow ($input) -> return
*/
function str_getcsv(string $input, string $delimiter = ',', string $enclosure = '"', string $escape = '\\\\')
{
Expand Down
5 changes: 5 additions & 0 deletions tests/test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

$email = (string)$_GET['bar'];
$domain = substr_replace($email,[4], 4);
echo $domain; // prints @example.com

0 comments on commit 4629a7d

Please sign in to comment.