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
BUG: Package Functions #242
Comments
Hi @MGatner. Thanks for reaching out, again :) |
Thanks! Checking now... |
Actually detecting less now. Running 2.1.12 (2021-11-09 16:02:04) with PHP 7.4.10 on Linux / 5.11.0-1020-aws
Results
-------
Found 4 used, 8 unused and 0 ignored packages
Used packages
✓ php
✓ tatter/exports
✓ tatter/settings
✓ tatter/thumbnails
Unused packages
✗ components/jquery
✗ enyo/dropzone
✗ fortawesome/font-awesome
✗ tatter/alerts
✗ tatter/assets
✗ tatter/audits
✗ tatter/permits
✗ twbs/bootstrap
Ignored packages The asset repos are expected (they used to be "Package provides no namespace") but |
Ok, I have removed some checks for the packages to be scanned. Now there are some "new" packages delivered using composer.
|
Thanks! Let me know how I can help. |
Will create a PR on composer-unused/symbol-scanner where I will add some test cases. Would be nice if you could review them as I try to replicate the issue with your packages. |
Great news @MGatner I could replicate the behavior for this issue. Problem is: |
That's awesome! Thank you for the update. |
Hi @MGatner could the check out the PR and see if this is working for you? |
@icanhazstring It still seems to be missing some of them. In the same example above, I'm looking at the I will say, the new version is waaaay faster! Very impressively so. Let me know if there are debug logs or something I can provide to help. |
Thanks, will take a deeper look |
I found the problem with this package. While the
Or you can add the namespace of to the function helper itself, this way it would be found using a NamespaceSymbol. |
Okay, I will try adding it to Composer's |
I see. If you add them to autoload.files this should work with phpstan as well. |
I merged the PR into main. |
Okay, that worked, but also one weirdness! I pulled the latest and used it on Results
-------
Found 4 used, 4 unused and 0 ignored packages
Used packages
✓ php
✓ tatter/exports
✓ tatter/frontend
✓ tatter/permits
Unused packages
✗ enyo/dropzone
✗ tatter/alerts
✗ tatter/preferences
✗ tatter/thumbnails
Ignored packages Then I modified vendor/tatter/alerts/composer.json to simulate having added the "autoload": {
"psr-4": {
"Tatter\\Alerts\\": "src"
},
"exclude-from-classmap": [
"**/Database/Migrations/**"
],
"files": [
"src/Helpers/alerts_helper.php"
]
}, After running Results
-------
Found 7 used, 1 unused and 0 ignored packages
Used packages
✓ php
✓ tatter/alerts
✓ tatter/exports
✓ tatter/frontend
✓ tatter/permits
✓ tatter/preferences
✓ tatter/thumbnails
Unused packages
✗ enyo/dropzone
Ignored packages Something fishy going on here? |
Funny 😅 |
Tried to reproduce with only Can you give me the precise version constraint for each package you are using?
|
Here are the exact steps to recreate it. I just did this in a fresh environment so I know it isn't cache or something.
|
Thanks. Will check it out |
PHP: 7.4 Before autoload fix:
After outload fix:
Looks good to me though? |
😳 That's bizarre. Same steps as mine? I've recreated this twice, and every time it erratically considers "thumbnails" and "preferences" in use. Maybe environment difference? All my tests are on Ubuntu 20.04 with PHP 7.4, not sure the precise Composer but version 2.x |
I am working on Mac though. Maybe I'll setup a docker with Ubuntu. But that seems odd 🤔 |
I mean, technically it is correct. It is just odd that it picks up the helper file functions without their addition to Composer's FWIW for some packages with helper files I will probably opt to ignore them rather than have them autoloaded every time; in some scenarios that is quite useful but in others the helper function are mostly "optional" and rarely used. It's too bad there's not an "autoload-dev" files section. If you every consider adding external Config files similar to PHPStan or CS Fixer, this would be on my request: additional files to load before scanning. |
Feel free to add a feature request discussion 😉 So we can close this one for now? |
Describe the bug
Composer Unused does not seem to detect a package as a dependency if the source repo uses a function that is defined in that package.
Error dump
Live example in Actions output: https://github.com/tattersoftware/codeigniter4-files/runs/4347265699?check_suite_focus=true
In this example
tatter/alerts
defines a helper functionalerts()
(https://github.com/tattersoftware/codeigniter4-alerts/blob/develop/src/Helpers/alerts_helper.php) which is used by the source repo's controller (https://github.com/tattersoftware/codeigniter4-files/blob/0ee8595a60394cebeb42ab11a3e095042b0ebd5e/src/Controllers/Files.php#L374).The text was updated successfully, but these errors were encountered: