Skip to content

Commit 884e22d

Browse files
committed
Refactor const to highlight their coupling matomo-org#4278
1 parent ba372fe commit 884e22d

12 files changed

Lines changed: 38 additions & 18 deletions

File tree

core/API/DataTableManipulator.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
namespace Piwik\API;
1212

1313
use Exception;
14+
use Piwik\Archive\DataTableFactory;
1415
use Piwik\DataTable\Row;
1516
use Piwik\DataTable;
1617
use Piwik\Period\Range;
@@ -119,7 +120,7 @@ protected function loadSubtable($dataTable, $row)
119120

120121
$request['idSubtable'] = $idSubTable;
121122
if ($dataTable) {
122-
$period = $dataTable->getMetadata('period');
123+
$period = $dataTable->getMetadata(DataTableFactory::TABLE_METADATA_PERIOD_INDEX);
123124
if ($period instanceof Range) {
124125
$request['date'] = $period->getDateStart() . ',' . $period->getDateEnd();
125126
} else {

core/Archive.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ private function uncompress($data)
712712
* whether archiving should be launched based on whether $this->idarchives has a
713713
* an entry for a specific 'done' flag.
714714
*
715-
* If this function is not called, then periods with no visits will not add
715+
* If this function is not called, then periods with no visits will not add
716716
* entries to the cache. If the archive is used again, SQL will be executed to
717717
* try and find the archive IDs even though we know there are none.
718718
*/

core/Archive/DataTableFactory.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ class DataTableFactory
8080
*/
8181
private $defaultRow;
8282

83+
const TABLE_METADATA_SITE_INDEX = 'site';
84+
const TABLE_METADATA_PERIOD_INDEX = 'period';
85+
8386
/**
8487
* Constructor.
8588
*/
@@ -383,8 +386,8 @@ private function transformMetadata($table)
383386
{
384387
$periods = $this->periods;
385388
$table->filter(function ($table) use ($periods) {
386-
$table->setMetadata('site', new Site($table->getMetadata('site')));
387-
$table->setMetadata('period', $periods[$table->getMetadata('period')]);
389+
$table->setMetadata(self::TABLE_METADATA_SITE_INDEX, new Site($table->getMetadata(self::TABLE_METADATA_SITE_INDEX)));
390+
$table->setMetadata(self::TABLE_METADATA_PERIOD_INDEX, $periods[$table->getMetadata(self::TABLE_METADATA_PERIOD_INDEX)]);
388391
});
389392
}
390393

core/DataTable/Renderer/Rss.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
namespace Piwik\DataTable\Renderer;
1212

1313
use Exception;
14+
use Piwik\Archive;
1415
use Piwik\Common;
1516
use Piwik\DataTable\Renderer;
1617
use Piwik\DataTable;
@@ -75,8 +76,8 @@ protected function renderTable($table)
7576
$moreRecentFirst = array_reverse($table->getDataTables(), true);
7677
foreach ($moreRecentFirst as $date => $subtable) {
7778
/** @var DataTable $subtable */
78-
$timestamp = $subtable->getMetadata('period')->getDateStart()->getTimestamp();
79-
$site = $subtable->getMetadata('site');
79+
$timestamp = $subtable->getMetadata(Archive\DataTableFactory::TABLE_METADATA_PERIOD_INDEX)->getDateStart()->getTimestamp();
80+
$site = $subtable->getMetadata(Archive\DataTableFactory::TABLE_METADATA_SITE_INDEX);
8081

8182
$pudDate = date('r', $timestamp);
8283

core/Site.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@ public static function setSites($sites)
7171
self::$infoSites = $sites;
7272
}
7373

74+
/**
75+
* @param $idsite
76+
* @param $site
77+
*/
78+
protected static function setSite($idsite, $site)
79+
{
80+
self::$infoSites[$idsite] = $site;
81+
}
82+
7483
/**
7584
* Sets the cached Site data with a non-associated array of site data.
7685
*
@@ -91,6 +100,7 @@ public static function setSitesFromArray($sites)
91100
self::setSites($sitesById);
92101
}
93102

103+
94104
/**
95105
* Returns a string representation of the site this instance references.
96106
*
@@ -313,7 +323,8 @@ static protected function getFor($idsite, $field)
313323
$idsite = (int)$idsite;
314324

315325
if (!isset(self::$infoSites[$idsite])) {
316-
self::$infoSites[$idsite] = API::getInstance()->getSiteFromId($idsite);
326+
$site = API::getInstance()->getSiteFromId($idsite);
327+
self::setSite($idsite, $site);
317328
}
318329

319330
return self::$infoSites[$idsite][$field];

plugins/API/ProcessedReport.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
use Exception;
1414
use Piwik\API\Request;
15+
use Piwik\Archive\DataTableFactory;
1516
use Piwik\Common;
1617
use Piwik\DataTable\Row;
1718
use Piwik\DataTable\Simple;
@@ -421,7 +422,7 @@ private function handleTableReport($idSite, $dataTable, &$reportMetadata, $showR
421422
list($enhancedSimpleDataTable, $rowMetadata) = $this->handleSimpleDataTable($idSite, $simpleDataTable, $columns, $hasDimension, $showRawMetrics);
422423
$enhancedSimpleDataTable->setAllTableMetadata($simpleDataTable->getAllTableMetadata());
423424

424-
$period = $simpleDataTable->getMetadata('period')->getLocalizedLongString();
425+
$period = $simpleDataTable->getMetadata(DataTableFactory::TABLE_METADATA_PERIOD_INDEX)->getLocalizedLongString();
425426
$newReport->addTable($enhancedSimpleDataTable, $period);
426427
$rowsMetadata->addTable($rowMetadata, $period);
427428
}

plugins/Actions/API.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,11 +351,11 @@ public function getSiteSearchCategories($idSite, $period, $date, $segment = fals
351351
foreach ($customVariableDatatables as $key => $customVariableTableForDate) {
352352
// we do not enter the IF, in the case idSite=1,3 AND period=day&date=datefrom,dateto,
353353
if ($customVariableTableForDate instanceof DataTable
354-
&& $customVariableTableForDate->getMetadata('period')
354+
&& $customVariableTableForDate->getMetadata(Archive\DataTableFactory::TABLE_METADATA_PERIOD_INDEX)
355355
) {
356356
$row = $customVariableTableForDate->getRowFromLabel($customVarNameToLookFor);
357357
if ($row) {
358-
$dateRewrite = $customVariableTableForDate->getMetadata('period')->getDateStart()->toString();
358+
$dateRewrite = $customVariableTableForDate->getMetadata(Archive\DataTableFactory::TABLE_METADATA_PERIOD_INDEX)->getDateStart()->toString();
359359
$idSubtable = $row->getIdSubDataTable();
360360
$categories = APICustomVariables::getInstance()->getCustomVariablesValuesFromNameId($idSite, $period, $dateRewrite, $idSubtable, $segment);
361361
$dataTable->addTable($categories, $key);

plugins/CoreVisualizations/JqplotDataGenerator/Evolution.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
namespace Piwik\Plugins\CoreVisualizations\JqplotDataGenerator;
1212

1313

14+
use Piwik\Archive\DataTableFactory;
1415
use Piwik\Common;
1516
use Piwik\DataTable;
1617
use Piwik\DataTable\Row;
@@ -40,7 +41,7 @@ protected function initChartObjectData($dataTable, $visualization)
4041
// the X label is extracted from the 'period' object in the table's metadata
4142
$xLabels = array();
4243
foreach ($dataTable->getDataTables() as $metadataDataTable) {
43-
$xLabels[] = $metadataDataTable->getMetadata('period')->getLocalizedShortString(); // eg. "Aug 2009"
44+
$xLabels[] = $metadataDataTable->getMetadata(DataTableFactory::TABLE_METADATA_PERIOD_INDEX)->getLocalizedShortString(); // eg. "Aug 2009"
4445
}
4546

4647
$units = $this->getUnitsForColumnsToDisplay();
@@ -75,12 +76,12 @@ protected function initChartObjectData($dataTable, $visualization)
7576

7677
if ($this->isLinkEnabled()) {
7778
$idSite = Common::getRequestVar('idSite', null, 'int');
78-
$periodLabel = reset($dataTables)->getMetadata('period')->getLabel();
79+
$periodLabel = reset($dataTables)->getMetadata(DataTableFactory::TABLE_METADATA_PERIOD_INDEX)->getLabel();
7980

8081
$axisXOnClick = array();
8182
$queryStringAsHash = $this->getQueryStringAsHash();
8283
foreach ($dataTable->getDataTables() as $idDataTable => $metadataDataTable) {
83-
$dateInUrl = $metadataDataTable->getMetadata('period')->getDateStart();
84+
$dateInUrl = $metadataDataTable->getMetadata(DataTableFactory::TABLE_METADATA_PERIOD_INDEX)->getDateStart();
8485
$parameters = array(
8586
'idSite' => $idSite,
8687
'period' => $periodLabel,

plugins/DBStats/MySQLMetadataProvider.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,7 @@ private function getRowCountsByArchiveName($statuses, $getRowSizeMethod, $forceC
230230
// if option exists && !$forceCache, use the cached data, otherwise create the
231231
$cachedData = Option::get($dataTableOptionName);
232232
if ($cachedData !== false && !$forceCache) {
233-
$table = new DataTable();
234-
$table->addRowsFromSerializedArray($cachedData);
233+
$table = DataTable::fromSerializedArray($cachedData);
235234
} else {
236235
// otherwise, create data table & cache it
237236
$sql = "SELECT name as 'label', COUNT(*) as 'row_count'$extraCols FROM {$status['Name']} GROUP BY name";

plugins/Goals/API.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,9 @@ protected function getItems($recordName, $idSite, $period, $date, $abandonedCart
254254
// we do not enter the IF
255255
// if case idSite=1,3 AND period=day&date=datefrom,dateto,
256256
if ($customVariableTableForDate instanceof DataTable
257-
&& $customVariableTableForDate->getMetadata('period')
257+
&& $customVariableTableForDate->getMetadata(Archive\DataTableFactory::TABLE_METADATA_PERIOD_INDEX)
258258
) {
259-
$dateRewrite = $customVariableTableForDate->getMetadata('period')->getDateStart()->toString();
259+
$dateRewrite = $customVariableTableForDate->getMetadata(Archive\DataTableFactory::TABLE_METADATA_PERIOD_INDEX)->getDateStart()->toString();
260260
$row = $customVariableTableForDate->getRowFromLabel($customVarNameToLookFor);
261261
if ($row) {
262262
$idSubtable = $row->getIdSubDataTable();

0 commit comments

Comments
 (0)