Skip to content

Commit

Permalink
phpcs fixes, updated expected screenshots + remove debug code from a …
Browse files Browse the repository at this point in the history
…test
  • Loading branch information
diosmosis committed Sep 23, 2024
1 parent fa6f5b8 commit 09cc47b
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 39 deletions.
6 changes: 3 additions & 3 deletions core/Plugin/Metric.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ abstract class Metric
*/
public const COMPONENT_SUBNAMESPACE = 'Metrics';

const AGGREGATION_TYPE_MAX = 'max';
const AGGREGATION_TYPE_MIN = 'min';
const AGGREGATION_TYPE_SUM = 'sum';
public const AGGREGATION_TYPE_MAX = 'max';
public const AGGREGATION_TYPE_MIN = 'min';
public const AGGREGATION_TYPE_SUM = 'sum';

/**
* Returns the column name of this metric, eg, `"nb_visits"` or `"avg_time_on_site"`.
Expand Down
7 changes: 4 additions & 3 deletions core/Plugin/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,8 @@ public function getMetricAggregationTypes(): array
$metricScopes = $this->getMetricScopes();
foreach ($aggregationTypes as $metricName => $aggregationType) {
$metricScope = $metricScopes[$metricName];
if (empty($metricScope)
if (
empty($metricScope)
|| !$this->isScopeSameOrSubsetOf($metricScope, $reportScope)
) {
unset($aggregationTypes[$metricName]);
Expand Down Expand Up @@ -1319,9 +1320,9 @@ private function getScope(): ?string

if ($dimension instanceof ConversionDimension) {
return 'log_conversion';
} else if ($dimension instanceof ActionDimension) {
} elseif ($dimension instanceof ActionDimension) {
return 'log_link_visit_action';
} else if ($dimension instanceof VisitDimension) {
} elseif ($dimension instanceof VisitDimension) {
return 'log_visit';
}

Expand Down
1 change: 0 additions & 1 deletion plugins/Actions/ArchivingHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Piwik\DataTable\Row;
use Piwik\Metrics as PiwikMetrics;
use Piwik\Piwik;
use Piwik\Plugins\Goals\Columns\Metrics\GoalSpecific\ConversionPageRate;
use Piwik\RankingQuery;
use Piwik\Tracker\Action;
use Piwik\Tracker\PageUrl;
Expand Down
6 changes: 3 additions & 3 deletions plugins/CoreHome/Columns/Metrics/EvolutionMetric.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public function getTranslatedName()
{
if (isset($this->wrappedMetricTranslatedName)) {
$metricName = Piwik::translate($this->wrappedMetricTranslatedName);
} else if ($this->wrapped instanceof Metric) {
} elseif ($this->wrapped instanceof Metric) {
$metricName = $this->wrapped->getTranslatedName();
} else {
$defaultMetricTranslations = Metrics::getDefaultMetricTranslations();
Expand Down Expand Up @@ -325,7 +325,7 @@ public function getExtraMetricAggregationTypes(): array

if (!empty($this->wrappedMetricAggregationType)) {
$aggregationType = $this->wrappedMetricAggregationType;
} else if ($this->wrapped instanceof Metric) {
} elseif ($this->wrapped instanceof Metric) {
$aggregationType = $this->wrapped->getAggregationType();
} else {
$allAggregationTypes = Metrics::getDefaultMetricAggregationTypes();
Expand All @@ -341,7 +341,7 @@ public function getExtraMetricSemanticTypes(): array

if (!empty($this->wrappedSemanticType)) {
$semanticType = $this->wrappedSemanticType;
} else if ($this->wrapped instanceof Metric) {
} elseif ($this->wrapped instanceof Metric) {
$semanticType = $this->wrapped->getSemanticType();
} else {
$allSemanticTypes = Metrics::getDefaultMetricSemanticTypes();
Expand Down
2 changes: 1 addition & 1 deletion plugins/CoreHome/Columns/Metrics/VisitsPercent.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
class VisitsPercent extends ProcessedMetric
{
const FORCED_TOTAL_VISITS_METADATA_NAME = 'VisitsPercent_total_visits';
public const FORCED_TOTAL_VISITS_METADATA_NAME = 'VisitsPercent_total_visits';

private $cachedTotalVisits = null;
private $forceTotalVisits;
Expand Down
4 changes: 2 additions & 2 deletions plugins/Goals/Goals.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
use Piwik\Plugins\Goals\Columns\Metrics\GoalSpecific\ConversionEntryRate;
use Piwik\Plugins\Goals\Columns\Metrics\GoalSpecific\ConversionPageRate;
use Piwik\Plugins\Goals\Columns\Metrics\GoalSpecific\ConversionRate;
use Piwik\Plugins\Goals\Columns\Metrics\GoalSpecific\ItemsCount;
use Piwik\Plugins\Goals\Columns\Metrics\GoalSpecific\RevenuePerEntry;
use Piwik\Plugins\Goals\Columns\Metrics\GoalSpecific\RevenuePerVisit;
use Piwik\Plugins\Goals\RecordBuilders\ProductRecord;
Expand Down Expand Up @@ -394,7 +393,8 @@ public function getReportMetadataEnd(&$reports, $info)

// add ecommerce metrics if idGoal is an ecommerce goal
$idGoal = \Piwik\Request::fromRequest()->getParameter('idGoal', '');
if ($idGoal === Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER
if (
$idGoal === Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER
|| $idGoal === Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_CART
) {
$goalMetrics['items'] = [
Expand Down
14 changes: 0 additions & 14 deletions plugins/Goals/tests/System/TrackGoalsOneConversionPerVisitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,6 @@ public function getApiForTesting()
{
$apiToCall = array('Goals.get');

return [
['API.getProcessedReport', [
'idSite' => self::$fixture->idSite,
'date' => self::$fixture->dateTime,
'period' => 'day',
'testSuffix' => 'showGoalsMetricsSingleGoal',
'otherRequestParameters' => [
'filter_update_columns_when_show_all_goals' => '1',
'filter_show_goal_columns_process_goals' => '1',
'apiModule' => 'DevicesDetection',
'apiAction' => 'getBrowsers',
],
]],
];
return array(
array($apiToCall, array(
'idSite' => self::$fixture->idSite,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<revenue_per_visit>Revenue per Visit</revenue_per_visit>
</processedMetrics>
<processedMetricFormulas>
<revenue_per_visit>($goals[&quot;idgoal=1&quot;].revenue + $goals[&quot;idgoal=2&quot;].revenue) / ($nb_visits != 0 ? $nb_visits : $nb_conversions)</revenue_per_visit>
<revenue_per_visit>$revenue / ($nb_visits != 0 ? $nb_visits : $nb_conversions)</revenue_per_visit>
<conversion_rate>$nb_visits_converted / $nb_visits</conversion_rate>
<nb_actions_per_visit>$nb_actions / $nb_visits</nb_actions_per_visit>
<avg_time_on_site>$sum_visit_length / $nb_visits</avg_time_on_site>
Expand Down Expand Up @@ -77,8 +77,8 @@
<revenue>sum</revenue>
</metricAggregationTypesGoal>
<processedMetricsGoal>
<revenue_per_visit>Ecommerce order Revenue per Visit</revenue_per_visit>
<conversion_rate>Ecommerce order conversion rate</conversion_rate>
<revenue_per_visit>Revenue per Visit</revenue_per_visit>
<conversion_rate>Conversion rate</conversion_rate>
</processedMetricsGoal>
<processedMetricFormulasGoal>
<revenue_per_visit>$goals[&quot;idgoal={idGoal}&quot;].revenue / ($nb_visits == 0 ? $goals[&quot;idgoal={idGoal}&quot;].nb_conversions : $nb_visits)</revenue_per_visit>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ public function getSemanticType(): ?string

public function getFormula(): ?string
{
$parts = array_map(function ($n) { return '$' . $n; }, $this->getDependentMetrics());
$parts = array_map(
function ($n) {
return '$' . $n;
},
$this->getDependentMetrics()
);
return implode(' + ', $parts);
}
}
25 changes: 25 additions & 0 deletions tests/PHPUnit/Framework/Assert/ProcessedMetricAssert.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

Check failure on line 1 in tests/PHPUnit/Framework/Assert/ProcessedMetricAssert.php

View workflow job for this annotation

GitHub Actions / PHPCS

Header blocks must be separated by a single blank line
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/

namespace PHPUnit\Framework\Assert;

class ProcessedMetricAssert
{
public function assertProcessedMetricFormulasAreValid(string $pluginName): void
{
// TODO
/*
- check plugin is loaded
- get list of processed metrics for the plugin (check that the list is not empty)
- for each:
- * check that the formula parses
- * create a fake datatable row with random values for columns
- * check that the compute function matches the result of evaluating the formula
*/
}
}
4 changes: 2 additions & 2 deletions tests/UI/expected-screenshots/RowEvolution_row_evolution.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 09cc47b

Please sign in to comment.