10up / phpcs-composer

Official 10up PHPCS rules.
MIT License
49 stars 8 forks source link

When using in package mode, phpcompatibility/php-compatibility version used is 9.3.5 #52

Open pabamato opened 10 months ago

pabamato commented 10 months ago

Describe the bug

If you clone the project and run composer install, it installsphpcompatibility/php-compatibility dev-develop which has the latest PHP sniffs. image

But when is installed via package in a project, is still usingphpcompatibility/php-compatibility 9.3.5: image

As a temp fix I added, the alias to my project: composer require --dev phpcompatibility/php-compatibility:"dev-develop as 9.99.99"

image

Steps to Reproduce

  1. #create composer project
    composer init

    create a file for testing

    testphpcs 2023-12-19 16-44-33

  2. # require latest phpcs-composer
    composer require --dev 10up/phpcs-composer:"^3.0"
  3. # show current insalled version
    composer show --tree phpcompatibility/php-compatibility
  4. # run phpcs in a very basic file -> no deprecation found for PHP 8.2
    ./vendor/bin/phpcs test_php_8_2.php  --standard="10up-Default"
  5. # require the develop branch of phpcompatibility/php-compatibility as an alias in your project
    composer require --dev phpcompatibility/php-compatibility:"dev-develop as 9.99.99"
  6. # show current insalled version
    # should be phpcompatibility/php-compatibility dev-develop
    composer show --tree phpcompatibility/php-compatibility
# run phpcs again -> should flag about utf8_encode()
./vendor/bin/phpcs test_php_8_2.php  --standard="10up-Default"
---------------------------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
---------------------------------------------------------------------------------------------------------------------------------------
 8 | WARNING | Function utf8_encode() is deprecated since PHP 8.2; Use mb_convert_encoding(), UConverter::transcode() or iconv instead
---------------------------------------------------------------------------------------------------------------------------------------

Screenshots, screen recording, code snippet

testphpcs 2023-12-19 16-55-03 testphpcs 2023-12-19 16-55-35

Environment information

No response

WordPress information

No response

Code of Conduct

darylldoyle commented 10 months ago

Thanks for flagging this @pabamato!

I've managed to replicate this issue, but can't seem to find a way to resolve it 🤔 Do you have any thoughts here? The other option is that we add the following to the installation instructions until v10 of PHPCompatibility and V3 of PHPCompatibilityWP are released, which would resolve this issue.

composer require --dev phpcompatibility/php-compatibility:"dev-develop as 9.99.99"
pabamato commented 9 months ago

Hi @darylldoyle, thanks for checking. I'm not sure we can resolve the issue without requiring the package at the project level. The proposed solution works for me.