solido/php-coding-standards
Solido PHP coding standards meta-package: shared dev requirements for Solido suite tooling and analyzers (e.g., PHPStan, PHP_CodeSniffer). Use dev-master; no stable releases. Include as a dev dependency in all Solido PHP packages.
Install the Package
Add to your Laravel project’s composer.json under require-dev:
composer require --dev solido/php-coding-standards:dev-master
Ensure your composer.json explicitly locks the version to avoid unintended updates:
"config": {
"preferred-install": "dist",
"sort-packages": true
}
First Use Case: PHPCS Integration Run PHPCS with Solido’s standards directly:
vendor/bin/phpcs --standard=./vendor/solido/php-coding-standards src/ tests/
For a quick check, use the --report=summary flag to avoid overwhelming output.
First Use Case: PHPStan Integration
Create a minimal phpstan.neon file in your project root:
includes:
- vendor/solido/phpstan-rules/extension.neon
- vendor/kcs/phpstan-strict-rules/rules.neon
parameters:
level: max
paths:
- src
- tests
Run PHPStan:
vendor/bin/phpstan analyse
First Use Case: Security Checks Add a security advisory check to your CI/CD pipeline:
vendor/bin/security-checker security:check
Local Development
# .husky/pre-commit
#!/bin/sh
vendor/bin/phpcs --standard=./vendor/solido/php-coding-standards src/ tests/ || exit 1
vendor/bin/phpstan analyse --error-format=checkstyle || exit 1
CI/CD Pipeline
Integrate checks into Laravel’s GitHub Actions workflow (.github/workflows/laravel.yml):
name: Laravel Coding Standards
on: [push, pull_request]
jobs:
coding-standards:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-php@v3
with:
php-version: '8.2'
- run: composer install --prefer-dist --no-interaction
- name: Run PHPCS
run: vendor/bin/phpcs --standard=./vendor/solido/php-coding-standards --report=full src/ tests/
- name: Run PHPStan
run: vendor/bin/phpstan analyse --error-format=github
- name: Run Security Check
run: vendor/bin/security-checker security:check
Custom Artisan Commands Create a custom Artisan command to run all checks:
php artisan make:command CheckStandards
Update the generated file (app/Console/Commands/CheckStandards.php):
public function handle()
{
$this->info('Running PHPCS...');
$this->callSilently('vendor/bin/phpcs', [
'--standard=./vendor/solido/php-coding-standards',
'src/',
'tests/',
]);
$this->info('Running PHPStan...');
$this->callSilently('vendor/bin/phpstan', ['analyse']);
$this->info('Running Security Check...');
$this->callSilently('vendor/bin/security-checker', ['security:check']);
}
Run with:
php artisan check:standards
Excluding Laravel Framework Code
Configure PHPStan to ignore Laravel’s internal files in phpstan.neon:
parameters:
excludePaths:
- vendor/laravel/framework/
- vendor/solido/*
Custom Rules for Laravel Extend Solido’s PHPStan rules to handle Laravel-specific patterns (e.g., dynamic properties):
includes:
- vendor/solido/phpstan-rules/extension.neon
- vendor/kcs/phpstan-strict-rules/rules.neon
- rules.neon # Your custom rules
Example rules.neon:
parameters:
rules:
Solido\PHPStanRules\Rules\*:
excludeClasses:
- Illuminate\Foundation\Application
- Illuminate\Database\Eloquent\Model
Integration with Laravel Valet
Add checks to your ~/.valet/Laravel/valet.php for local development:
if (file_exists(__DIR__ . '/../../composer.json')) {
$composer = json_decode(file_get_contents(__DIR__ . '/../../composer.json'), true);
if (isset($composer['require-dev']['solido/php-coding-standards'])) {
putenv('VALET_PHPSTAN=1');
putenv('VALET_PHPCS=1');
}
}
Strict PHPStan Rules
level: max may flag Laravel’s dynamic properties or magic methods as errors.phpstan.neon:
parameters:
rules:
PhpStan\Rules\*:
excludeClasses:
- Illuminate\Support\Traits\ForwardsCalls
PHPCS Path Issues
Could not open "./vendor/solido/php-coding-standards".vendor/bin/phpcs --standard=$(pwd)/vendor/solido/php-coding-standards src/
Dependency Conflicts
phpstan/extension-installer).composer.json:
"require-dev": {
"phpstan/extension-installer": "^1.1",
"solido/phpstan-rules": "dev-master"
}
CI/CD Timeouts
- name: Cache Composer
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
- name: Cache PHPStan
uses: actions/cache@v3
with:
path: .phpstan.cache
key: ${{ runner.os }}-phpstan-${{ hashFiles('**/composer.lock') }}
Unstable dev-master
dev-master may break your pipeline.composer.json:
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"allow-plugins": {
"composer/semver": true
}
}
PHPCS Debugging
--debug to diagnose path or rule issues:
vendor/bin/phpcs --standard=./vendor/solido/php-coding-standards --debug src/
--report=full for detailed error messages.PHPStan Debugging
--verbose for detailed output:
vendor/bin/phpstan analyse --verbose
--memory-limit=1G to avoid memory issues on large codebases.Security Checker Debugging
--format=json to analyze advisories programmatically:
vendor/bin/security-checker security:check --format=json > security.json
Custom PHPCS Rules
Extend Solido’s standards by creating a custom .phpcs.xml file:
<config name="standard" value="./vendor/solido/php-coding-standards"/>
<config name="extensions" value="php,inc,module,install,test,sh"/>
<rule ref="solido">
<exclude name="Generic.Files.LineEndings" />
</rule>
Custom PHPStan Rules
Add custom rules to phpstan.neon:
includes:
- vendor/solido/phpstan-rules/extension.neon
- rules/custom.neon
Example rules/custom.neon:
How can I help you explore Laravel packages today?