Skip to content
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

Requirement of Requests package problematic #16

Closed
BrianHenryIE opened this issue Nov 24, 2023 · 1 comment · Fixed by #18
Closed

Requirement of Requests package problematic #16

BrianHenryIE opened this issue Nov 24, 2023 · 1 comment · Fixed by #18

Comments

@BrianHenryIE
Copy link
Contributor

I've been getting errors using PhpStan WordPress:

$ phpstan analyse 
Note: Using configuration file /Users/brianhenry/Sites/bh-wp-bitcoin-gateway/phpstan.neon.
Fatal error: Cannot declare class WpOrg\Requests\Autoload, because the name is already in use in /Users/brianhenry/Sites/bh-wp-bitcoin-gateway/vendor/php-stubs/wordpress-stubs/wordpress-stubs.php on line 18703
Script phpstan analyse --memory-limit 1G handling the cs event returned with error code 255

I think there are two ways to address it.

Add documentation to the README:

# Add a `provide` entry to tell Composer not to install Requests.
# brew install jq sponge
cat composer.json | jq ".provide += { \"rmccue/requests\": \"*\" }" | sponge composer.json

main...BrianHenryIE:WP-Requests-PSR18-Adapter:patch-1

Or move "rmccue/requests": "^1.8 || ^2.0" from require to require-dev and add suggest:

"suggest": {
    "rmccue/requests": "Requests is included with WordPress but must be required independently otherwise."
}

main...BrianHenryIE:WP-Requests-PSR18-Adapter:patch-2

I think the latter should work. It's more drastic than the first but more straightforward for consumers of this package.

@Art4
Copy link
Owner

Art4 commented Nov 24, 2023

If one is using the library in a WordPress context but uses composer for installation, I recommend to use replace in composer.json to not install rmccue/requests two times. The composer.json could look like this:

{
    "name": "art4/testproject",
    "type": "project",
    "require": {
        "art4/requests-psr18-adapter": "^1.1"
    },
    "require-dev": {
        "phpstan/phpstan": "^1.10",
        "szepeviktor/phpstan-wordpress": "^1.3"
    },
    "replace": {
        "rmccue/requests": "*"
    }
}

Update: I've created #18 to point this out in the README.md.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants