Skip to content

Automatic refactoring

Automatic refactoring

Shopware CLI includes a built-in automatic refactoring tool that helps you automatically update and clean up code in your Shopware projects and extensions.

Use this tool to modernize your codebase when upgrading to a new Shopware version or to apply best-practice changes automatically.

  • Rector for PHP
  • ESLint for JavaScript
  • Custom rules for Admin Twig files

Refactoring an extension

WARNING

Before you start, make sure you work on a copy or Git-versioned branch, because this command will modify your files in place!

Refactoring an entire project

You can also refactor a full Shopware project instead of a single extension.

The CLI runs Rector and ESLint automatically. After completion, review all changes and commit or revert them as needed.

Make sure the shopware/core requirement in your composer.json file reflects the version you're targeting. Shopware CLI determines which upgrade rules to apply based on that version constraint.

Experimental Twig upgrade using Large Language Models (LLMs)

Shopware CLI also includes an experimental AI-powered Twig upgrade tool. It can help migrate Twig templates between Shopware versions by using Large Language Models (LLMs) to propose code adjustments.

Because it's experimental, only run this feature on version-controlled (in Git or similar) code. It may generate changes that need manual review.

Run the upgrade:

Supported providers

The Twig upgrade tool currently supports multiple providers:

ProviderDescriptionRequired environment variable
geminiGoogle Gemini LLMGEMINI_API_KEY
openrouterOpenRouter APIOPENROUTER_API_KEY
ollamaLocal Ollama instanceOLLAMA_HOST (optional)

Recommendations:

  • For the most accurate Twig upgrades, use Google Gemini 2.5 Pro (--provider gemini --model gemini-2.5-pro).
  • If you prefer a fully local setup, use Ollama, but ensure you have pulled a compatible model (e.g., ollama pull llama3).

After running refactoring

Use Git or your diff tool to review the changes.

Test your extension or project thoroughly.

Commit the accepted changes and discard any unwanted ones.

You can combine automatic refactoring with other Shopware CLI commands (e.g., project build or extension validate) as part of your upgrade workflow.