Getting started
1. Analyze
From your project root (the directory holding composer.json):
custos analysecustos checks the whole project, minus the default excludes, against your target PHP version, usually taken from composer.json. Each finding gives its position, severity, message and rule ID, and says when a quick-fix is available:
src/Invoice.php:3:5: warning: Variable $total is used only once; inline its value. [OneTimeUseVariables] (fixable)
src/Invoice.php:6:7: info: Stray semicolon; remove it. [UnnecessarySemicolon] (fixable)
src/Invoice.php:7:6: error: Restrict the classes unserialize() may create via its second argument. [UnserializeExploits]
1 file(s) analyzed: 1 error(s), 1 warning(s), 1 infoThe command fails when a finding is a warning or worse; --fail-on changes the threshold (see exit codes).
Want to know more about a rule? Run custos explain OneTimeUseVariables, or open its page in the rule reference.
2. Fix
Preview the quick-fixes as a diff, then apply them:
custos fix --dry-run --diff src
custos fix src--- a/src/Invoice.php
+++ b/src/Invoice.php
@@ -1,6 +1,5 @@
<?php
function total($a) {
- $total = $a + 1;
- return $total;
+ return $a + 1;
}
-foo();;
+foo();Fix one rule at a time if you want small, reviewable commits:
custos fix --rule UnnecessarySemicolon src3. Format
Lay out the code following a style preset (PER by default, or the style of your Pint, PHP-CS-Fixer or Mago configuration):
custos format --check
custos formatSee Formatting.
4. Configure
Create a custos.json at the project root to pin the PHP version, choose paths, and turn rules on or off:
{
"php": "8.3",
"paths": ["src", "tests"],
"rules": {
"StaticClosureCanBeUsed": { "enabled": false }
}
}See Configuration.
5. Adopt on legacy code
On an existing code base, record the current findings in a baseline so that only new ones are reported:
custos analyse --generate-baseline custos-baseline.json