Skip to content

Commit

Permalink
[GHA] Add PHP 8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Sep 14, 2021
1 parent 46cd957 commit f24ae46
Showing 1 changed file with 29 additions and 24 deletions.
53 changes: 29 additions & 24 deletions Ctype.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ final class Ctype
*
* @see https://php.net/ctype-alnum
*
* @param string|int $text
* @param mixed $text
*
* @return bool
*/
public static function ctype_alnum($text)
{
$text = self::convert_int_to_char_for_ctype($text);
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);

return \is_string($text) && '' !== $text && !preg_match('/[^A-Za-z0-9]/', $text);
}
Expand All @@ -41,13 +41,13 @@ public static function ctype_alnum($text)
*
* @see https://php.net/ctype-alpha
*
* @param string|int $text
* @param mixed $text
*
* @return bool
*/
public static function ctype_alpha($text)
{
$text = self::convert_int_to_char_for_ctype($text);
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);

return \is_string($text) && '' !== $text && !preg_match('/[^A-Za-z]/', $text);
}
Expand All @@ -57,13 +57,13 @@ public static function ctype_alpha($text)
*
* @see https://php.net/ctype-cntrl
*
* @param string|int $text
* @param mixed $text
*
* @return bool
*/
public static function ctype_cntrl($text)
{
$text = self::convert_int_to_char_for_ctype($text);
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);

return \is_string($text) && '' !== $text && !preg_match('/[^\x00-\x1f\x7f]/', $text);
}
Expand All @@ -73,13 +73,13 @@ public static function ctype_cntrl($text)
*
* @see https://php.net/ctype-digit
*
* @param string|int $text
* @param mixed $text
*
* @return bool
*/
public static function ctype_digit($text)
{
$text = self::convert_int_to_char_for_ctype($text);
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);

return \is_string($text) && '' !== $text && !preg_match('/[^0-9]/', $text);
}
Expand All @@ -89,13 +89,13 @@ public static function ctype_digit($text)
*
* @see https://php.net/ctype-graph
*
* @param string|int $text
* @param mixed $text
*
* @return bool
*/
public static function ctype_graph($text)
{
$text = self::convert_int_to_char_for_ctype($text);
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);

return \is_string($text) && '' !== $text && !preg_match('/[^!-~]/', $text);
}
Expand All @@ -105,13 +105,13 @@ public static function ctype_graph($text)
*
* @see https://php.net/ctype-lower
*
* @param string|int $text
* @param mixed $text
*
* @return bool
*/
public static function ctype_lower($text)
{
$text = self::convert_int_to_char_for_ctype($text);
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);

return \is_string($text) && '' !== $text && !preg_match('/[^a-z]/', $text);
}
Expand All @@ -121,13 +121,13 @@ public static function ctype_lower($text)
*
* @see https://php.net/ctype-print
*
* @param string|int $text
* @param mixed $text
*
* @return bool
*/
public static function ctype_print($text)
{
$text = self::convert_int_to_char_for_ctype($text);
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);

return \is_string($text) && '' !== $text && !preg_match('/[^ -~]/', $text);
}
Expand All @@ -137,13 +137,13 @@ public static function ctype_print($text)
*
* @see https://php.net/ctype-punct
*
* @param string|int $text
* @param mixed $text
*
* @return bool
*/
public static function ctype_punct($text)
{
$text = self::convert_int_to_char_for_ctype($text);
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);

return \is_string($text) && '' !== $text && !preg_match('/[^!-\/\:-@\[-`\{-~]/', $text);
}
Expand All @@ -153,13 +153,13 @@ public static function ctype_punct($text)
*
* @see https://php.net/ctype-space
*
* @param string|int $text
* @param mixed $text
*
* @return bool
*/
public static function ctype_space($text)
{
$text = self::convert_int_to_char_for_ctype($text);
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);

return \is_string($text) && '' !== $text && !preg_match('/[^\s]/', $text);
}
Expand All @@ -169,13 +169,13 @@ public static function ctype_space($text)
*
* @see https://php.net/ctype-upper
*
* @param string|int $text
* @param mixed $text
*
* @return bool
*/
public static function ctype_upper($text)
{
$text = self::convert_int_to_char_for_ctype($text);
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);

return \is_string($text) && '' !== $text && !preg_match('/[^A-Z]/', $text);
}
Expand All @@ -185,13 +185,13 @@ public static function ctype_upper($text)
*
* @see https://php.net/ctype-xdigit
*
* @param string|int $text
* @param mixed $text
*
* @return bool
*/
public static function ctype_xdigit($text)
{
$text = self::convert_int_to_char_for_ctype($text);
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);

return \is_string($text) && '' !== $text && !preg_match('/[^A-Fa-f0-9]/', $text);
}
Expand All @@ -204,11 +204,12 @@ public static function ctype_xdigit($text)
* (negative values have 256 added in order to allow characters in the Extended ASCII range).
* Any other integer is interpreted as a string containing the decimal digits of the integer.
*
* @param string|int $int
* @param mixed $int
* @param string $function
*
* @return mixed
*/
private static function convert_int_to_char_for_ctype($int)
private static function convert_int_to_char_for_ctype($int, $function)
{
if (!\is_int($int)) {
return $int;
Expand All @@ -218,6 +219,10 @@ private static function convert_int_to_char_for_ctype($int)
return (string) $int;
}

if (\PHP_VERSION_ID >= 80100) {
@trigger_error($function.'(): Argument of type int will be interpreted as string in the future', \E_USER_DEPRECATED);
}

if ($int < 0) {
$int += 256;
}
Expand Down

0 comments on commit f24ae46

Please sign in to comment.