Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

php is always marked as unused requirement #79

Closed
JoshuaBehrens opened this issue May 16, 2020 · 8 comments
Closed

php is always marked as unused requirement #79

JoshuaBehrens opened this issue May 16, 2020 · 8 comments

Comments

@JoshuaBehrens
Copy link
Contributor

JoshuaBehrens commented May 16, 2020

Describe the bug

A composer.json with a php version constraint gets as output that the php requirement is unused and should be discarded. There is a psr 4 valid class in the src folder that uses a core function. That should count to require any php version.

Error dump

composer.json

{
    "name": "foo/bar",
    "description": "foobar",
    "type": "library",
    "minimum-stability": "stable",
    "require": {
        "php": ">=7.4 <7.5"
    },
    "autoload": {
        "psr-4": {
            "Foo\\Bar\\": "src/"
        }
    },
    "require-dev": {
        "phpunit/phpunit": ">=9.1 <10",
        "phpstan/phpstan": ">=0.12 <0.13",
        "phpstan/extension-installer": ">=1 <2",
        "phpstan/phpstan-phpunit": ">=0.12 <0.13",
        "phpstan/phpstan-deprecation-rules": ">=0.12 <0.13",
        "phpstan/phpstan-strict-rules": ">=0.12 <0.13",
        "psalm/plugin-phpunit": ">=0.10 <0.11",
        "vimeo/psalm": ">=3 <4",
        "infection/infection": ">=0.15 <0.16",
        "friendsofphp/php-cs-fixer": ">=2 <3",
        "icanhazstring/composer-unused": ">=0.7 <0.8"
    },
    "autoload-dev": {
        "psr-4": {
            "Foo\\Bar\\Test\\": "test/"
        }
    }
}

Command

composer unused -vvv

Plugin command unused (Icanhazstring\Composer\Unused\Command\UnusedCommand) would override a Composer command and has been skipped
Running 1.10.6 (2020-05-06 10:28:10) with PHP 7.4.6 on Darwin / 19.3.0
You are running composer with Xdebug enabled. This has a major impact on runtime performance. See https://getcomposer.org/xdebug

Loading packages
----------------

 1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100% < 1 sec/< 1 sec 12.0 MiB

Scanning files from basedir /Users/joshuabehrens/tmp/foo-bar-base
--------------------------------------------------------------------------------

 2/2 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100% < 1 sec/< 1 sec 14.0 MiB

Results
-------

Found 0 used, 1 unused and 0 ignored packages

 Used packages

 Unused packages
 ✗ php

 Ignored packages                                                                                                                                                                                                         

Log

{"time":"2020-05-16T15:24:01.074944+00:00","level":"info","message":"version","context":{"value":"0.7.0"}}
{"time":"2020-05-16T15:24:01.075084+00:00","level":"info","message":"requires","context":{"php":">=7.4 <7.5"}}
{"time":"2020-05-16T15:24:01.075108+00:00","level":"info","message":"dev-requires","context":{"phpunit\/phpunit":">=9.1 <10","phpstan\/phpstan":">=0.12 <0.13","phpstan\/extension-installer":">=1 <2","phpstan\/phpstan-phpunit":">=0.12 <0.13","phpstan\/phpstan-deprecation-rules":">=0.12 <0.13","phpstan\/phpstan-strict-rules":">=0.12 <0.13","psalm\/plugin-phpunit":">=0.10 <0.11","vimeo\/psalm":">=3 <4","infection\/infection":">=0.15 <0.16","friendsofphp\/php-cs-fixer":">=2 <3","icanhazstring\/composer-unused":">=0.7 <0.8"}}
{"time":"2020-05-16T15:24:01.075122+00:00","level":"info","message":"autoload","context":{"psr-4":{"Foo\\Bar\\":"src\/"}}}
{"time":"2020-05-16T15:24:01.075132+00:00","level":"info","message":"dev-autoload","context":{"psr-4":{"Foo\\Bar\\Test\\":"test\/"}}}
{"time":"2020-05-16T15:24:01.158628+00:00","level":"debug","message":"Parsing file \/Users\/joshuabehrens\/tmp\/foo-bar-base\/dev-ops\/php_cs.php","context":[]}
{"time":"2020-05-16T15:24:01.168590+00:00","level":"debug","message":"Parsing file \/Users\/joshuabehrens\/tmp\/foo-bar-base\/src\/Party.php","context":[]}
@icanhazstring
Copy link
Member

Hi again. Thanks for reporting. The scan of core exetnsikns7and the language itself is not very stable.

For example if you require a package that uses php. php will be reported as required by that package instead of the root project itself.

This should also solve the problem you are describing. I will see to it. Thanks for reporting.

@JoshuaBehrens
Copy link
Contributor Author

Thanks for you fast reaction. In case you need any support from my side just give me a note.

@icanhazstring
Copy link
Member

icanhazstring commented May 17, 2020

Ok found the bug, as we try to load all classes, constants and function from all "extensions".
As all extensions having the correct name (e.g. json - which will match as ext-json) this is working fine.

Only difference is the "core" extension, so php itself. The current implementation is trying to find the ext-core which does not work obviously :)

I will try and fix this with #78 as they both need a new test implementation.
In the meantime #78 should be fixed with the PR #80 and maybe you can check if this works properly :)

As I said, this issue will be fixed there as well but needs a bit more implementation detail.


edit:

Solved in #80 as well.
Will merge this into master so you could check with current dev-master against your CI if everything works out.

@JoshuaBehrens
Copy link
Contributor Author

Nice I'll try ASAP. Thanks for your super fast reaction :shipit:

@JoshuaBehrens
Copy link
Contributor Author

I can confirm that nothing in a psr 4 setup results in a php unused and thus non-zero exit code 👍 and having an empty class is not triggering the php usage 🤔. I do not expect some sort of feature detection check to determine the php version but any php file should trigger the usage of php, doesn't it? Using a function like strlen is correctly detected and results in a zero exit code 💯

All in all I'd take it like it is because it is solving my problem. Some edge cases still need to be covered in the future for those weird people with empty php files 😅

@icanhazstring
Copy link
Member

icanhazstring commented May 19, 2020

Yep. Currently extensions as well as core language are only detected if symbols (class, constant, functions) are used.

Ofc if you are using plain php without any of those symbols. The language is still "used" 😅

Maybe some improvement in the future 😉

Thanks for testing the changes 👍
Tag coming up asap

@icanhazstring
Copy link
Member

@JoshuaBehrens
Copy link
Contributor Author

🥳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants