Closed mklepaczewski closed 3 years ago
As bad as this is - I just comment out these four functions mentioned above from
vendor/php-stubs/wordpress-stubs/wordpress-stubs.php
π π π
I use sed
also to do it.
if () :
function bla () {}
endinf;
Conditional function definition is an awful thing. But WordPress targets non-developers so we have to live with it.
Related to #33
May I suggest adding your sed
workaround to readme.md
(possibly FAQ section)? It seems like this issue will be coming back from time to time.
this issue will be coming back from time to time.
For sure.
I'd like to revisit this issue and instead of attempting to edit a composer package by hand this should be done automatically via Composer when needed. This should be done using a Composer package patch and not manual edits. The Composer package cweagans/composer-patches can be used to patch this package. I'm going to work up a patch file to be used and do it this way.
to work up a patch file
All right, Tim. Please keep in mind that each release needs that file!
No! I need to be clear. This package is way more complex than I can bear.
Some use cases still need manual intervention. Sorry for that. It is WordPress.
@szepeviktor well, yes, you are correct that each release will need the patch. And it is no different than having to manually edit the file after every release as well. The thing of it is that in order for this to work with CI/CD I have to be use the patching mechanism in order to maintain the automation.
Also, to be clear I'm not proposing something that needs to be maintained here, other than perhaps making a note of using a patching mechanism instead of just sed
.
@timnolte I gladly extend the Dirty corner section for you!! π
@szepeviktor thank you for all of the work you do to maintain this stuff btw. I know it's not always easy, and goes very often without thanks and recognition.
I also saw this on a project in the past and decided it was actually roots/wp-password-bcrypt
that was at fault for not wrapping its pluggable definition of wp_set_password()
in a function_exists
check but then I forgot to do anything about it.
@johnbillion ah, thanks, I may actually patch that package instead of wordpress-stubs, as that is the one that is causing me grief right now.
π @timnolte You may also exclude roots/wp-password-bcrypt
from analysis.
@szepeviktor that's the interesting thing is that I actually did exclude it in my phpstan.neon.dist
configuration but it still appears to cause a problem. I explicitly put it in the excludePaths
under analyseAndScan
and it still causes PHPStan to completely fail.
I think the fact that it's being autoloaded via Composer might actually be the problem.
You can uninstall that package before analysis or use https://github.com/mcaskill/composer-plugin-exclude-files or find another way.
@johnbillion so actually, patching the roots/wp-password-bcrypt
package doesn't resolve the issue, even with a function_exists
wrapper. I just patched the package to see if that fixes things and the way things seem to be autoloading is that the roots/wp-password-bcrypt
package appears to be loading before the php-stubs/wordpress-stubs
methods.
@timnolte Running and testing cannot be done with this conditional function definition.
You may run it untouched, and test it patched.
e.g. add return;
in the second line of wp-password-bcrypt.php
before testing
@szepeviktor I'm not quite clear on what you mean by:
run it untouched, and test it patched.
This package is a Composer dependency and there is no distinction between "running" and "testing" by a local developer running the command or having PHPStan run/check files in their IDE. Additionally, for local development we are using a Docker setup that has the site running, so again there is no separation of "run" & "test" in terms of Composer actions.
@timnolte Before you perform static analysis you have to get rid of roots/wp-password-bcrypt
e.g. by uninstalling it or adding that return;
- somehow you have to avoid those function definitions
Stubs do not contain if
-s, so core's password functions will always be there, even if those functions already exist.
Thus you have to modify your environment, there is no clean solution.
So it actually appears like this site might not actually being using that plugin properly. I completely removed the package and the site seems to actually run without issue, at least logging in which is what I would expect. Going to pull a production database to do more testing to be certain.
This issue causes a pain for any sort of CI/CD and local development linting functionality, like even IDE integration. And to be clear I don't feel like this is actually a PHPStand WordPress issue but that Roots plugin. I know all to well the pains of trying to hack on "modern" development strategies/tools on a system that is not modern by current standards.
I added the sed
commands to post-install-cmd
in the scripts section.
{
"scripts": {
"post-install-cmd": [
"sed -i -e 's#function wp_check_password#function __wp_check_password#' vendor/php-stubs/wordpress-stubs/wordpress-stubs.php",
"sed -i -e 's#function wp_hash_password#function __wp_hash_password#' vendor/php-stubs/wordpress-stubs/wordpress-stubs.php",
"sed -i -e 's#function wp_set_password#function __wp_set_password#' vendor/php-stubs/wordpress-stubs/wordpress-stubs.php"
]
}
}
It seems that there are few conflicts when using https://roots.io/bedrock/ with
roots/wp-password-bcrypt
which declares its own variants of some funtions:Running
vendor/bin/phpstan analyze
throws:Steps to reproduce
Workaround
As bad as this is - I just comment out these four functions mentioned above from
vendor/php-stubs/wordpress-stubs/wordpress-stubs.php