Skip to content

fix: refine theme path matching and enhance theme suggestion logic#179

Merged
dermatz merged 2 commits intomainfrom
fix/theme-suggester
Apr 26, 2026
Merged

fix: refine theme path matching and enhance theme suggestion logic#179
dermatz merged 2 commits intomainfrom
fix/theme-suggester

Conversation

@dermatz
Copy link
Copy Markdown
Member

@dermatz dermatz commented Apr 26, 2026

This pull request improves the accuracy and robustness of theme code matching and theme suggestions. The main changes include stricter matching logic in ThemePath, better handling of empty input, and more consistent, case-insensitive comparison in the theme suggestion logic.

Theme path resolution improvements:

  • The getPath method in ThemePath.php now only returns a path if the theme code matches exactly with either 'frontend/' . $themeCode or 'adminhtml/' . $themeCode, instead of using a substring match. This prevents accidental partial matches and ensures more precise theme resolution.

Theme suggestion robustness and accuracy:

  • The findSimilarThemes method in ThemeSuggester.php now immediately returns an empty array if the input theme name is empty, preventing unnecessary processing and possible errors.
  • Theme code comparisons in findSimilarThemes are now performed in a case-insensitive manner for both Levenshtein distance and substring checks, improving the quality and user-friendliness of suggestions.

Code cleanup:

  • Removed redundant constructor docblock comments in ThemeSuggester.php for improved code clarity.

Co-authored-by: Copilot <copilot@github.com>
Copilot AI review requested due to automatic review settings April 26, 2026 13:20
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR tightens Magento theme resolution and improves CLI theme suggestions by avoiding partial theme-code matches and making suggestion matching more robust and case-insensitive.

Changes:

  • Refined ThemePath::getPath() to only match exact frontend/<themeCode> or adminhtml/<themeCode> registrations (no substring matches).
  • Improved ThemeSuggester::findSimilarThemes() to early-return on empty input and compare theme codes case-insensitively for both Levenshtein and substring matching.
  • Removed redundant constructor docblock noise in ThemeSuggester.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/Service/ThemeSuggester.php Makes theme suggestions safer (empty input) and more user-friendly (case-insensitive matching).
src/Model/ThemePath.php Prevents accidental partial matches by requiring exact theme registration key matches.
Comments suppressed due to low confidence (1)

src/Service/ThemeSuggester.php:53

  • strtolower($invalidTheme) and strtolower($themeCode) are recomputed multiple times per iteration (for both levenshtein and str_contains). Consider precomputing the lowercased input once before the loop, and lowercasing $themeCode once per iteration, to reduce repeated work and keep the matching logic easier to read.
        $themes = $this->themeList->getAllThemes();
        $threshold = (int) (strlen($invalidTheme) / 3);
        $suggestions = [];

        foreach ($themes as $theme) {
            $themeCode = $theme->getCode();
            $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;

Comment thread src/Model/ThemePath.php Outdated
@dermatz dermatz merged commit 3484f34 into main Apr 26, 2026
13 checks passed
@dermatz dermatz deleted the fix/theme-suggester branch April 26, 2026 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants