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

Fix some PHP8.1 deprecation warnings occurred while running tests #18314

Merged
merged 6 commits into from Nov 16, 2021

Conversation

sgiehl
Copy link
Member

@sgiehl sgiehl commented Nov 15, 2021

Description:

Tried running the tests locally and a couple of deprecation warnings showed up. Not sure if they would occur normally. But should be good to fix them nevertheless.

refs #17686

Review

@sgiehl sgiehl added Needs Review PRs that need a code review not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org. labels Nov 15, 2021
@sgiehl sgiehl added this to the 4.6.0 milestone Nov 15, 2021

// Update minimum only if it is set
if ($newRowToAdd[Metrics::INDEX_EVENT_MIN_EVENT_VALUE] !== false) {
if ($newRowToAdd[Metrics::INDEX_EVENT_MIN_EVENT_VALUE] !== false && $newRowToAdd[Metrics::INDEX_EVENT_MIN_EVENT_VALUE] !== null) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems this one actually fixes some kind of bug, that was never recognized.
Before when an event value was null, which imho means it is not set, it was indirectly casted to int (caused by the round) and thus always resulted in 0. So the minimum event value was incorrectly reported as 0.
This can be seen in the expected test results I have updated. In the Fixture we are actually not setting 0 as event value, so imho this should be a valid change

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@sgiehl
Copy link
Member Author

sgiehl commented Nov 15, 2021

I'll put this into review. There might still be some PHP 8.1 issues around. But might be good to already merge this before releasing an RC. Will continue searching for additional PHP 8.1 issues the coming days and create a new PR if I find any.

@sgiehl sgiehl marked this pull request as ready for review November 15, 2021 16:28
@sgiehl sgiehl requested a review from tsteur November 15, 2021 16:28
Copy link
Member

@tsteur tsteur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall. Left a few comments while reviewing mostly for myself. I think it's only stringEndsWith that might need looking at

core/Common.php Outdated Show resolved Hide resolved
core/Common.php Outdated Show resolved Hide resolved

// Update minimum only if it is set
if ($newRowToAdd[Metrics::INDEX_EVENT_MIN_EVENT_VALUE] !== false) {
if ($newRowToAdd[Metrics::INDEX_EVENT_MIN_EVENT_VALUE] !== false && $newRowToAdd[Metrics::INDEX_EVENT_MIN_EVENT_VALUE] !== null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@@ -71,7 +71,7 @@ public function getPrettyTimeFromSeconds($numberOfSeconds, $displayTimeAsSentenc
} else {
$time = sprintf(Piwik::translate('Intl_NDays'), $days) . " " . sprintf("%02s", $hours) . ':' . sprintf("%02s", $minutes) . ':' . sprintf("%02s", $seconds);
}
$centiSeconds = ($numberOfSeconds * 100) % 100;
$centiSeconds = intval($numberOfSeconds * 100) % 100;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note to myself, this avoids Deprecated: Implicit conversion from float xxxxx to int loses precision. There was no rounding happening before either https://3v4l.org/OK980 so all good

core/Url.php Outdated Show resolved Hide resolved
@@ -298,7 +298,7 @@ public static function safe_unserialize($string, $allowedClasses = [], $rethrow
{
try {
// phpcs:ignore Generic.PHP.ForbiddenFunctions
return unserialize($string, ['allowed_classes' => empty($allowedClasses) ? false : $allowedClasses]);
return unserialize($string ?? '', ['allowed_classes' => empty($allowedClasses) ? false : $allowedClasses]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note to myself: it'll return always false which it also did before https://3v4l.org/qC9u3

@sgiehl
Copy link
Member Author

sgiehl commented Nov 15, 2021

@tsteur thanks for the review. I've applied some changes.

Copy link
Member

@tsteur tsteur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sgiehl 👍 checked with https://3v4l.org/dAKrC and works

Be good to merge once tests pass (unless they fail for another reason)

@justinvelluppillai justinvelluppillai merged commit 3b00013 into 4.x-dev Nov 16, 2021
@justinvelluppillai justinvelluppillai deleted the php81fixes branch November 16, 2021 00:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Review PRs that need a code review not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants