New rule: explode() limit parameter must be set

This commit is contained in:
Dylan K. Taylor
2025-03-04 20:44:01 +00:00
parent 3a2d0d77d1
commit d0d84d4c51
19 changed files with 136 additions and 25 deletions

View File

@ -72,9 +72,11 @@ final class JwtUtils{
* @throws JwtException
*/
public static function split(string $jwt) : array{
$v = explode(".", $jwt);
//limit of 4 allows us to detect too many parts without having to split the string up into a potentially large
//number of parts
$v = explode(".", $jwt, limit: 4);
if(count($v) !== 3){
throw new JwtException("Expected exactly 3 JWT parts, got " . count($v));
throw new JwtException("Expected exactly 3 JWT parts delimited by a period");
}
return [$v[0], $v[1], $v[2]]; //workaround phpstan bug
}