Problem with php-cs-fixer after upgrade php to version 8
Asked Answered
L

4

8

After upgrade to php8 I have a problem with php-cs-fixer which I installed globally via composer. Right now I can not use php-cs-fixer because every time I get:

PHP needs to be a minimum version of PHP 5.6.0 and maximum version of PHP 7.4.*.
To ignore this requirement please set `PHP_CS_FIXER_IGNORE_ENV`.

For php upgrade and usage different version of php I use https://github.com/shivammathur/homebrew-php

For previous version of php (7.4) everything works fine.

Lentissimo answered 15/1, 2021 at 15:2 Comment(2)
PHP 8 has been out for less than two months; it's going to take a while for all the tools you use to be ready for it!Purveyor
I got a similar issue today because current version of cs fixer (3.14.4) does not support php above 8.1 (for a good reason actually github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/6787 ) but using PHP_CS_FIXER_IGNORE_ENV works (I guess it would fail if you use it on a file with specific 8.2 syntax)Prizefight
L
8

The first version of php-cs-fixer to support PHP 8 was Version 2.18 released on 18th Jan 2021.

Lentissimo answered 18/1, 2021 at 17:34 Comment(0)
P
6

https://cs.symfony.com/doc/usage.html#environment-options

PHP_CS_FIXER_IGNORE_ENV=1 php php-cs-fixer.phar fix /path/to/dir

Puncheon answered 16/11, 2022 at 9:48 Comment(0)
E
0

The PHP_CS_FIXER_IGNORE_ENV environment variable can be used to ignore any environment requirements. This includes requirements like missing PHP extensions, unsupported PHP versions or by using HHVM.

NOTE: Execution may be unstable when used.

PHP_CS_FIXER_IGNORE_ENV=1 php php-cs-fixer.phar fix /path/to/dir

Exit code of the fix command is built using following bit flags:

0 - OK.

1 - General error (or PHP minimal requirement not matched).

4 - Some files have invalid syntax (only in dry-run mode).

8 - Some files need fixing (only in dry-run mode).

16 - Configuration error of the application.

32 - Configuration error of a Fixer.

64 - Exception raised within the application.

Ethelyn answered 2/8, 2023 at 7:59 Comment(0)
U
-3

In the file: ./vendor/bin/php-cs-fixer

Remove the code below (starting at line 26):

elseif (!defined('PHP_VERSION_ID') || \PHP_VERSION_ID < 50600 || \PHP_VERSION_ID >= 70500) {
    fwrite(STDERR, "PHP needs to be a minimum version of PHP 5.6.0 and maximum version of PHP 7.4.*.\n");

    if (getenv('PHP_CS_FIXER_IGNORE_ENV')) {
        fwrite(STDERR, "Ignoring environment requirements because `PHP_CS_FIXER_IGNORE_ENV` is set. Execution may be unstable.\n");
    } else {
        exit(1);
    }
}

It's a quick fix, but it will get you back up and running.

Unessential answered 18/1, 2021 at 15:53 Comment(1)
Ok but I would like to set this environment. Version 2.18 solve my problemsLentissimo

© 2022 - 2024 — McMap. All rights reserved.