10up / autoshare-for-twitter

Automatically shares the post title or custom message and a link to the post to X/Twitter.
https://wordpress.org/plugins/autoshare-for-twitter/
GNU General Public License v2.0
116 stars 19 forks source link

Made an implicit float to integer conversion explicit to fix PHP 8.2 deprecation warning #301

Closed justinmaurerdotdev closed 10 months ago

justinmaurerdotdev commented 10 months ago

Description of the Change

The string replacement was based on a calculation of half of the URL's length. When that length is an odd number, the substr_replace function was getting a decimal instead of an integer, which throws a deprecation warning about "implicit float to int conversion" in PHP 8.2.

How to test the Change

The staging handling for autopost functionality should still work, and the warning about a site change being detected should be displayed in the dashboard while working on staging or development environments.

Changelog Entry

Fixed - minor deprecation warning about implicit float to int conversion

Credits

Props @justinmaurerdotdev

Checklist:

I was not able to get my tests to pass because of this error in the phpcs pre-commit process:

----------------------------------------------------------------------
1 | ERROR | An error occurred during processing; checking has been
  |       | aborted. The error message was: trim(): Passing null to
  |       | parameter #1 ($string) of type string is deprecated in
  |       | .../wp-content/plugins/autoshare-for-twitter/vendor/wp-coding-standards/wpcs/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php
  |       | on line 280 (Internal.Exception)
----------------------------------------------------------------------
justinmaurerdotdev commented 10 months ago

Happy to help. Sorry I didn't catch those easy syntax issues. Not sure why PHPCS decided to error instead of tell me about them... Anyway, thanks for getting this merged, and for the new release!