Skip to content

Commit

Permalink
lib: Fix String::endsWith() complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
lippserd committed Nov 24, 2015
1 parent 742542d commit 5c3089a
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions library/Icinga/Util/String.php
Expand Up @@ -101,17 +101,17 @@ public static function findSimilar($string, array $possibilities, $similarity =
}

/**
* 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;
}

/**
Expand Down

0 comments on commit 5c3089a

Please sign in to comment.