VOOZH about

URL: https://deepwiki.com/MahoCommerce/maho-phpstan-plugin/2-getting-started

⇱ Getting Started | MahoCommerce/maho-phpstan-plugin | DeepWiki


Loading...
Menu

Getting Started

This section provides an overview of installing and using the mahocommerce/maho-phpstan-plugin in your Maho or Magento 1.x project. The plugin extends PHPStan to handle Magento's dynamic factory methods (Mage::getModel(), Mage::helper()), magic method patterns (Varien_Object::getData()/setData()), and template scope issues.

Child Pages:

For architectural details, see Architecture. For specific subsystems, see Type Inference System and Reflection Extensions.

Prerequisites

Before installing the plugin, ensure your environment meets these requirements:

RequirementVersionPurposeSource
PHP>= 8.2Runtime environmentcomposer.json7
PHPStan^2.1Static analysis enginecomposer.json8
Composer2.xPackage managementPackage distribution

The plugin is designed for analyzing Magento 1.x and Maho codebases that use:

  • Factory methods: Mage::getModel('catalog/product'), Mage::helper('core'), Mage::getSingleton()
  • Magic methods: $object->getData('field'), $object->setField($value), $object->hasField()
  • Template scoping: .phtml files with $this variable access to block methods

Sources: composer.json6-8

Installation Overview

The plugin is distributed as a Composer package with type: phpstan-extension declared in composer.json4 PHPStan automatically discovers extensions through the extra.phpstan.includes field (composer.json24-29).

Installation Workflow


For detailed installation instructions including troubleshooting, see Installation.

Sources: composer.json4 composer.json14-17 composer.json24-29

Package Structure

The plugin follows PHPStan extension conventions and organizes code into distinct subsystems:


Key Files:

  • composer.json1-31: Package metadata, dependencies, and PHPStan registration
  • extension.neon: Service definitions and PHPStan extension point registration
  • src/: PHP classes implementing PHPStan extension interfaces
  • mock/: Type stub files for Mage framework classes (loaded via autoload-dev)

Sources: composer.json2-4 composer.json14-22 composer.json24-29

Configuration Overview

After installation, the plugin is automatically active via PHPStan's extension discovery mechanism. The extension.neon file registers all components without requiring user configuration. However, you can customize behavior through your project's phpstan.neon file.

Configuration Cascade


Available Parameters

The plugin exposes configuration parameters in the parameters.mahocommerce namespace:

ParameterTypeDefaultPurpose
useLocalXmlboolfalseUse app/etc/local.xml for config resolution
enforceMagicMethodDocBlockboolfalseRequire @method annotations on Varien_Object subclasses

Example phpstan.neon:


For complete configuration details, see Configuration.

Sources: composer.json24-29

Usage Overview

Once installed and configured, the plugin operates transparently within PHPStan's analysis pipeline:

Analysis Flow


For a complete walkthrough with example code, see Quick Start Guide.

Sources: composer.json1-31

Typical Use Cases

The plugin handles several common Magento/Maho patterns:

Factory Method Type Inference

Code Pattern:


Plugin Resolution:

  • MageTypeExtension intercepts factory method calls
  • MageCoreConfig converts aliases to class names (e.g., 'catalog/product''Mage_Catalog_Model_Product')
  • PHPStan receives concrete ObjectType instead of generic object

Magic Method Recognition

Code Pattern:


Plugin Resolution:

  • VarienObjectReflectionExtension detects Varien_Object subclasses
  • Creates MagicMethodReflection wrapping getData()/setData() methods
  • PHPStan treats magic methods as valid without @method annotations

Template Scope Resolution

Code Pattern (.phtml file):


Plugin Resolution:

  • BindThisScopeResolverExtension transforms template scope
  • Wraps protected methods as public via PublicMethodReflection
  • Allows $this to access block methods without visibility errors

Sources: Based on plugin architecture

Next Steps

With the plugin installed and configured, you can:

  1. Run static analysis: Execute vendor/bin/phpstan analyse to analyze your codebase
  2. Customize behavior: Adjust configuration parameters in phpstan.neon (see Basic Configuration)
  3. Understand type inference: Learn how the plugin resolves Magento factory methods (see Type Inference System)
  4. Handle magic methods: Understand magic method analysis for Varien_Object subclasses (see Varien Object Magic Methods)
  5. Analyze templates: Configure PHTML template analysis (see PHTML Scope Resolution)

For detailed installation steps including troubleshooting, proceed to Installation. For configuration options and examples, see Basic Configuration.