Skip to content

Commit

Permalink
Simple fixes for PHP8.1 (#17929)
Browse files Browse the repository at this point in the history
  • Loading branch information
justinvelluppillai authored Sep 3, 2021
1 parent 3182379 commit 0914642
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion core/ArchiveProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public function insertNumericRecords($numericRecords)
*/
public function insertNumericRecord($name, $value)
{
$value = round($value, 2);
$value = round($value ?? 0, 2);
$value = Common::forceDotAsSeparatorForDecimalPoint($value);

$this->archiveWriter->insertRecord($name, $value);
Expand Down
2 changes: 1 addition & 1 deletion core/AssetManager/UIAssetCacheBuster.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function piwikVersionBasedCacheBuster($pluginNames = false)
}
}

$cacheBuster = md5($pluginsInfo . PHP_VERSION . Version::VERSION . trim($currentGitHash));
$cacheBuster = md5($pluginsInfo . PHP_VERSION . Version::VERSION . trim($currentGitHash ?? ''));

if ($pluginNames !== false) {
return $cacheBuster;
Expand Down
4 changes: 2 additions & 2 deletions core/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ private static function sanitizeString($value)
*/
public static function unsanitizeInputValue($value)
{
return htmlspecialchars_decode($value, self::HTML_ENCODING_QUOTE_STYLE);
return htmlspecialchars_decode($value ?? '', self::HTML_ENCODING_QUOTE_STYLE);
}

/**
Expand Down Expand Up @@ -456,7 +456,7 @@ public static function unsanitizeInputValues($value)
*/
public static function sanitizeLineBreaks($value)
{
return str_replace(array("\n", "\r"), '', $value);
return is_null($value) ? '' : str_replace(array("\n", "\r"), '', $value);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion core/DataTable/Filter/AddColumnsProcessedMetrics.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function filter($table)
$this->deleteRowsWithNoVisit($table);
}

$extraProcessedMetrics = $table->getMetadata(DataTable::EXTRA_PROCESSED_METRICS_METADATA_NAME);
$extraProcessedMetrics = $table->getMetadata(DataTable::EXTRA_PROCESSED_METRICS_METADATA_NAME) ?: [];

$extraProcessedMetrics[] = new ConversionRate();
$extraProcessedMetrics[] = new ActionsPerVisit();
Expand Down
1 change: 1 addition & 0 deletions core/Translation/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public static function clean($s)
public function translate($translationId, $args = array(), $language = null)
{
$args = is_array($args) ? $args : array($args);
$translationId = $translationId ?? '';

if (strpos($translationId, "_") !== false) {
list($plugin, $key) = explode("_", $translationId, 2);
Expand Down
2 changes: 1 addition & 1 deletion core/Twig.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function piwik_fix_lbrace($string)
$replace = array_map(function ($val) { return $val . '⁣' . $val; }, $chars);
}

$replacedString = str_replace($search, $replace, $string);
$replacedString = is_null($string) ? $string : str_replace($search, $replace, $string);

// try to replace characters until there are no changes
if ($string !== $replacedString) {
Expand Down

0 comments on commit 0914642

Please sign in to comment.