lib: Fix String::endsWith() complexity

This commit is contained in:
Eric Lippmann 2015-11-24 15:53:13 +01:00
parent 742542d52e
commit 5c3089ae85
1 changed files with 7 additions and 7 deletions

View File

@ -101,17 +101,17 @@ class String
}
/**
* Check if a string ends with a different string
* Test whether the given string ends with the given suffix
*
* @param $haystack string The string to search for matches
* @param $needle string The string to match at the start of the haystack
* @param string $string The string to test
* @param string $suffix The suffix the string must end with
*
* @return bool Whether or not needle is at the beginning of haystack
* @return bool
*/
public static function endsWith($haystack, $needle)
public static function endsWith($string, $suffix)
{
return $needle === '' ||
(($temp = strlen($haystack) - strlen($needle)) >= 0 && false !== strpos($haystack, $needle, $temp));
$stringSuffix = substr($string, -strlen($suffix));
return $stringSuffix !== false ? $stringSuffix === $suffix : false;
}
/**