shopwarelabs / phpstan-shopware
PhpStan Rules for Shopware
Requires
- php: ^8.2
- phpstan/phpstan: ^2
- symfony/polyfill-php84: *
Requires (Dev)
- friendsofphp/php-cs-fixer: v3.64.0
- phpstan/extension-installer: *
- phpunit/phpunit: ~11.3.6
- shopware/core: ^6.6
README
This package provides additional PHPStan rules for Shopware 6 projects. It helps developers catch common mistakes and enforce best practices specific to Shopware development.
Installation
You can install the package via composer:
composer require --dev shopwarelabs/phpstan-shopware
Usage
To use these rules, include the package's configuration file in your PHPStan configuration:
includes: - vendor/shopwarelabs/phpstan-shopware/rules.neon
or you use PHPStan Extension Installer
Features
- Custom rules for Shopware 6.5 specific patterns
- Improved type inference for Shopware core classes
- Additional checks for common Shopware development pitfalls
Available Rules
Here's a comprehensive list of all available rules:
-
NoSuperglobalsRule: Prevents usage of superglobals (
$_GET
,$_POST
,$_FILES
,$_REQUEST
). Use proper request objects instead. -
DisallowFunctionsRule: Prevents usage of certain disallowed functions in the codebase.
-
NoEntityRepositoryInLoopRule: Prevents EntityRepository method calls within loops to avoid N+1 query problems.
-
NoSessionInPaymentHandlerAndStoreApiRule: Prevents usage of session in payment handlers and Store API contexts.
-
NoSymfonySessionInConstructorRule: Prevents injection of Symfony Session in constructor to avoid early session starts.
-
ForbidGlobBraceRule: Prevents usage of glob brace expansion for better cross-platform compatibility.
-
InternalClassExtendsRule: Ensures proper extension of internal classes.
-
NoUserEntityGetStoreTokenRule: Prevents direct access to store tokens from User entities.
-
MethodBecomesAbstractRule: Checks for methods that should be abstract.
-
ClassExtendUsesAbstractClassWhenExisting: Enforces the use of abstract classes when they exist.
-
NoDALFilterByID: Prevents direct ID filtering in DAL queries.
-
ScheduledTaskTooLowIntervalRule: Ensures scheduled tasks don't have too low intervals.
-
DisallowDefaultContextCreation: Prevents creation of default contexts in inappropriate places.
-
SetForeignKeyRule: Enforces proper foreign key handling.
-
InternalFunctionCallRule: Controls usage of internal functions.
-
InternalMethodCallRule: Controls usage of internal methods.
Configuration
You can customize the behavior of these rules by adding configuration to your phpstan.neon
file. See the configuration section for more details.
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for details.
License
The MIT License (MIT). Please see License File for more information.