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 c78ce837..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 (str_contains($code, $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 c036cfcb..07cc6451 100644 --- a/src/Service/ThemeSuggester.php +++ b/src/Service/ThemeSuggester.php @@ -19,8 +19,6 @@ class ThemeSuggester private const MAX_SUGGESTIONS = 3; /** - * Constructor - * * @param ThemeList $themeList */ public function __construct( @@ -41,13 +39,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 +57,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); } }