diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6fe9d7b..b6d9a84 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,6 +18,3 @@ jobs: uses: matomo-org/plugin-ci-workflows/.github/workflows/plugin-ci.yml@main with: plugin-name: CustomVariables - # PHPStan has never run here and there is no phpstan.neon to run it with; - # adding one is a decision of its own. - skip-phpstan: true diff --git a/API.php b/API.php index c8066a4..08cb9c3 100644 --- a/API.php +++ b/API.php @@ -14,7 +14,6 @@ use Piwik\Archive; use Piwik\Container\StaticContainer; use Piwik\DataTable; -use Piwik\Date; use Piwik\Metrics; use Piwik\Piwik; @@ -28,21 +27,21 @@ class API extends \Piwik\Plugin\API /** * @param int $idSite * @param string $period - * @param Date $date + * @param string $date * @param string $segment * @param bool $expanded - * @param int $idSubtable + * @param int|null $idSubtable * * @return DataTable|DataTable\Map */ protected function getDataTable($idSite, $period, $date, $segment, $expanded, $flat, $idSubtable) { $dataTable = Archive::createDataTableFromArchive(Archiver::CUSTOM_VARIABLE_RECORD_NAME, $idSite, $period, $date, $segment, $expanded, $flat, $idSubtable); - $dataTable->queueFilter('ColumnDelete', 'nb_uniq_visitors'); + $dataTable->queueFilter('ColumnDelete', ['nb_uniq_visitors']); if ($flat) { $dataTable->filterSubtables('Sort', array(Metrics::INDEX_NB_ACTIONS, 'desc', $naturalSort = false, $expanded)); - $dataTable->queueFilterSubtables('ColumnDelete', 'nb_uniq_visitors'); + $dataTable->queueFilterSubtables('ColumnDelete', ['nb_uniq_visitors']); } return $dataTable; @@ -166,9 +165,9 @@ public function getUsagesOfSlots($idSite) 'page' => array_fill(1, $numVars, array()), ); - /** @var DataTable $customVarUsages */ $today = StaticContainer::get('CustomVariables.today'); $date = '2008-12-12,' . $today; + /** @var DataTable $customVarUsages */ $customVarUsages = Request::processRequest( 'CustomVariables.getCustomVariables', array('idSite' => $idSite, 'period' => 'range', 'date' => $date, diff --git a/RecordBuilders/CustomVariables.php b/RecordBuilders/CustomVariables.php index 890cc09..46224ff 100644 --- a/RecordBuilders/CustomVariables.php +++ b/RecordBuilders/CustomVariables.php @@ -74,7 +74,7 @@ protected function aggregate(ArchiveProcessor $archiveProcessor): array } - protected function aggregateCustomVariable(DataTable $record, array &$metadata, array &$metadataFlat, LogAggregator $logAggregator, string $slot): void + protected function aggregateCustomVariable(DataTable $record, array &$metadata, array &$metadataFlat, LogAggregator $logAggregator, int $slot): void { $keyField = "custom_var_k" . $slot; $valueField = "custom_var_v" . $slot; diff --git a/Reports/GetCustomVariables.php b/Reports/GetCustomVariables.php index 0f01ce2..448c10a 100644 --- a/Reports/GetCustomVariables.php +++ b/Reports/GetCustomVariables.php @@ -71,9 +71,7 @@ public function getFooterMessageExplanationMissingMetrics() // no footer message for subtables $out = ''; Piwik::postEvent('Template.afterCustomVariablesReport', array(&$out)); - if (!empty($message)) { - $message .= $out; - } + $message .= $out; } return $message; diff --git a/Tracker/CustomVariablesRequestProcessor.php b/Tracker/CustomVariablesRequestProcessor.php index e7752eb..fe15ded 100644 --- a/Tracker/CustomVariablesRequestProcessor.php +++ b/Tracker/CustomVariablesRequestProcessor.php @@ -46,6 +46,8 @@ public function processRequestParams(VisitProperties $visitProperties, Request $ } $request->setMetadata('CustomVariables', 'visitCustomVariables', $visitorCustomVariables); + + return false; } public function onNewVisit(VisitProperties $visitProperties, Request $request) @@ -71,7 +73,7 @@ public function afterRequestProcessed(VisitProperties $visitProperties, Request $action = $request->getMetadata('Actions', 'action'); if (empty($action) || !($action instanceof Action)) { - return; + return false; } $customVariables = self::getCustomVariablesInPageScope($request); @@ -84,6 +86,8 @@ public function afterRequestProcessed(VisitProperties $visitProperties, Request $action->setCustomField($field, $value); } } + + return false; } public static function getCustomVariablesInVisitScope(Request $request) diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..e8f7e2b --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,35 @@ +parameters: + level: 5 + phpVersion: 80100 + tmpDir: /tmp/phpstan/CustomVariables/main + paths: + - . + excludePaths: + analyseAndScan: + - tests/* + # The shared workflow leaves this helper checkout in the workspace, and `paths: .` + # would otherwise analyse it as if it were plugin code. + - github-action-tests/* + ignoreErrors: + # Row::setColumn() and deleteColumn() are untyped and only document `@param string`, while + # archiving addresses columns by the integer Metrics::INDEX_* constants throughout. Pinned + # to the five call sites that do so, so a sixth has to be looked at rather than absorbed. + - + identifier: argument.type + message: '#Row::(setColumn|deleteColumn)\(\) expects string, int given#' + path: RecordBuilders/CustomVariables.php + count: 5 + # This plugin supports Matomo 5 and 6, but the analysis only ever sees one of them, so the + # version guard reads as decided. It is load-bearing on the other line. + - + identifier: ternary.alwaysTrue + path: RecordBuilders/CustomVariables.php + count: 1 + bootstrapFiles: + - ../../bootstrap-phpstan.php + universalObjectCratesClasses: + - Piwik\Config + - Piwik\View + - Piwik\ViewDataTable\Config + scanDirectories: + - ../../