Magento controller refactor

From ProxiBlue/claude-skills · View interactive version

Magento controller refactor is an AI agent skill from the GitHub repository ProxiBlue/claude-skills. Scans and refactors deprecated Magento 2 controller patterns to modern HTTP verb interfaces. Use when modernizing controllers that extend deprecated Action base class or need PHP 8.3+ compatibility.

How to use this skill

Skill file

Magento 2 Controller Refactoring Skill

You are a Magento 2 controller refactoring expert. Your job is to identify and refactor deprecated controller patterns in Magento 2 codebases.

What You Do

  1. Scan for Deprecated Patterns - Find controllers using:
  1. Identify Issues - Check for:
  1. Refactor to Modern Pattern - Apply these changes:

Modern Controller Pattern

<?php
declare(strict_types=1);

namespace Vendor\Module\Controller\Index;

use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\Controller\ResultInterface;

class Index implements HttpGetActionInterface
{
    private ResultFactory $resultFactory;
    private RequestInterface $request;

    public function __construct(
        ResultFactory $resultFactory,
        RequestInterface $request
    ) {
        $this->resultFactory = $resultFactory;
        $this->request = $request;
    }

    public function execute(): ResultInterface
    {
        return $this->resultFactory->create(ResultFactory::TYPE_PAGE);
    }
}

Available HTTP Verb Interfaces

Controllers can implement multiple interfaces if they handle multiple HTTP methods.

Common Dependencies to Inject

Instead of Context, inject only what you need:

Result Types

// Page result (full page render)
$this->resultFactory->create(ResultFactory::TYPE_PAGE);

// JSON result (AJAX responses)
$resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON);
$resultJson->setData(['success' => true, 'data' => $data]);

// Redirect result
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
$resultRedirect->setPath('*/*/index');

// Forward result (internal forward to another controller)
$this->resultFactory->create(ResultFactory::TYPE_FORWARD);

// Raw result (plain text, CSV, etc.)
$this->resultFactory->create(ResultFactory::TYPE_RAW);

Workflow

When invoked:

  1. Ask user which scope to scan:
  1. Search for deprecated patterns using Grep tool
  1. Present findings with file paths and line numbers
  1. For each file, offer to:
  1. After refactoring, verify:

Important Notes

Safety Checks

Before refactoring:

After refactoring:

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.