Skip to content

Commit

Permalink
Fix php 8.1 deprecation warning in Device Detector (#20360)
Browse files Browse the repository at this point in the history
* ensure value is a string

* apply code formatting
  • Loading branch information
sgiehl authored Feb 21, 2023
1 parent 89edf62 commit de63d3f
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 123 deletions.
56 changes: 28 additions & 28 deletions plugins/DevicesDetection/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,17 @@ public function getType($idSite, $period, $date, $segment = false)
$this->ensureDefaultRowsInTable($dataTable);

$mapping = AbstractDeviceParser::getAvailableDeviceTypeNames();
$dataTable->filter('AddSegmentByLabelMapping', array('deviceType', $mapping));
$dataTable->filter('ColumnCallbackAddMetadata', array('label', 'logo', __NAMESPACE__ . '\getDeviceTypeLogo'));
$dataTable->filter('GroupBy', array('label', __NAMESPACE__ . '\getDeviceTypeLabel'));
$dataTable->filter('AddSegmentByLabelMapping', ['deviceType', $mapping]);
$dataTable->filter('ColumnCallbackAddMetadata', ['label', 'logo', __NAMESPACE__ . '\getDeviceTypeLogo']);
$dataTable->filter('GroupBy', ['label', __NAMESPACE__ . '\getDeviceTypeLabel']);
return $dataTable;
}

protected function ensureDefaultRowsInTable($dataTable)
{
$requiredRows = array_fill(0, count(AbstractDeviceParser::getAvailableDeviceTypes()), Metrics::INDEX_NB_VISITS);

$dataTables = array($dataTable);
$dataTables = [$dataTable];

if (!($dataTable instanceof DataTable\Map)) {
foreach ($dataTables as $table) {
Expand All @@ -75,9 +75,9 @@ protected function ensureDefaultRowsInTable($dataTable)
foreach ($requiredRows as $requiredRow => $key) {
$row = $table->getRowFromLabel($requiredRow);
if (empty($row)) {
$table->addRowsFromSimpleArray(array(
array('label' => $requiredRow, $key => 0)
));
$table->addRowsFromSimpleArray([
['label' => $requiredRow, $key => 0]
]);
}
}
}
Expand All @@ -95,9 +95,9 @@ protected function ensureDefaultRowsInTable($dataTable)
public function getBrand($idSite, $period, $date, $segment = false)
{
$dataTable = $this->getDataTable('DevicesDetection_brands', $idSite, $period, $date, $segment);
$dataTable->filter('GroupBy', array('label', __NAMESPACE__ . '\getDeviceBrandLabel'));
$dataTable->filter('ColumnCallbackAddMetadata', array('label', 'logo', __NAMESPACE__ . '\getBrandLogo'));
$dataTable->filter('AddSegmentByLabel', array('deviceBrand'));
$dataTable->filter('GroupBy', ['label', __NAMESPACE__ . '\getDeviceBrandLabel']);
$dataTable->filter('ColumnCallbackAddMetadata', ['label', 'logo', __NAMESPACE__ . '\getBrandLogo']);
$dataTable->filter('AddSegmentByLabel', ['deviceBrand']);
return $dataTable;
}

Expand All @@ -122,7 +122,7 @@ public function getModel($idSite, $period, $date, $segment = false)
list($brand, $model) = explode(';', $label, 2);
$brand = getDeviceBrandLabel($brand);
} else {
$brand = null;
$brand = '';
$model = $label;
}

Expand All @@ -132,7 +132,7 @@ public function getModel($idSite, $period, $date, $segment = false)
}
});

$dataTable->filter('GroupBy', array('label', __NAMESPACE__ . '\getModelName'));
$dataTable->filter('GroupBy', ['label', __NAMESPACE__ . '\getModelName']);
return $dataTable;
}

Expand All @@ -147,15 +147,15 @@ public function getModel($idSite, $period, $date, $segment = false)
public function getOsFamilies($idSite, $period, $date, $segment = false)
{
$dataTable = $this->getDataTable('DevicesDetection_os', $idSite, $period, $date, $segment);

// handle legacy archives
if ($dataTable instanceof DataTable\Map || !$dataTable->getRowsCount()) {
$versionDataTable = $this->getDataTable('DevicesDetection_osVersions', $idSite, $period, $date, $segment);
$dataTable = $this->mergeDataTables($dataTable, $versionDataTable);
}

$dataTable->filter('GroupBy', array('label', __NAMESPACE__ . '\getOSFamilyFullName'));
$dataTable->filter('ColumnCallbackAddMetadata', array('label', 'logo', __NAMESPACE__ . '\getOsFamilyLogo'));
$dataTable->filter('GroupBy', ['label', __NAMESPACE__ . '\getOSFamilyFullName']);
$dataTable->filter('ColumnCallbackAddMetadata', ['label', 'logo', __NAMESPACE__ . '\getOsFamilyLogo']);
return $dataTable;
}

