inspirecz / dresscode-standard
INSPIRE coding standard for DressCode: presets translated from inspirecz/coding-standard and the Inspire sniffs ported as DressCode rules.
Package info
github.com/InspireCZ/dresscode-standard
Type:dresscode-plugin
pkg:composer/inspirecz/dresscode-standard
Requires
- php: 8.4 - 8.6
- dresscode/dresscode: ^1.5@dev
- nette/neon: ^4.0
- nette/utils: ^4.1
Requires (Dev)
- nette/tester: ^2.6
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-19 11:52:22 UTC
README
The INSPIRE CZ coding standard as a DressCode plugin: the decisions of
inspirecz/coding-standard (PHP_CodeSniffer + Slevomat) translated to DressCode presets, and the Inspire.*
sniffs ported as DressCode rules. The aim is to replace PHP_CodeSniffer on projects running PHP 8.4 and newer.
Installation
composer require --dev inspirecz/dresscode-standard
The PHPStan extensions phpstan.neon of the project includes have to be installed next to DressCode, otherwise
DressCode cannot start PHPStan with the configuration of the project and works without types.
Configuration
dresscode.neon in the root of the project:
typeAnalysis: phpstan use: - Inspire\DressCode\Plugin - inspire/standard - deprecations - correctness paths: - app - test - admin excludePaths: - app/tmp - admin/tmp overrides: - paths: [admin/**] use: [inspire/admin]
For the types of the administration modules, phpstan.neon of the project must scan the NW7 admin classes,
which are not in the Composer autoload:
parameters: scanDirectories: - vendor/inspire/nw7-admin/backend - vendor/inspire/nw7-admin/framework
Presets
| Preset | Replaces | Use |
|---|---|---|
inspire/standard |
ruleset.strict.xml (over ruleset.xml) |
app/, test/ |
inspire/admin |
ruleset.nw6.xml, as a set over inspire/standard |
override for admin/ |
Rules
| Decision | Replaces |
|---|---|
inspire.blankLineBefore.controlStructure |
Inspire.ControlStructures.BlankLines |
inspire.blankLineBefore.return |
Inspire.Methods.BlankLinesBeforeReturn |
inspire.tracyDump |
Inspire.Methods.DisallowTracyDumpMethods |
inspire.emptyInterface |
Inspire.Classes.EmptyInterface |
inspire.inlineCommentSpacing |
Inspire.ControlStructures.InlineCommentSpacing, beyond spacing.comment.marker |
inspire.emptyInlineComment |
the same sniff on an empty //, for admin/ where comments.empty is kept |
inspire.emptyConstruct |
SlevomatCodingStandard.ControlStructures.DisallowEmpty |
inspire.unusedVariable |
SlevomatCodingStandard.Variables.UnusedVariable |
inspire.unusedVariableIgnoresForeachValues |
its ignoreUnusedValuesWhenOnlyKeysAreUsedInForeach |
inspire.unusedClosureUse |
SlevomatCodingStandard.Functions.UnusedInheritedVariablePassedToClosure |
inspire.methodOrder |
static constructors and abstract methods of SlevomatCodingStandard.Classes.ClassStructure |
inspire.namespaceDeclaration |
SlevomatCodingStandard.Namespaces.NamespaceDeclaration |
inspire.duplicateSpaces |
SlevomatCodingStandard.Whitespaces.DuplicateSpaces |
inspire.strictTypesFormat |
declare(strict_types = 1) of SlevomatCodingStandard.TypeHints.DeclareStrictTypes |
inspire.declarationTrailingComma |
SlevomatCodingStandard.Functions.RequireTrailingCommaInDeclaration, beyond multiline.trailingComma.parameter |
inspire.yodaConstant |
SlevomatCodingStandard.ControlStructures.RequireYodaComparison, beyond expressions.comparison.yoda |
inspire.inlineDocVar |
SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration, for admin/ |
inspire.unconditionalIf |
Generic.CodeAnalysis.UnconditionalIfStatement |
inspire.jumbledIncrementer |
Generic.CodeAnalysis.JumbledIncrementer |
inspire.forAsWhile |
Generic.CodeAnalysis.ForLoopShouldBeWhileLoop |
inspire.emptyStatement, inspire.emptyCatch |
Generic.CodeAnalysis.EmptyStatement, its catch for admin/ only |
inspire.nestingLevel, inspire.maxNestingLevel |
Generic.Metrics.NestingLevel |
inspire.inlineHtml |
Generic.Files.InlineHTML |
inspire.characterBeforeOpeningTag |
Generic.PHP.CharacterBeforePHPOpeningTag |
inspire.alternativePhpTags |
Generic.PHP.DisallowAlternativePHPTags |
inspire.mergeConflict |
Generic.VersionControl.GitMergeConflict |
inspire.oldStyleConstructor |
Generic.NamingConventions.ConstructorName |
inspire.defineUpperCase |
define() of Generic.NamingConventions.UpperCaseConstantName |
inspire.tabs |
Generic.WhiteSpace.DisallowTabIndent, beyond indentation.unit |
inspire.methodUnderscore, inspire.propertyUnderscore |
the Underscore checks of PSR2.Methods.MethodDeclaration and PSR2.Classes.PropertyDeclaration |
inspire.emptyCatchComment |
Squiz.Commenting.EmptyCatchComment |
inspire.returnAnnotationWithoutReturn |
InvalidNoReturn of Squiz.Commenting.FunctionComment |
inspire.incrementDecrement |
Squiz.Operators.IncrementDecrementUsage |
inspire.eval |
Squiz.PHP.Eval |
inspire.unreachableCode |
Squiz.PHP.NonExecutableCode, for admin/ |
The test files of the sniffs (PHP_CodeSniffer 4.0.4, Slevomat 8.31.1) are the fixtures of the rules, with the violations the sniffs report there; a test file PHP cannot parse is cut before the code it cannot. They are used under the licenses of PHP_CodeSniffer and Slevomat, in tests/fixtures/LICENSE.md. The rules fixing whitespace and layout fix what they report, the others only report it, as most of the sniffs do.
The other sniffs of the rulesets map to decisions of DressCode itself, which the presets set: among them
braces.position.class and function for PEAR.Classes.ClassDeclaration and PEAR.Functions.FunctionDeclaration,
spacing.cast for Generic.Formatting.SpaceAfterCast, spacing.ternary for Squiz.WhiteSpace.OperatorSpacing,
hygiene.classNameNotation.object for SlevomatCodingStandard.Classes.ModernClassNameReference,
blankLines.afterDeclare and beforeNamespace for SlevomatCodingStandard.TypeHints.DeclareStrictTypes, and
functions.trailingBareReturn for the ReturnNotRequired check of Squiz.PHP.NonExecutableCode in admin/.
Where it differs from PHP_CodeSniffer
Fixed by DressCode and then checked by PHP_CodeSniffer, vendor/inspire of a project (about 1 700 files) leaves only:
-
A comment on a line of its own above
} else {and} elseif (...) {: DressCode indents it as the}, taking it for the comment of the next branch, PHP_CodeSniffer as the statements above it. Neither tool can be told otherwise, so such a comment goes inside the branch it is about:if ($x) { $result = 'yes'; // otherwise we say no <- PHP_CodeSniffer wants it here, DressCode moves it four spaces left } else { // otherwise we say no <- both take it here $result = 'no'; }
-
A line holding a
caseand its statement,case 1: return;, indented with tabs: DressCode leaves it as it is.
DressCode reports beyond PHP_CodeSniffer: whitespace at the end of a line (file.trailingWhitespace, which it removes;
a string keeps its own), \dump() with a leading backslash, which Inspire.Methods.DisallowTracyDumpMethods
does not see in PHP_CodeSniffer 4, an annotation in a plain comment anywhere (phpdoc.annotation.plainComment), and what
its presets of deprecations and upgrades find.
Generic.Classes.DuplicateClassName compares the files of a run with each other, which a rule of DressCode cannot;
Composer warns about two classes of one name when it builds the autoloader.
Moving from PHP_CodeSniffer
-
DressCode reads
phpcs:ignore,phpcs:disableandphpcs:enablecomments, but translates only the sniffs it knows itself, and a plugin cannot add its own.inspire-dresscode-suppressionsadds the decisions of this plugin to such a comment,// phpcs:ignore Inspire.Methods.DisallowTracyDumpMethodsbecoming// phpcs:ignore Inspire.Methods.DisallowTracyDumpMethods, inspire.tracyDump, which both tools follow, a name they do not know meaning nothing to them. Run it from the root of the project, where it takespathsandexcludePathsofdresscode.neon;--dry-runonly lists the files, and any paths given replace those of the configuration:php vendor/bin/inspire-dresscode-suppressionsOnce PHP_CodeSniffer is gone,
dresscode migrate suppressionsrewrites the comments to thedresscode:form andinspire-dresscode-suppressions --finishdrops the names of the sniffs from them, leaving the decisions. -
A path of
overridesmatches a directory of that name anywhere, sopaths: [admin]also takessrc/admin/of a package; name the directories of the project where it has such ones. -
DressCode reports a file PHP cannot parse (
$string{0}) as a syntax error, where PHP_CodeSniffer checks it anyway.
Tests
composer install
composer tester