composer install
- Install dependenciesbin/magento setup:install
- Install Magentobin/magento setup:upgrade
- Update database schemabin/magento setup:di:compile
- Compile dependency injectionbin/magento setup:static-content:deploy
- Deploy static assets
vendor/bin/phpunit -c dev/tests/unit/phpunit.xml.dist
- Run all unit testsvendor/bin/phpunit -c dev/tests/unit/phpunit.xml.dist path/to/TestFile.php
- Run single test filevendor/bin/phpunit -c dev/tests/unit/phpunit.xml.dist --filter testMethodName path/to/TestFile.php
- Run specific test methodvendor/bin/phpunit -c dev/tests/integration/phpunit.xml.dist
- Run integration tests
vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php
- Fix code style issuesvendor/bin/phpstan analyse
- Static analysisvendor/bin/phpmd app/code/ text cleancode,codesize,controversial,design,naming,unusedcode
- Mess detector
- Follow PSR-2 standards with Magento extensions
- Use CamelCase for class names, camelCase for methods and variables
- Use short array syntax
[]
instead ofarray()
- 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);
- For nullable integer fields:
- 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