llaville / php-compatinfo

Library that find out the minimum version and the extensions required for a piece of code to run
https://llaville.github.io/php-compatinfo/7.1/
Other
371 stars 21 forks source link

composer requirements verification #353

Open deubert-it opened 2 years ago

deubert-it commented 2 years ago

New Feature request

Summary

Verify or suggest changes to a given composer.json - php version/php extension requirements.

Description

Based on the required modules and php version the analyzer detects for a given path, I would like to be able to compare this information to a given composer.json.

The composer.json can hold requirements like this:

"require": {
  "php": "^7.3",
  "ext-zip": "*",
  "ext-simplexml": "*",
  "ext-json": "*",
[..]

The output of the compatinfo analysis should be compared against this to either verify its correctness, or if there are mismatches, suggest changes to the composer.json to match actual requirements from the code.

The composer.json can contain php version pinning, which should also be taken into consideration:

"config": {
  "platform": {
    "php": "7.3.24"
  }
}

If you think it makes sense to add this feature to this library, and could give me some pointers where to put what, I'd be happy to invest some time into this for implementation.

llaville commented 2 years ago

Agree with you, it may be a cool feature ! I've a lot of work to do before, but if you are in hurry, you can submit a PR ?

deubert-it commented 2 years ago

Hi @llaville ,

please check my PR which should be linked - there is more information about it in the PR description.

Screenshot from 2022-07-09 14-38-24

llaville commented 2 years ago

Sorry @deubert-it, I was very busy last weeks and have no free time to have a chance to have a look. I hope to check it next week !

llaville commented 2 years ago

Hello @deubert-it I've finally took time to have a look on your PR proposal. First I would like to thanks you for this effort, even if I think it's not the best way : I'll try to explains why !

PHP CompatInfo v6 has an architectecture based on Extension(s) (see https://github.com/llaville/php-compatinfo/blob/master/docs/01_Components/04_Extensions/Hooks.md) to extends and add new features without altering the analyser:run command.

Reporter category allows to present results on new format (see https://github.com/llaville/php-compatinfo/blob/master/docs/01_Components/04_Extensions/Reporter.md)

There are two standard extensions (Logger and ProgressBar), but in your context (needs) you have to display a new report as output, so the Reporter extension is the best example to follow.

If something is not enough clear, please ask me again !

llaville commented 1 year ago

Hello @deubert-it

Don't know if you've missed my previous comment, or if you're too much busy, but I'll let you know that finally branch 6.5 is available. If you've time to provide a new PR with this code base, I'll have a review on it ! If you've no more free time to do it yourself, I'll be happy to migrate your proposal to this new code base.

Awaiting your answer :)

llaville commented 1 year ago

There is a use case that didn't proceed as expected for me !

When source code analysed give a version that is lower than the constraint provided in composer.json

I.e: source code analysed requires a minimum PHP 5.4 while composer constraint is ^7.4

Give such kind of output


 [ERROR] minimal required php version 5.4.0 from analysis does not match the required php version constraint in
         composer.json ^7.4

< ... MORE ...>

 [ERROR] composer.json verification failed!