Search by

mwx / coding-standard

metaworx

ECS preset for the metaworx code style, configuring the mwx/ecs-fixers fixers

0.12.0 2026-09-25 11:06 UTC

This package is auto-updated.

Last update: 2026-09-25 09:30:23 UTC


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 as vendor/bin/ecs-mwx (wherever the project's bin-dir is)
  • ecs.php — the default config, passed as --config; run directly (php …/ecs.php), the same runner
  • config/ecs/ — the preset: base rules, newline handling, control-structure braces, member reordering, and per-topic settings under config/ecs/settings/
  • src/Config/ComposedConfig.php — mwx\ECS\Config\ComposedConfig, which the preset's configs are composed with
  • src/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.