BrianHenryIE / bh-wc-checkout-rate-limiter

Prevent card-attack fraud on WooCommerce stores by rate-limiting the "place order" button
GNU General Public License v2.0
57 stars 4 forks source link

Fatal error thrown at checkout #16

Closed dixonl90 closed 1 year ago

dixonl90 commented 1 year ago

Hello!

This looks like a great plugin, thanks for putting in the time to make it.

I've installed on my development environment, however once I click checkout on the checkout page the following fatal error is thrown:

PHP Fatal error:  Declaration of BrianHenryIE\Checkout_Rate_Limiter\WpOop\TransientCache\CachePool::get($key, $default = null) must be compatible with Psr\SimpleCache\CacheInterface::get(string $key, mixed $default = null): mixed in /srv/www/devsite/current/web/app/plugins/bh-wc-checkout-rate-limiter/vendor-prefixed/wp-oop/transient-cache/src/CachePool.php on line 93

Here's the logs

2022-11-23T10:05:23+00:00 DEBUG Checking 192.168.57.1 rate limit 2 per 60 seconds.
{"debug_backtrace":[{"file":"\/srv\/www\/devsite\/current\/web\/app\/plugins\/bh-wc-checkout-rate-limiter\/src\/WooCommerce\/class-ajax.php","lineNumber":78,"arguments":[],"applicationFrame":false,"method":"[top]","class":null}],"filters":["template_redirect","wc_ajax_checkout"]}
2022-11-23T10:05:23+00:00 ERROR Declaration of BrianHenryIE\Checkout_Rate_Limiter\WpOop\TransientCache\CachePool::get($key, $default = null) must be compatible with Psr\SimpleCache\CacheInterface::get(string $key, mixed $default = null): mixed
{"type":64,"message":"Declaration of BrianHenryIE\\Checkout_Rate_Limiter\\WpOop\\TransientCache\\CachePool::get($key, $default = null) must be compatible with Psr\\SimpleCache\\CacheInterface::get(string $key, mixed $default = null): mixed","file":"\/srv\/www\/devsite\/current\/web\/app\/plugins\/bh-wc-checkout-rate-limiter\/vendor-prefixed\/wp-oop\/transient-cache\/src\/CachePool.php","line":93,"debug_backtrace":[{"file":"\/srv\/www\/devsite\/current\/web\/app\/plugins\/bh-wc-checkout-rate-limiter\/vendor-prefixed\/brianhenryie\/bh-wp-logger\/src\/PHP\/class-php-shutdown-handler.php","lineNumber":87,"arguments":[],"applicationFrame":true,"method":"handle","class":"BrianHenryIE\\Checkout_Rate_Limiter\\WP_Logger\\PHP\\PHP_Shutdown_Handler"},{"file":"unknown","lineNumber":0,"arguments":[],"applicationFrame":false,"method":"[top]","class":null}],"filters":["template_redirect","wc_ajax_checkout"]}

Looks like it's due to the difference in some implementations, here's Psr\SimpleCache\CacheInterface:

public function get(string $key, mixed $default = null): mixed;

This is BrianHenryIE\Checkout_Rate_Limiter\WpOop\TransientCache\CachePool

public function get($key, $default = null)

In theory it should be a simple change of definitions.

Env details: WC Version: 5.8.1 WP Version: 5.9.3 PHP Version: 8.0.17

dixonl90 commented 1 year ago

On further investigation it appears the issue is that another plugin includes a newer version of Psr\SimpleCache which has the types specified.

BrianHenryIE commented 1 year ago

I've another project BrianHenryIE/strauss which prefixes Composer packages' namespaces. I had intentionally excluded psr/* packages from prefixing since their purpose is interoperability. Maybe that's the wrong choice. I've made sure to prefix simple-cache in this project now. Thanks