Skip to content

Commit f8f7f51

Browse files
authored
Merge pull request #91 from matomo-org/spice-psr
Adds test for PHPCS
2 parents 6ced5ca + 81c1644 commit f8f7f51

23 files changed

Lines changed: 114 additions & 37 deletions

.github/workflows/phpcs.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: PHPCS check
2+
3+
on: pull_request
4+
5+
permissions:
6+
actions: read
7+
checks: read
8+
contents: read
9+
deployments: none
10+
issues: read
11+
packages: none
12+
pull-requests: read
13+
repository-projects: none
14+
security-events: none
15+
statuses: read
16+
17+
jobs:
18+
phpcs:
19+
name: PHPCS
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v4
23+
with:
24+
lfs: false
25+
persist-credentials: false
26+
- name: Setup PHP
27+
uses: shivammathur/setup-php@v2
28+
with:
29+
php-version: '7.4'
30+
tools: cs2pr
31+
- name: Install dependencies
32+
run:
33+
composer init --name=matomo/anonymouspiwikusagemeasurement --quiet;
34+
composer --no-plugins config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true -n;
35+
composer config repositories.matomo-coding-standards vcs https://github.com/matomo-org/matomo-coding-standards -n;
36+
composer require matomo-org/matomo-coding-standards:dev-master;
37+
composer install --dev --prefer-dist --no-progress --no-suggest
38+
- name: Check PHP code styles
39+
id: phpcs
40+
run: ./vendor/bin/phpcs --report-full --standard=phpcs.xml --report-checkstyle=./phpcs-report.xml
41+
- name: Show PHPCS results in PR
42+
if: ${{ always() && steps.phpcs.outcome == 'failure' }}
43+
run: cs2pr ./phpcs-report.xml --prepend-filename

AnonymousPiwikUsageMeasurement.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Matomo - free/libre analytics platform
45
*
@@ -16,8 +17,8 @@
1617

1718
class AnonymousPiwikUsageMeasurement extends \Piwik\Plugin
1819
{
19-
const TRACKING_DOMAIN = 'https://demo-anonymous.matomo.org';
20-
const EXAMPLE_DOMAIN = 'http://example.com';
20+
public const TRACKING_DOMAIN = 'https://demo-anonymous.matomo.org';
21+
public const EXAMPLE_DOMAIN = 'http://example.com';
2122

2223
private $profilingStack = array();
2324

@@ -79,11 +80,9 @@ public function trackApiCall(&$return, $endHookParams)
7980

8081
// we need to make sure the call was actually for this method to not send wrong data.
8182
if ($method === $call['method']) {
82-
8383
$neededTimeInMs = ceil(($endTime - $call['time']) * 1000);
8484
break;
8585
}
86-
8786
} while (!empty($this->profilingStack));
8887

8988
if (empty($neededTimeInMs)) {
@@ -118,9 +117,11 @@ public function addMatomoClientTracking(&$out)
118117
'userId' => Piwik::getCurrentUserLogin()
119118
);
120119

121-
if (Piwik::isUserIsAnonymous()
120+
if (
121+
Piwik::isUserIsAnonymous()
122122
|| !$settings->canUserOptOut->getValue()
123-
|| $userSettings->userTrackingEnabled->getValue()) {
123+
|| $userSettings->userTrackingEnabled->getValue()
124+
) {
124125
// an anonymous user is currently always tracked, an anonymous user would not have permission to read
125126
// this user setting. The `isUserIsAnonymous()` check is not needed but there to improve performance
126127
// in case user is anonymous. Then we avoid checking whether user has access to any sites which can be slow
@@ -135,5 +136,4 @@ public function addMatomoClientTracking(&$out)
135136

136137
$out .= "\nvar piwikUsageTracking = " . json_encode($config) . ";\n";
137138
}
138-
139139
}

SystemSettings.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Matomo - free/libre analytics platform
45
*

Tasks.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Matomo - free/libre analytics platform
45
*

Tracker.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Matomo - free/libre analytics platform
45
*
@@ -41,5 +42,4 @@ protected function getBaseUrl()
4142

4243
return parent::getBaseUrl();
4344
}
44-
4545
}

Tracker/CustomVariables.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Matomo - free/libre analytics platform
45
*
@@ -92,6 +93,4 @@ public function getClientVisitCustomVariables()
9293
)
9394
);
9495
}
95-
96-
97-
}
96+
}

Tracker/Profiles.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Matomo - free/libre analytics platform
45
*
@@ -58,5 +59,4 @@ public function uninstall()
5859
{
5960
Db::dropTables(array($this->tableNamePrefixed));
6061
}
61-
62-
}
62+
}

Tracker/Targets.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Matomo - free/libre analytics platform
45
*
@@ -63,5 +64,4 @@ public function getTargets()
6364

6465
return $targets;
6566
}
66-
6767
}

Tracker/Trackers.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Matomo - free/libre analytics platform
45
*
@@ -45,5 +46,4 @@ public function makeTrackers()
4546

4647
return $trackers;
4748
}
48-
49-
}
49+
}

Updates/0.1.1.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Matomo - free/libre analytics platform
45
*

0 commit comments

Comments
 (0)