A lightweight VS Code extension that formats PHP files using PHP-CS-Fixer. Zero dependencies, auto-discovers your config and executable.
- Formats PHP files on demand or on save
- Auto-discovers
vendor/bin/php-cs-fixeror falls back to global installation - Auto-discovers
.php-cs-fixer.phpor.php-cs-fixer.dist.phpconfig files - Multi-root workspace support
- Workspace Trust support for security
- Minimal footprint (~4 KB bundled)
- PHP-CS-Fixer installed locally or globally
- PHP available in your PATH
# Local installation (recommended)
composer require --dev friendsofphp/php-cs-fixer
# Global installation
composer global require friendsofphp/php-cs-fixer- Install this extension from the VS Code Marketplace
- Install PHP-CS-Fixer via Composer
- Create a
.php-cs-fixer.phpconfig file in your project root - Set this extension as your default PHP formatter:
{
"[php]": {
"editor.defaultFormatter": "muuvmuuv.vscode-just-php-cs-fixer",
"editor.formatOnSave": true
}
}| Setting | Default | Description |
|---|---|---|
php-cs-fixer.executable |
Auto-detect | Path to PHP-CS-Fixer executable |
php-cs-fixer.config |
Auto-detect | Path to config file |
php-cs-fixer.allow-risky |
false |
Allow risky rules |
{
"php-cs-fixer.executable": "vendor/bin/php-cs-fixer",
"php-cs-fixer.config": ".php-cs-fixer.php",
"php-cs-fixer.allow-risky": true,
"[php]": {
"editor.defaultFormatter": "muuvmuuv.vscode-just-php-cs-fixer",
"editor.formatOnSave": true
}
}Create a .php-cs-fixer.php file in your project root:
<?php
$finder = PhpCsFixer\Finder::create()
->in(__DIR__)
->exclude('vendor');
return (new PhpCsFixer\Config())
->setRules([
'@PSR12' => true,
'@Symfony' => true,
])
->setFinder($finder);Other PHP formatting extensions tend to be complex, bundle PHP-CS-Fixer themselves, or include HTML formatting that conflicts with PHP-CS-Fixer. This extension:
- Does one thing well - runs PHP-CS-Fixer
- Has zero runtime dependencies
- Uses your PHP-CS-Fixer installation and config
- Works seamlessly with other extensions like Intelephense
- Open the Output panel (
View > Output) - Select "PHP-CS-Fixer" from the dropdown
- Check the logs for errors
| Issue | Solution |
|---|---|
| Executable not found | Install via composer require --dev friendsofphp/php-cs-fixer or set php-cs-fixer.executable |
| Config not found | Create .php-cs-fixer.php in project root or set php-cs-fixer.config |
| Untrusted workspace | Grant workspace trust or configure settings at user level |
# Install dependencies
npm install
# Build
npm run compile
# Watch mode
npm run dev
# Run tests
npm test
# Package
npm run packageThe PHP-CS-Fixer logo is © Fabien Potencier
