From fc1747b90cba6a28176225aee7631a1d1744df70 Mon Sep 17 00:00:00 2001 From: Mathias Elle Date: Sun, 26 Apr 2026 15:20:05 +0200 Subject: [PATCH 1/2] fix: refine theme path matching and enhance theme suggestion logic Co-authored-by: Copilot --- src/Model/ThemePath.php | 2 +- src/Service/ThemeSuggester.php | 13 +++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/Model/ThemePath.php b/src/Model/ThemePath.php index c78ce837..0071a436 100644 --- a/src/Model/ThemePath.php +++ b/src/Model/ThemePath.php @@ -27,7 +27,7 @@ public function getPath(string $themeCode): ?string { $registeredThemes = $this->componentRegistrar->getPaths(ComponentRegistrar::THEME); foreach ($registeredThemes as $code => $path) { - if (str_contains($code, $themeCode)) { + if ($code === 'frontend/' . $themeCode || $code === 'adminhtml/' . $themeCode) { return $path; } } diff --git a/src/Service/ThemeSuggester.php b/src/Service/ThemeSuggester.php index c036cfcb..9a60ec46 100644 --- a/src/Service/ThemeSuggester.php +++ b/src/Service/ThemeSuggester.php @@ -18,11 +18,6 @@ class ThemeSuggester */ private const MAX_SUGGESTIONS = 3; - /** - * Constructor - * - * @param ThemeList $themeList - */ public function __construct( private readonly ThemeList $themeList, ) { @@ -41,13 +36,17 @@ public function __construct( */ public function findSimilarThemes(string $invalidTheme): array { + if ($invalidTheme === '') { + return []; + } + $themes = $this->themeList->getAllThemes(); $threshold = (int) (strlen($invalidTheme) / 3); $suggestions = []; foreach ($themes as $theme) { $themeCode = $theme->getCode(); - $distance = levenshtein($invalidTheme, $themeCode); + $distance = levenshtein(strtolower($invalidTheme), strtolower($themeCode)); // Accept if: distance ≤ 1/3 of input length OR substring match (case-insensitive) if ($distance <= $threshold || str_contains(strtolower($themeCode), strtolower($invalidTheme))) { @@ -55,10 +54,8 @@ public function findSimilarThemes(string $invalidTheme): array } } - // Sort by distance (best matches first) asort($suggestions); - // Return max 3 suggestions return array_slice(array_keys($suggestions), 0, self::MAX_SUGGESTIONS); } } From ad2eb35a77dfef3a93689cd0b26d5ad4cfa8e201 Mon Sep 17 00:00:00 2001 From: Mathias Elle Date: Sun, 26 Apr 2026 15:31:13 +0200 Subject: [PATCH 2/2] fix: enhance constructor PHPDoc for Inspector and ThemeSuggester classes Co-authored-by: Copilot --- src/Block/Inspector.php | 9 ++++++++- src/Model/ThemePath.php | 9 +++------ src/Service/ThemeSuggester.php | 3 +++ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/Block/Inspector.php b/src/Block/Inspector.php index 14f85198..6c3b3c05 100644 --- a/src/Block/Inspector.php +++ b/src/Block/Inspector.php @@ -20,7 +20,14 @@ class Inspector extends Template private const XML_PATH_INSPECTOR_ENABLED = 'dev/mageforge_inspector/enabled'; private const XML_PATH_SHOW_BUTTON_LABELS = 'mageforge/inspector/show_button_labels'; - /** @phpstan-param array $data */ + /** + * @param Context $context + * @param State $state + * @param ScopeConfigInterface $scopeConfig + * @param DevHelper $devHelper + * @param array $data + * @phpstan-param array $data + */ public function __construct( Context $context, private readonly State $state, diff --git a/src/Model/ThemePath.php b/src/Model/ThemePath.php index 0071a436..bed867b5 100644 --- a/src/Model/ThemePath.php +++ b/src/Model/ThemePath.php @@ -26,12 +26,9 @@ public function __construct( public function getPath(string $themeCode): ?string { $registeredThemes = $this->componentRegistrar->getPaths(ComponentRegistrar::THEME); - foreach ($registeredThemes as $code => $path) { - if ($code === 'frontend/' . $themeCode || $code === 'adminhtml/' . $themeCode) { - return $path; - } - } - return null; + return $registeredThemes['frontend/' . $themeCode] + ?? $registeredThemes['adminhtml/' . $themeCode] + ?? null; } } diff --git a/src/Service/ThemeSuggester.php b/src/Service/ThemeSuggester.php index 9a60ec46..07cc6451 100644 --- a/src/Service/ThemeSuggester.php +++ b/src/Service/ThemeSuggester.php @@ -18,6 +18,9 @@ class ThemeSuggester */ private const MAX_SUGGESTIONS = 3; + /** + * @param ThemeList $themeList + */ public function __construct( private readonly ThemeList $themeList, ) {