21torr/janus
Janus PHP provides shared configuration for CI and PHP code style tools, making it easy to standardize linting, formatting, and automation across projects. Includes ready-to-use presets and documentation for quick setup.
Installation: Add Janus to your project via Composer:
composer require --dev 21torr/janus
Ensure your composer.json specifies either "type": "project" (Symfony/Laravel) or "type": "library" for non-framework projects.
First Run: Initialize Janus with the correct package type (auto-detected or manually specified):
vendor/bin/janus init
This generates config files for:
phpstan.neon).php-cs-fixer.dist.php)composer.jsonRun Checks: Execute static analysis and style checks:
vendor/bin/janus check
Or run individual tools:
vendor/bin/phpstan analyse
vendor/bin/php-cs-fixer fix
CI Integration:
Add to your GitHub Actions (.github/workflows/ci.yml):
- name: Run Janus
run: vendor/bin/janus check
janus.php (auto-generated) for package-specific rules.phpstan.neon for PHPStan exclusions/extensions (e.g., Doctrine, PHPUnit).composer.json for merged scripts (e.g., janus:check).Onboarding a New Developer:
Run vendor/bin/janus check locally to catch style issues early. The -v flag in PHPStan shows error identifiers, helping developers resolve issues faster.
Project Initialization:
janus init during project setup or when migrating to a new Laravel/Symfony version.--type=library or --type=symfony if needed.Daily Workflow:
.git/hooks/pre-commit or use a tool like husky:
vendor/bin/janus check --no-fix
vendor/bin/janus fix to auto-correct style issues.janus.php to add project-specific exclusions (e.g., for legacy code):
return [
'phpstan' => [
'exclude' => ['app/OldLegacyCode/**'],
],
];
CI/CD Pipeline:
janus check command as a quality gate:
jobs:
janus:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: composer install
- run: vendor/bin/janus check
Symfony/Laravel-Specific Workflows:
vendor/bin/janus doctrine:validate
Custom Composer Scripts:
Merge Janus scripts into your composer.json:
{
"scripts": {
"janus": "janus",
"lint": "janus check --no-fix",
"fix": "janus fix"
}
}
Run with:
composer janus
mix.scripts.push('vendor/bin/janus check --no-fix');
phpstan.neon as your IDE’s PHPStan config (File > Settings > PHP > Quality Tools > PHPStan).JANUS_PACKAGE_ROOT env var:
JANUS_PACKAGE_ROOT=packages/my-package vendor/bin/janus check
vendor/bin/phpstan analyse app/ --memory=1G
vendor/bin/phpstan analyse tests/ --memory=2G
Auto-Run Disabled by Default:
composer install (since v2.0.1). Enable with:
composer require --dev 21torr/janus --with-all-dependencies --no-scripts
vendor/bin/janus init --auto-run
composer.json:
"scripts": {
"post-install-cmd": "janus init --auto-run"
}
Symfony 8+ Path Issues:
config/bundles.php exists (Janus v2.1.0+ fixes this).--verbose to see resolved paths.False Positives:
missingType.iterableValue are globally disabled (v1.3.3+).phpstan.neon:
includes:
- vendor/21torr/janus/phpstan.neon
rules:
Doctrine\DBAL\Types\Type:
doctrine.columnType: false
Composer Plugin Conflicts:
humbug/box), ensure Janus runs last:
"scripts": {
"post-install-cmd": [
"@humbug/box",
"janus init --auto-run"
]
}
PHPStan v2 Migration:
vendor/bin/phpstan analyse --debug to compare v1/v2 outputs.Legacy Code:
Route::controller()).janus.php to exclude directories or suppress specific rules:
return [
'phpstan' => [
'exclude' => ['app/Http/Controllers/Old/**'],
'rules' => [
'Laravel\Rules\Deprecated' => false,
],
],
];
Verbose Output:
Use --verbose for detailed logs:
vendor/bin/janus check --verbose
Look for:
missingReturnType).Dry Runs: Test changes without modifying files:
vendor/bin/php-cs-fixer fix --dry-run
vendor/bin/phpstan analyse --no-progress
Isolated Testing: Run Janus on a single file/directory:
vendor/bin/janus check app/Models/User.php
CI Debugging: Cache Composer dependencies to avoid flaky CI runs:
- name: Cache Composer
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
Custom PHPStan Rules:
Add project-specific rules to phpstan.neon:
includes:
- vendor/21torr/janus/phpstan.neon
- phpstan-rules.neon
Example phpstan-rules.neon:
rules:
MyApp\Rules\CustomRule: true
PHP-CS-Fixer Customization:
Extend the default config in .php-cs-fixer.dist.php:
$finder = PhpCsFixer\Finder::create()
->in(__DIR__)
->exclude('vendor')
->exclude('storage')
->name('*.php')
->notName('*.blade.php'); // Add Blade exclusions
Doctrine Schema Validation: Validate schema in CI even if no migrations exist:
vendor/bin/janus doctrine:validate --no-migrations
Performance:
How can I help you explore Laravel packages today?