[UTIL] Fix bugs found in App\Util\Formatting by tests

This commit is contained in:
Hugo Sales 2021-05-02 14:57:47 +00:00
parent 15a8f8ab7f
commit 3b39046a38
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
1 changed files with 4 additions and 4 deletions

View File

@ -48,9 +48,9 @@ abstract class Formatting
return self::$twig->createTemplate($template, null)->render($context);
}
public static function twigRenderFile(string $template, array $context): string
public static function twigRenderFile(string $template_path, array $context): string
{
return self::$twig->render($template, $context);
return self::$twig->render($template_path, $context);
}
/**
@ -62,7 +62,7 @@ abstract class Formatting
*/
public static function normalizePath(string $path): string
{
return str_replace(['/', '\\'], ['/', '/'], $path);
return preg_replace(',(/|\\\\)+,', '/', $path);
}
/**
@ -151,7 +151,7 @@ abstract class Formatting
*/
public static function removeSuffix(string $haystack, string $needle)
{
return self::startsWith($haystack, $needle) ? substr($haystack, -strlen($needle)) : $haystack;
return self::endsWith($haystack, $needle) && !empty($needle) ? substr($haystack, 0, -strlen($needle)) : $haystack;
}
public static function camelCaseToSnakeCase(string $str): string