From 3b39046a38f513d3f267340a01d771bc3697bad6 Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Sun, 2 May 2021 14:57:47 +0000 Subject: [PATCH] [UTIL] Fix bugs found in App\Util\Formatting by tests --- src/Util/Formatting.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Util/Formatting.php b/src/Util/Formatting.php index cf6cb79d57..d815c1e2ba 100644 --- a/src/Util/Formatting.php +++ b/src/Util/Formatting.php @@ -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