php-compatinfo icon indicating copy to clipboard operation
php-compatinfo copied to clipboard

composer requirements verification

Open deubert-it opened this issue 2 years ago • 6 comments

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.

deubert-it avatar Jul 08 '22 14:07 deubert-it

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 ?

llaville avatar Jul 08 '22 15:07 llaville

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

deubert-it avatar Jul 09 '22 12:07 deubert-it

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 avatar Aug 12 '22 16:08 llaville

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 avatar Aug 21 '22 06:08 llaville

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 avatar Oct 16 '22 16:10 llaville

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!

llaville avatar Oct 28 '22 05:10 llaville