mwx / coding-standard
ECS preset for the metaworx code style, configuring the mwx/ecs-fixers fixers
Package info
gitlab.com/metaworx/open-source/php-library/coding-standard
pkg:composer/mwx/coding-standard
Requires
- php: ^8.2
- mwx/ecs-fixers: ^0.10
- symplify/easy-coding-standard: ^13.0
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
The metaworx PHP coding standard as a distributable ECS preset,
built on the custom fixers from mwx/ecs-fixers.
Contents
bin/ecs-mwx— the runner, installed asvendor/bin/ecs-mwx(wherever the project'sbin-diris)ecs.php— the default config, passed as--config; run directly (php …/ecs.php), the same runnerconfig/ecs/— the preset: base rules, newline handling, control-structure braces, member reordering, and per-topic settings underconfig/ecs/settings/src/Config/ComposedConfig.php—mwx\ECS\Config\ComposedConfig, which the preset's configs are composed withsrc/Runner/EcsBinary.php—mwx\ECS\Runner\EcsBinary, which finds the project's autoloader and ECS through Composer
Usage
config/ecs/base.php resolves paths from the consuming project's working
directory (src/, tests/ and packages/ when present;
fixture and spec case trees are skipped),
and explicit paths on the ecs command line override them:
vendor/bin/ecs check [paths...] --fix --config vendor/mwx/coding-standard/config/ecs/default.php
Put the paths first.
ECS 13 gives a path that follows an option without a value - --fix,
--clear-cache, --no-progress-bar and the like - to that option,
which then reads as off,
and falls back to the config's paths: the whole project.
The preset recovers such a path and says so on STDERR,
though the option that took it stays off;
where only some paths were taken it refuses the run,
since it cannot add them back.
Any other config checks the whole project,
and with --fix given earlier on the line, fixes it.
The custom fixers are autoloaded through the consuming project's composer
autoloader (mwx/ecs-fixers is a dependency of this package).
The runner
vendor/bin/ecs-mwx runs ECS with the preset:
vendor/bin/ecs-mwx check [paths...] [--fix] [--reorder]
Without --config, and without an ecs.php in the working directory,
it uses config/ecs/default.php.
--reorder also orders class members
(config/ecs/settings/reorder_class_members.php),
as ECS_REORDER=1 does for any ECS command using the default config.
It finds ECS through Composer:
the autoloader Composer's proxy names,
or, run as php …/ecs.php, the one in the vendor directory of the nearest
composer.json - COMPOSER_VENDOR_DIR and config.vendor-dir honoured.
Composing your own config
A config of your own can take the preset's parts and add to them.
ComposedConfig applies each part in order to the same ECSConfig:
the preset's files, which return ECSConfig::configure() builders,
and builders or other composed configs of your own.
ECS accepts it without the deprecation warning its
function (ECSConfig $ecsConfig): void form prints:
<?php
use mwx\ECS\Config\ComposedConfig;
use Symplify\EasyCodingStandard\Config\ECSConfig;
$preset = __DIR__ . '/vendor/mwx/coding-standard/config/ecs';
return ComposedConfig::fromFiles(
$preset . '/base.php',
$preset . '/settings/standard_rules.php',
)
->with( ECSConfig::configure()->withSkip( [ '*/legacy/*' ] ) )
->withIf( (bool) getenv( 'ECS_REORDER' ), $preset . '/settings/reorder_class_members.php' );
The builders cannot be merged into one -
withRules() replaces the rule list rather than adding to it -
which is why the parts are applied in turn instead.
Install
composer require --dev mwx/coding-standard
MIT license.