magento-controller-refactor_skill

This skill refactors legacy Magento 2 controllers to modern HTTP verb interfaces, improving type safety and PHP 8.3+ compatibility.

7

GitHub Stars

1

Bundled Files

2 months ago

Catalog Refreshed

4 months ago

First Indexed

Readme & install

Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.

Installation

Preview and clipboard use veilstrat where the catalogue uses aiagentskills.

npx veilstrat add skill proxiblue/claude-skills --skill magento-controller-refactor

  • SKILL.md4.9 KB

Overview

This skill scans Magento 2 controller code and refactors deprecated controller patterns to modern HTTP-verb-based controllers compatible with PHP 8.3+. It modernizes controllers that extend the deprecated Action base class, replaces Context injection with specific dependencies, and ensures typed properties and correct return types.

How this skill works

The skill searches a chosen scope (directory, module, or single file) for controllers extending Magento\Framework\App\Action\Action, old Context injection patterns, and missing HTTP verb interfaces. For each match it shows the file and lines, explains required changes, and can apply refactors: remove Action inheritance, add the correct Http*ActionInterface(s), inject ResultFactory/RequestInterface/ResponseInterface or other needed services, add typed properties, and ensure execute() returns ResultInterface. It performs safety checks, produces diffs, and verifies PHP syntax after changes.

When to use it

  • Modernizing legacy Magento 2 controllers before upgrading to PHP 8.3+
  • Removing reliance on the deprecated Action base class
  • Preparing modules for stricter typed properties and return types
  • Converting controllers to explicit HTTP verb interfaces for clearer routing
  • Batch-updating many controllers across a module or codebase

Best practices

  • Scan a targeted scope first and review findings before applying changes
  • Confirm each refactor with a diff and keep business logic unchanged
  • Inject only required services instead of passing full Context
  • Use declare(strict_types=1) and PHP 8.3 typed properties for all new/updated classes
  • Run php -l on changed files and then bin/magento setup:di:compile and bin/magento cache:flush

Example use cases

  • Refactor a module where controllers still extend Action to implement HttpGetActionInterface or HttpPostActionInterface
  • Replace Context injection with ResultFactory and RequestInterface in multiple controllers
  • Convert controllers using $this->_redirect() to ResultFactory redirect results
  • Add typed properties and explicit ResultInterface return types to prepare for PHP 8.3
  • Audit app/code for controllers missing HTTP verb interfaces and apply consistent patterns

FAQ

No. The refactor preserves existing logic; it only changes class structure, dependencies, and result handling. You should review diffs before committing.

How do you handle controllers that accept multiple HTTP methods?

Controllers can implement multiple Http*ActionInterface interfaces. The refactor will add the appropriate interfaces based on detected request handling and keep execute() as the single entry point.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational
magento-controller-refactor skill by proxiblue/claude-skills | VeilStrat