Skip to content

Instantly share code, notes, and snippets.

@markshust
Created March 15, 2025 11:05
Show Gist options
  • Save markshust/b6cb04a12b6a4a0beb5e66a4ab3dc376 to your computer and use it in GitHub Desktop.
Save markshust/b6cb04a12b6a4a0beb5e66a4ab3dc376 to your computer and use it in GitHub Desktop.
Claude Code configuration for Magento

Magento 2 Dev Commands & Guidelines

Build & Installation

  • composer install - Install dependencies
  • bin/magento setup:install - Install Magento
  • bin/magento setup:upgrade - Update database schema
  • bin/magento setup:di:compile - Compile dependency injection
  • bin/magento setup:static-content:deploy - Deploy static assets

Testing

  • vendor/bin/phpunit -c dev/tests/unit/phpunit.xml.dist - Run all unit tests
  • vendor/bin/phpunit -c dev/tests/unit/phpunit.xml.dist path/to/TestFile.php - Run single test file
  • vendor/bin/phpunit -c dev/tests/unit/phpunit.xml.dist --filter testMethodName path/to/TestFile.php - Run specific test method
  • vendor/bin/phpunit -c dev/tests/integration/phpunit.xml.dist - Run integration tests

Code Quality

  • vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php - Fix code style issues
  • vendor/bin/phpstan analyse - Static analysis
  • vendor/bin/phpmd app/code/ text cleancode,codesize,controversial,design,naming,unusedcode - Mess detector

Coding Standards

  • Follow PSR-2 standards with Magento extensions
  • Use CamelCase for class names, camelCase for methods and variables
  • Use short array syntax [] instead of array()
  • Order imports alphabetically and group by namespace
  • For dependencies, favor constructor injection, use type hints
  • Handle exceptions properly, never suppress or swallow them
  • Use PHP 8.1+ features where possible
  • Always use constructor property promotion
  • Always declare parameter types and return types in methods
  • Don't add return types to functions that need to abide by an interface (models, resource models, collections, etc.)
  • Always add proper type casting for integer returns in model classes:
    • For nullable integer fields: return $this->getData(FIELD) ? (int) $this->getData(FIELD) : null;
    • For required integer fields: return (int) $this->getData(FIELD);
  • Add line break to the end of files
  • Add @throws tags to docblocks for exceptions, where appropriate
  • Use trailing commaas for all arrays and method arguments
  • Import all classes with use statements rather than using FQCNs
  • Do not add copyright headers, but add line break and declare(strict_types=1) to top of each PHP class
  • Don't nest arrays on single line, always use multi-line format for readability
  • Always add extra line breaks between conditions and before return statements, unless only statement in block
  • Always add an extra line break after parent::__construct calls
  • Methods that contain one or no parameters break curly brackets onto a new line
  • Methods with multiple parameters should have parameters on new lines with trailing commas
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment