DressCode Backward Compatibility
A minor version of DressCode may add a new decision to a standard, and fix will then change code it
used to leave alone. A new version never overrides a value you set in your configuration, though, and tools that read the output,
as well as your own rules, get similar guarantees.
Standards and Sets
A minor version may add a decision to a standard or a set, and it does so on purpose: a standard describes a style, not a list of rules frozen on the day you installed it. When DressCode learns to check another part of the style a standard prescribes, you get it with the update.
If you want to keep these changes under control, there are two ways. Lock the version of DressCode in
composer.lock and update deliberately, reviewing the diff the update brings. Or set the decision you don't like to
keep in your configuration; a value from the configuration takes precedence over every preset, even one that gains
the decision only in a new version. What you write in your configuration does not change unless you change it.
The output of dresscode config shows
where every value came from.
Output for Tools
The json output has a version key. It goes up only when a key disappears, is renamed or changes its
meaning. New keys may be added in minor versions, so a tool that reads the document should ignore keys it does not know. The text
of violation messages may change to become clearer or more precise; a tool that acts on violations should read the decision path
in the decision key, not the message.
The lines format keeps its grammar, one line per finding in the form
path:line:column: severity: message [decision], so a matcher you set up in your editor following the guide keeps working after an update.
The agent format is written for a model, and its wording may change to whatever helps the agent; its meaning does
not: a clean file stays silent, a rewrite is reported only for a written file, and the line numbers refer to the file as it is on
disk now.
Public API
A rule, a plugin and a program that embeds DressCode can rely on these classes between minor versions:
- writing a rule:
Rulewith its subclassesNodeRuleandGapRule,RuleInfo,RuleContext,Claim,Space,Line,Gap,LineSplits,StylewithImportStyle(the shape of imports),Violationand the enumsStage,Severity,Tristate,RiskandDecisionKind; - decisions:
Decision,Domainwith the domains inDomains\(Words,Shapes,Count,Flag,Names,Text,GrammarEntry,Map), the valuesValuesandValuewith the layer that set the value (Config\Layer,Config\LayerKind), and the catalogueConfig\Catalogue; - configuration:
Config,Profile,Override,PluginandPluginManifest; presets are NEON files and their names; - rule helpers:
GlobalCalls(which global function a call calls),CodeWriter(code written in the style the file uses),QualifiedNames(the two halves of a fully qualified name) and the grammar of the maps inUpgrading\(MemberMap,MemberMapGrammar,MemberMapEntry,MemberPattern,MemberMapMatch,ArgumentPattern,ArgumentPatternItem,ArgumentBindings,FunctionPattern); the built-in rules inRules\only by the name and namespace of their class, so that you can name them in the configuration; their methods are not public; - analyses and testing: everything in
Analyses\exceptRegistry,PhpStan,Declarations,PhpSymbolsDataandPhpSignaturesData, plusTesting\RuleTesterandTesting\UpgradingTestertogether with their exceptionTesting\TestFailure, and the file resultFileResultthatUpgradingTester::runSample()returns; - command line:
Console\Applicationfor a program that wants to embed a run (see DressCode Inside Your Own Tool); - exceptions:
ConfigurationException,RuleException,ConvergenceException; - from the library PhpSyntax, everything not marked
@internal:Parser,Lexer,Printer,Node,Token,Trivia, the nodes, the analyses,Style,Indentation, the enums andParseException.
Anything marked @internal can change at any time: the engine, loading and resolving the configuration, the rest of
the command line, the output formats, and the helpers that the built-in rules share only among themselves. So a program that wants
to run DressCode calls it through the command line or through Console\Application. A test guards both lists, so a
class that is in neither of them fails the test suite instead of becoming public API by accident.
Some public classes are created only by the engine: a rule reads FileResult, ImportStyle,
LineSplits or MemberMapMatch but does not create them, so their constructor is
@internal.
For everything that is public:
- Parameter names are a contract. Methods may be called with named arguments, so a parameter is never renamed in a minor version.
- A public enum may gain a case.
SeverityorRiskmay get a new value in a minor version. Amatchover them in a rule or a plugin therefore needs adefaultarm. - New node classes. The PhpSyntax tree may get a new node for new PHP syntax in a minor version, so a
matchover node classes needs adefaulttoo. - The order of rules is not guaranteed. Rules run in the order they were registered, but that may change in a minor version; a rule must not rely on another rule running before it or after it. Rules pass information to each other only through a decision, the style of the run or an analysis of the file (see A Rule in Detail).