Loading...
Loading...
Generates PHPStan configurations for PHP projects. Creates phpstan.neon with appropriate level, extensions, paths, baseline support, and DDD-specific rules.
npx skill4agent add dykyi-roman/awesome-claude-code acc-create-phpstan-configphpstan.neon # Main configuration
phpstan-baseline.neon # Error baseline (if needed)# phpstan.neon
includes:
- vendor/phpstan/phpstan-strict-rules/rules.neon
- vendor/phpstan/phpstan-deprecation-rules/rules.neon
- vendor/phpstan/phpstan-phpunit/extension.neon
parameters:
level: 8
phpVersion: 80400
paths:
- src
- tests
excludePaths:
- tests/Fixtures/*
- src/Infrastructure/Legacy/*
# Strict type checking
checkMissingIterableValueType: true
checkGenericClassInNonGenericObjectType: true
checkUninitializedProperties: true
checkImplicitMixed: true
reportUnmatchedIgnoredErrors: true
# Parallel processing
parallel:
maximumNumberOfProcesses: 4# phpstan.neon
includes:
- phpstan-baseline.neon
- vendor/phpstan/phpstan-strict-rules/rules.neon
- vendor/phpstan/phpstan-deprecation-rules/rules.neon
parameters:
level: 6
paths:
- src
- tests
excludePaths:
- src/Legacy/*
- tests/Fixtures/*
# Gradually increase strictness
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
# Type aliases for legacy code
typeAliases:
UserId: 'int|string'
Timestamp: 'int|DateTimeInterface'# phpstan.neon
includes:
- vendor/phpstan/phpstan-strict-rules/rules.neon
- vendor/phpstan/phpstan-deprecation-rules/rules.neon
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-doctrine/extension.neon
parameters:
level: 9
phpVersion: 80400
paths:
- src
excludePaths:
- src/Infrastructure/Migrations/*
# Strict for Domain layer
checkMissingIterableValueType: true
checkGenericClassInNonGenericObjectType: true
checkUninitializedProperties: true
checkImplicitMixed: true
# Report all issues
reportUnmatchedIgnoredErrors: true
reportStaticMethodSignatures: true
# Parallel for speed
parallel:
maximumNumberOfProcesses: 8
processTimeout: 300.0
# Custom parameters
doctrine:
repositoryClass: App\Infrastructure\Persistence\DoctrineRepository
objectManagerLoader: tests/object-manager.php
# Ignore patterns
ignoreErrors:
# Doctrine entities
- '#Property .+ has no type specified#'
path: src/Infrastructure/Doctrine/Entity/*
# Value Objects immutability
- '#Readonly property .+ is assigned outside of its declaring class#'
path: src/Domain/*/ValueObject/*
# Custom rules
rules:
- App\PHPStan\DomainLayerRule
- App\PHPStan\ValueObjectImmutabilityRuleincludes:
- vendor/phpstan/phpstan-phpunit/extension.neon
parameters:
# PHPUnit-specific settings
phpunit:
configPath: phpunit.xmlincludes:
- vendor/phpstan/phpstan-doctrine/extension.neon
parameters:
doctrine:
repositoryClass: Doctrine\ORM\EntityRepository
objectManagerLoader: tests/object-manager.phpincludes:
- vendor/phpstan/phpstan-symfony/extension.neon
- vendor/phpstan/phpstan-symfony/rules.neon
parameters:
symfony:
containerXmlPath: var/cache/dev/App_KernelDevDebugContainer.xml
consoleApplicationLoader: tests/console-application.phpparameters:
ignoreErrors:
# Constructor property promotion
- '#Constructor of class .+ has an unused parameter#'
# Doctrine entities
- '#Property .+ does not accept null#'
path: src/Infrastructure/Doctrine/Entity/*
# Test doubles
- '#Call to an undefined method .+Mock::#'
path: tests/*
# Dynamic properties in tests
- '#Access to an undefined property .+Test::\$#'
path: tests/*
# Factory methods
- '#Method .+Factory::create\(\) should return .+ but returns#'
# Event handlers
- '#Parameter .+ of method .+Handler::__invoke\(\) has no type specified#'# Generate baseline for existing errors
vendor/bin/phpstan analyse --generate-baseline
# Generate baseline with specific name
vendor/bin/phpstan analyse --generate-baseline=phpstan-baseline.neon
# Analyze and exclude baseline errors
vendor/bin/phpstan analyse# Step 1: Start with baseline at current level
parameters:
level: 0
# Step 2: Generate baseline
# vendor/bin/phpstan analyse --generate-baseline
# Step 3: Increase level
parameters:
level: 1
# Step 4: Fix new errors or add to baseline
# Repeat until level 8| Level | Focus | Timeline |
|---|---|---|
| 0-2 | Basic errors, undefined variables | Week 1 |
| 3-4 | Return types, dead code | Week 2-3 |
| 5-6 | Argument types, type hints | Week 4-6 |
| 7-8 | Union types, no mixed | Week 7-10 |
| 9 | Maximum strictness | Ongoing |
phpstan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
- run: composer install
- run: vendor/bin/phpstan analyse --memory-limit=1G --error-format=githubphpstan:
script:
- vendor/bin/phpstan analyse --memory-limit=1G --error-format=gitlab > phpstan.json
artifacts:
reports:
codequality: phpstan.jsonparameters:
# Parallel processing
parallel:
maximumNumberOfProcesses: 8
processTimeout: 300.0
# Cache results
tmpDir: var/cache/phpstan
# Memory limit
memoryLimitFile: 1Gcomposer.jsonphpstan.neon