Expand Down Expand Up @@ -191,15 +191,15 @@ protected function mergeDataTables(DataTable\DataTableInterface $dataTable, Data
}

} else if (!$dataTable->getRowsCount() && $dataTable2->getRowsCount()) {
$dataTable2->filter('GroupBy', array('label', function ($label) {
$dataTable2->filter('GroupBy', ['label', function ($label) {
if (preg_match("/(.+) [0-9]+(?:\.[0-9]+)?$/", $label, $matches)) {
return $matches[1]; // should match for browsers
}
if (strpos($label, ';')) {
return substr($label, 0, 3); // should match for os
}
return $label;
}));
}]);
return $dataTable2;
}

Expand All @@ -218,11 +218,11 @@ public function getOsVersions($idSite, $period, $date, $segment = false)
{
$dataTable = $this->getDataTable('DevicesDetection_osVersions', $idSite, $period, $date, $segment);

$segments = array('operatingSystemCode', 'operatingSystemVersion');
$dataTable->filter('AddSegmentByLabel', array($segments, Archiver::BROWSER_SEPARATOR));
$dataTable->filter('ColumnCallbackAddMetadata', array('label', 'logo', __NAMESPACE__ . '\getOsLogo'));
$segments = ['operatingSystemCode', 'operatingSystemVersion'];
$dataTable->filter('AddSegmentByLabel', [$segments, Archiver::BROWSER_SEPARATOR]);
$dataTable->filter('ColumnCallbackAddMetadata', ['label', 'logo', __NAMESPACE__ . '\getOsLogo']);
// use GroupBy filter to avoid duplicate rows if old (UserSettings) and new (DevicesDetection) reports were combined
$dataTable->filter('GroupBy', array('label', __NAMESPACE__ . '\getOsFullName'));
$dataTable->filter('GroupBy', ['label', __NAMESPACE__ . '\getOsFullName']);
return $dataTable;
}

Expand Down Expand Up @@ -251,8 +251,8 @@ public function getBrowsers($idSite, $period, $date, $segment = false)
$dataTable = $this->mergeDataTables($dataTable, $versionDataTable);
}

$dataTable->filter('GroupBy', array('label', __NAMESPACE__ . '\getBrowserName'));
$dataTable->filter('ColumnCallbackAddMetadata', array('label', 'logo', __NAMESPACE__ . '\getBrowserFamilyLogo'));
$dataTable->filter('GroupBy', ['label', __NAMESPACE__ . '\getBrowserName']);
$dataTable->filter('ColumnCallbackAddMetadata', ['label', 'logo', __NAMESPACE__ . '\getBrowserFamilyLogo']);
return $dataTable;
}

Expand All @@ -268,10 +268,10 @@ public function getBrowserVersions($idSite, $period, $date, $segment = false)
{
$dataTable = $this->getDataTable('DevicesDetection_browserVersions', $idSite, $period, $date, $segment);

$segments = array('browserCode', 'browserVersion');
$dataTable->filter('AddSegmentByLabel', array($segments, Archiver::BROWSER_SEPARATOR));
$dataTable->filter('ColumnCallbackAddMetadata', array('label', 'logo', __NAMESPACE__ . '\getBrowserLogo'));
$dataTable->filter('ColumnCallbackReplace', array('label', __NAMESPACE__ . '\getBrowserNameWithVersion'));
$segments = ['browserCode', 'browserVersion'];
$dataTable->filter('AddSegmentByLabel', [$segments, Archiver::BROWSER_SEPARATOR]);
$dataTable->filter('ColumnCallbackAddMetadata', ['label', 'logo', __NAMESPACE__ . '\getBrowserLogo']);
$dataTable->filter('ColumnCallbackReplace', ['label', __NAMESPACE__ . '\getBrowserNameWithVersion']);
return $dataTable;
}

Expand All @@ -288,7 +288,7 @@ public function getBrowserEngines($idSite, $period, $date, $segment = false)
$dataTable = $this->getDataTable('DevicesDetection_browserEngines', $idSite, $period, $date, $segment);
$dataTable->filter('AddSegmentValue');
// use GroupBy filter to avoid duplicate rows if old (UserSettings) and new (DevicesDetection) reports were combined
$dataTable->filter('GroupBy', array('label', __NAMESPACE__ . '\getBrowserEngineName'));
$dataTable->filter('GroupBy', ['label', __NAMESPACE__ . '\getBrowserEngineName']);
return $dataTable;
}
}
Loading

0 comments on commit de63d3f

Please sign in to comment.