maglnet / ComposerRequireChecker

A CLI tool to check whether a specific composer package uses imported symbols that aren't part of its direct composer dependencies
MIT License
895 stars 73 forks source link

How to skip particular file #407

Open bogdandubyk opened 1 year ago

bogdandubyk commented 1 year ago

I have an issue with doctrine-ODM, particularly with this file https://github.com/doctrine/mongodb-odm/blob/2.6.x/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Match.php , checker failing with an error:

In LocateASTFromFiles.php line 41:

  Parsing the file [/srv/app/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/GraphLookup/Match.php] resulted in an error: Syntax error, unexpected T_MATCH, expecting T_STRING on line 15  

and it's because I'm using PHP 8.2 where match is a reserved word, I tried adding a file to a white list like this

  "symbol-whitelist" : [
    "null", "true", "false",
    "static", "self", "parent",
    "array", "string", "int", "float", "bool", "iterable", "callable", "void", "object",
    "Doctrine\\ODM\\MongoDB\\Aggregation\\Stage\\GraphLookup\\Match"
  ],

but not sure if I'm doing it correctly or if it's possible at all, but anyway issue is still there. Is there a way to handle this? In general this file is deprecated and my app is working only checker failing

fredden commented 1 year ago

It looks like the PHP requirements in that package are too open. For example, they claim to support PHP 8.4 and 8.9 (neither of which have been released): https://github.com/doctrine/mongodb-odm/blob/2.5.2/composer.json#L24. Getting that fixed should solve this particular problem going forward, as Composer will refuse to install packages which are not compatible with the running (or configured) PHP version.

It seems that you have already reported this problem upstream in https://github.com/doctrine/mongodb-odm/issues/2539. I think the work-around is to use a supported PHP version (which may take some experimentation given the broad claim in their composer.json).

bogdandubyk commented 1 year ago

thank you @fredden, but still is it very hard to provide some configuration option similar to symbol-whitelist where files that should be skipped can be lister? I'm not asking to introduce this feature right away but can imagine more cases like mine, and it's nice to have the option to ignore some file/path. Something similar implemented by unused checker https://github.com/composer-unused/composer-unused#exclude-folders-and-packages

Ocramius commented 1 year ago

What we could do is drop eager scanning of all vendors, relying on the autoloader only: tricky, but possibly necessary for these conditional logic blocks.

As for MongoDB ODM: are you 100% sure that you have a version installed that is compatible with your PHP version?

Marco Pivetta

@.***

https://ocramius.github.io/

On Mon, 26 Jun 2023 at 23:03, Bogdan Dubyk @.***> wrote:

thank you @fredden https://github.com/fredden, but still is it very hard to provide some configuration option similar to symbol-whitelist where files that should be skipped can be lister? I'm not asking to introduce this feature right away but can imagine more cases like mine, and it's nice to have the option to ignore some file/path. Something similar implemented by unused checker https://github.com/composer-unused/composer-unused#exclude-folders-and-packages

— Reply to this email directly, view it on GitHub https://github.com/maglnet/ComposerRequireChecker/issues/407#issuecomment-1608256826, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABFVEAGY4YMGAU5LHSXFGTXNH2I7ANCNFSM6AAAAAAZUTY3VQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

malarzm commented 1 year ago

The class that this project is complaining about is deprecated and exists solely for BC reasons: https://github.com/doctrine/mongodb-odm/blob/69e64e7eb51f07bcfc09bc8e7ea8329f301b44ff/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Match.php#L11-L14. Said class is not used from within the ODM and the project works perfectly fine with PHP 8.2

bogdandubyk commented 1 year ago

yes, I'm on the latest stable version which supports PHP 8.2, all works perfectly, only CI failing because the checker analyzing this deprecated file and failing.

Ocramius commented 1 year ago

My very simplistic endorsement here would be to make something as simple as rm vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/GraphLookup/Match.php in a pre-tool step :+1:

Assuming you don't actually need that file, it's probably best to even drop it from your final build artifact that goes to production, to avoid anything ever touching it :)