Download the PHP package stolt/coding-standard-migrator without Composer

On this page you can find all versions of the php package stolt/coding-standard-migrator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package coding-standard-migrator

Coding Standard Migrator

Test Status Version Downloads PHP Version PDS Skeleton Lean dist package

A CLI tool and library which migrates a PHP coding-standard configuration to another coding standard. Mago is the migration target, the supported sources are PHP-CS-Fixer, PHP_CodeSniffer, and Pint.

Migration path Source configuration
php-cs-fixer → mago .php-cs-fixer.php, .php-cs-fixer.dist.php, .php_cs, .php_cs.dist
phpcs → mago phpcs.xml, phpcs.xml.dist, .phpcs.xml, .phpcs.xml.dist, ruleset.xml
pint → mago pint.json, .pint.json

Since the coding standards do not overlap one to one, a migration is a starting point and not a finished configuration. Every migration therefore comes with a report which states what was translated, what the target standard does implicitly, and which rules need a manual decision.

Why Coding Standard Migrator?

Moving from PHP-CS-Fixer, PHP_CodeSniffer, or Pint to Mago is not just a configuration-file rename.

Different tools expose different rule sets and semantics.

Coding Standard Migrator makes that migration explicit:

  1. analyze what can be migrated
  2. identify gaps
  3. generate a Mago configuration
  4. review the migration report
  5. verify the result with Mago

What the Coding Standard Migrator does not do

The Coding Standard Migrator does not guarantee behavioural equivalence.

It translates configuration where a known Mago equivalent exists and explicitly reports mappings that require a manual review.

Installation

Usage

See how much of the configuration of the current directory a migration would carry over before running one:

Mappable is the sum of Equivalent and Partial, the rules which end up in the migrated configuration. The other three rule counts each name a reason why a rule does not: Unsupported and No mapping known need a manual decision, Disabled in source never asked for anything. Linter candidates and Redundant with Mago are cross sections of the same rules, the ones which need a [linter.rules] entry, and the ones the Mago formatter applies anyway.

The migration confidence is the share of the source configuration which survives, with a partial mapping counting half and a rule the target standard covers anyway or which was disabled to begin with counting fully. Add --verbose to list the rules which need a manual decision, or --fail-under 80 to turn the confidence into a CI gate.

Migrate the PHP-CS-Fixer configuration of the current directory to a mago.toml:

Migrate a PHP_CodeSniffer ruleset or a Pint configuration instead:

Preview the migration without writing anything:

Options of the migrate command

Option Description
--from The coding standard to migrate from, defaults to php-cs-fixer
--to The coding standard to migrate to, defaults to mago
--working-dir, -d The directory to run in, defaults to the current one
--config, -c The source configuration file, autodetected when omitted
--target, -t The file to write to, defaults to the target standard's default
--php-version The PHP version to pin in the migrated configuration
--path, -p A path the coding standard applies to, repeatable
--dry-run Shows the migrated configuration instead of writing it
--force, -f Overwrites an existing target configuration
--fail-on-unmapped Exits non-zero when a rule could not be migrated, made for CI

Options of the analyze command

Option Description
--from The coding standard to analyze, defaults to php-cs-fixer
--to The coding standard to analyze the migration to, defaults to mago
--working-dir, -d The directory to run in, defaults to the current one
--config, -c The configuration file to analyze, autodetected when omitted
--fail-under Exits non-zero below this migration confidence, made for CI

The command is also reachable as analyse. The supported standards and migration paths are listed by the standards command.

Usage via cpx

If you don't want to add coding-standard-migrator as a development dependency, you can run it directly with cpx.

Install cpx globally:

Then run the migrator directly from your project:

To migrate your PHP-CS-Fixer configuration to Mago:

You can pass the same options as with the locally installed binary:

cpx keeps the package isolated from your project's Composer dependencies, so you can use coding-standard-migrator without adding it to composer.json. It also caches the package between runs, making later invocations faster.

Tip: If coding-standard-migrator is already installed in your project, cpx can use the project's local binary first. This makes cpx stolt/coding-standard-migrator ... convenient both for projects that have the tool installed and for one-off migrations.

Usage as a library

How a migration works

  1. A ConfigurationReader turns the configuration file of the source standard into a tool-agnostic SourceConfiguration, holding a Ruleset plus the settings which live outside of the rules, such as the indent and the line ending.
  2. A RuleMapper translates every Rule into a Mapping and collects them in a MappingReport. Each mapping carries one of these outcomes:

    Outcome Meaning
    linter rule The rule became one or more rules of the target linter
    formatter option The rule became one or more options of the target formatter
    covered by formatter The target formatter does this anyway, no configuration needed
    skipped The rule was disabled in the source and needed no translation
    unsupported The target standard knowingly has no equivalent
    unknown No mapping is known, the rule needs a manual decision

    A translated mapping additionally carries a MappingFidelity, either equivalent or partial. Mapping tables state their caveats as notes, which makes a note the default signal for a partial mapping, overridable per mapping.

  3. A ConfigurationWriter renders the report as the configuration file of the target standard. Rules which need attention are added as comments to the generated file. MigrationAnalysis instead reduces the report to the counts the analyze command shows, which is why analyzing never touches a writer.

Mappings are only added to a RuleTable once they are verified against the Mago formatter reference and the Mago linter rules. Everything else stays unknown, so a migration never invents a setting which does not exist.

Rule sets are shared ground between the standards: a @PSR12 rule of PHP-CS-Fixer, a <rule ref="PSR12"/> of PHP_CodeSniffer, and a "preset": "psr12" of Pint all end up as the same rule-set entry, which the tables map onto a Mago formatter preset.

There are two rule vocabularies and therefore two tables:

Supporting another coding standard

Adding one means adding implementations, not changing the engine:

Register them in Standard\StandardRegistry and the migrate command picks up the new migration path.

Known limitations

Contributing

If you're considering contributing to this library, have a look at this repository's CONTRIBUTING.md for more advice.

License

This package is licensed under the MIT license, see LICENSE.md.


All versions of coding-standard-migrator with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
ext-json Version *
ext-libxml Version *
ext-simplexml Version *
symfony/console Version ^6.4 || ^7.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package stolt/coding-standard-migrator contains the following files

Loading the files please wait ...