PHP K&R Formatter (
|
| Setting | Type | Default | Description |
|---|---|---|---|
phpFormater.engine |
string |
"builtin" |
Choose "builtin" (standalone TS engine) or "php-cs-fixer" |
phpFormater.alignAssignments |
boolean |
true |
Vertically align = assignment operators in consecutive lines |
phpFormater.collapseFunctionSignatures |
boolean |
true |
Collapse multi-line function parameter signatures into a single line |
phpFormater.indentSize |
number |
Auto | Number of spaces per indentation level (defaults to active editor tabSize) |
phpFormater.insertSpaces |
boolean |
Auto | Use spaces instead of tabs (defaults to active editor insertSpaces) |
phpFormater.phpCsFixerPath |
string |
"php-cs-fixer" |
Executable path for php-cs-fixer |
Code Examples
1. K&R Brace Style & Multi-line Function Collapsing
Before
<?php
function complexCalculator(
int $base,
int $multiplier,
bool $useBonus = false
): int
{
if ($useBonus)
{
return $base * $multiplier + 50;
}
else
{
return $base * $multiplier;
}
}
After (Shift + Alt + F)
<?php
function complexCalculator(int $base, int $multiplier, bool $useBonus = false): int {
if ($useBonus) {
return $base * $multiplier + 50;
} else {
return $base * $multiplier;
}
}
2. Vertical Assignment Alignment (=)
Before
$this->db = $db;
$this->logger = $logger;
$this->config = $config;
After (Shift + Alt + F)
$this->db = $db;
$this->logger = $logger;
$this->config = $config;
Usage
- Open any PHP file (
.php,.phtml, etc.). - Right-click inside the editor and select Format Document (
Shift + Alt + F/Option + Shift + F). - Or enable
editor.formatOnSave: truein VS Code settings to format on file save.
Development & Building with Yeoman (yo code)
If you want to develop, compile, or build this extension using the VS Code extension tooling ecosystem (yo code / vsce):
Install Prerequisites:
npm install -g yo generator-code @vscode/vsceCompile Source Code:
npm run compileWatch Mode (Auto-recompile on save):
npm run watchPackage Extension into VSIX:
vsce package
License
MIT License (c) 2026 Pirulug