Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/Block/Inspector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, mixed> $data */
/**
* @param Context $context
* @param State $state
* @param ScopeConfigInterface $scopeConfig
* @param DevHelper $devHelper
* @param array $data
* @phpstan-param array<string, mixed> $data
*/
public function __construct(
Context $context,
private readonly State $state,
Expand Down
9 changes: 3 additions & 6 deletions src/Model/ThemePath.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
10 changes: 5 additions & 5 deletions src/Service/ThemeSuggester.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ class ThemeSuggester
private const MAX_SUGGESTIONS = 3;

/**
* Constructor
*
* @param ThemeList $themeList
*/
public function __construct(
Expand All @@ -41,24 +39,26 @@ 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))) {
$suggestions[$themeCode] = $distance;
}
}

// Sort by distance (best matches first)
asort($suggestions);

// Return max 3 suggestions
return array_slice(array_keys($suggestions), 0, self::MAX_SUGGESTIONS);
}
}
Loading