PHP CS Fixer

A tool to automatically fix PHP coding standards issues.

Version

2.14.0

Runtime

PHP Versions

Supported Languages

PHP

Official Documentation

http://cs.sensiolabs.org/

YAML Configuration

phpcsfixer:

  • input:

    Patterns to include in execution and reports.

  • ignore:

    Patterns to exclude from execution and reports.

  • auto-fix:

    true/false

    Note If no rules are specified, PHP-CS-Fixer will use PSR-1 and PSR-2 which has the line_ending rule to use LF as EOL characters.

    This means PHP-CS-Fixer does not keep CRLF line endings and all EOL characters are converted to LF in files where the auto-fix is applied in such cases. So if this behavior does not suit your project, you can specify the EOL characters via setLineEnding in PhpCsFixer\ConfigInterface.

  • config-file:

    Alias of --config option.

  • machine:

    • cpu:

      Amount of CPU. The default machine has 0.25 CPU with 960 MiB RAM.

      Inspecode automatically specifies -d memory_limit=<limit> to PHP-CS-Fixer in order to configure the maximum amount of memory that PHP-CS-Fixer is allowed to allocate according to this value. Inspecode reserves 240 MiB RAM for system, and makes the rest of RAM available to PHP-CS-Fixer for memory allocation. For example, -d memory_limit=720M is specified by default (for 0.25 CPU), -d memory_limit=5520M is specified for 1.5 CPU.

  • options:

    Below is the list of options that are supported:

      --path-mode=PATH-MODE          Specify path mode (can be override or intersection). [default: "override"]
      --allow-risky=ALLOW-RISKY      Are risky fixers allowed (can be yes or no).
      --config=CONFIG                The path to a .php_cs file.
      --rules=RULES                  The rules.
    
  • thresholds:

    • num-issues:

      No tool specific severity levels are available.

  • experimental:

    • incremental:

      true/false

      Note: The incremental analysis is disabled if any kinds of configuration files are changed. The files recognized as configuration files are as follows:

      • Configuration files:
        • Files specified in config-file field
        • Files specified to --config option
        • If none of the above configuration files are found:
          • **/.php_cs.dist, **/.php_cs

YAML Examples

  • With default options:

    inspecode:
      phpcsfixer: default
    
  • With enabling auto-fixing and default options:

    inspecode:
      phpcsfixer: auto-fix
    
  • With custom machine:

    inspecode:
      phpcsfixer:
        machine:
          cpu: 1.5 # 1.5 CPU, 5760 MiB RAM
    
  • With a configuration file:

    inspecode:
      phpcsfixer:
        config-file: ./.php_cs
    

    The above configuration is equivalent to:

    inspecode:
      phpcsfixer:
        options:
          --config: ./.php_cs
    

Configuration File Detection

If no configuration files are specified via config-file field, Inspecode walks the file tree in lexical order in your repository to find a configuration file, named .php_cs or .php_cs.dist, and specifies the file first found to RuboCop automatically via --config option.

Note: Inspecode ignores specific configuration files while searching. See Configuration > Tool Configuration > Field: config-file for detail.

If the configuration file detected by Inspecode is not the one you want to use or you do not want to use any configuration files, you can disable Inspecode from detecting configuration files by explicitly setting an empty string to config-file field like below:

inspecode:
  phpcsfixer:
    config-file: ""

results matching ""

    No results matching ""