Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds test for phpcs using Matomo coding standards, #PG-3751 #547

Merged
merged 31 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a4cbe27
Adds test for phpcs using Matomo coding standards, #PG-3751
AltamashShaikh Aug 19, 2024
6753775
changes for test to work
AltamashShaikh Aug 19, 2024
429878d
Debug command added
AltamashShaikh Aug 19, 2024
9365b09
More debug statement
AltamashShaikh Aug 19, 2024
7c4cdb7
more debug
AltamashShaikh Aug 19, 2024
e5c35e0
Debug statement
AltamashShaikh Aug 19, 2024
d97352e
debug changes
AltamashShaikh Aug 19, 2024
a316a55
debug changes
AltamashShaikh Aug 19, 2024
bf6d29d
print path
AltamashShaikh Aug 19, 2024
a38c435
fixes to use matomo-coding-standard
AltamashShaikh Aug 20, 2024
6cd41a7
Uses matomo-coding-standards
AltamashShaikh Aug 20, 2024
b1f7846
gitignored unwanted vendor folders
AltamashShaikh Aug 22, 2024
274b33a
gitignored slevomat
AltamashShaikh Aug 22, 2024
a617569
Formats more files as per PHPCS
AltamashShaikh Aug 22, 2024
1422dcd
Updated gitignored
AltamashShaikh Aug 22, 2024
f1e2f54
Updated phpcs.xml
AltamashShaikh Aug 22, 2024
c1a6518
Fixes formatting error
AltamashShaikh Aug 22, 2024
a5eb299
Changes to include matomo-coding-standard in GH action directly
AltamashShaikh Sep 3, 2024
a5f379c
fixes error
AltamashShaikh Sep 3, 2024
b90f957
Reverted vendor changes
AltamashShaikh Sep 3, 2024
197e833
Updated ruleset
AltamashShaikh Sep 4, 2024
47f5f88
Added matomo as ref
AltamashShaikh Sep 4, 2024
e45d5bc
Updated lineLimit to 200
AltamashShaikh Sep 4, 2024
23ba3ef
Fixes lineLength issue
AltamashShaikh Sep 4, 2024
085eb54
Merge branch '5.x-dev' into spice-psr-check-coding-standard
AltamashShaikh Sep 4, 2024
4e07d4a
Updated ignore list
AltamashShaikh Sep 4, 2024
b9ea8aa
Merge branch 'spice-psr-check-coding-standard' of github.com:matomo-o…
AltamashShaikh Sep 4, 2024
fb6922d
Composer changes reverted
AltamashShaikh Sep 4, 2024
c54849a
Updated .gitignore
AltamashShaikh Sep 5, 2024
1268d30
Changed order of composer install after php install
AltamashShaikh Sep 5, 2024
ae4de50
Removed blank line
AltamashShaikh Sep 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/workflows/phpcs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: PHPCS check

on: pull_request

permissions:
actions: read
checks: read
contents: read
deployments: none
issues: read
packages: none
pull-requests: read
repository-projects: none
security-events: none
statuses: read

jobs:
phpcs:
name: PHPCS
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
lfs: false
persist-credentials: false
- name: Install dependencies
run:
composer --no-plugins config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true -n;
composer config repositories.matomo-coding-standards vcs https://github.com/matomo-org/matomo-coding-standards -n;
composer require matomo-org/matomo-coding-standards:dev-master;
composer install --dev --prefer-dist --no-progress --no-suggest
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
tools: cs2pr
AltamashShaikh marked this conversation as resolved.
Show resolved Hide resolved
- name: Check PHP code styles
id: phpcs
run: ./vendor/bin/phpcs --report-full --standard=phpcs.xml --report-checkstyle=./phpcs-report.xml
- name: Show PHPCS results in PR
if: ${{ always() && steps.phpcs.outcome == 'failure' }}
run: cs2pr ./phpcs-report.xml --prepend-filename
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,11 @@ vendor/**/composer.lock
/vue/dist/*.common.js
/vue/dist/*.map
/vue/dist/*.development.*
vendor/bin/phpcs
vendor/bin/phpcbf
vendor/dealerdirect
vendor/matomo-org/matomo-coding-standards
vendor/phpstan
vendor/slevomat
vendor/squizlabs
phpcs-report.xml
AltamashShaikh marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 2 additions & 1 deletion ApiQuotaHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/

namespace Piwik\Plugins\GoogleAnalyticsImporter;

/**
Expand All @@ -17,7 +18,7 @@ class ApiQuotaHelper
* Calculate the daily maximum api quota available for the instance
* @return int
*/
public function getMaxDailyApiQuota() : int
public function getMaxDailyApiQuota(): int
{
//Local installation. No limitations from google applicable
return -1;
Expand Down
1 change: 1 addition & 0 deletions CannotImportCustomDimensionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/

namespace Piwik\Plugins\GoogleAnalyticsImporter;

class CannotImportCustomDimensionException extends \Exception
Expand Down
1 change: 1 addition & 0 deletions CannotImportCustomDimensionGA4Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/

namespace Piwik\Plugins\GoogleAnalyticsImporter;

class CannotImportCustomDimensionGA4Exception extends \Exception
Expand Down
1 change: 1 addition & 0 deletions CannotImportGoalException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/

namespace Piwik\Plugins\GoogleAnalyticsImporter;

class CannotImportGoalException extends \Exception
Expand Down
1 change: 1 addition & 0 deletions CannotProcessImportException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/

namespace Piwik\Plugins\GoogleAnalyticsImporter;

class CannotProcessImportException extends \Exception
Expand Down
8 changes: 6 additions & 2 deletions Commands/ArchiveImportedData.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,29 @@
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/

namespace Piwik\Plugins\GoogleAnalyticsImporter\Commands;

use Piwik\Container\StaticContainer;
use Piwik\Plugin\ConsoleCommand;
use Piwik\Plugins\GoogleAnalyticsImporter\ImportStatus;
use Piwik\Plugins\GoogleAnalyticsImporter\Logger\LogToSingleFileProcessor;
use Piwik\Plugins\GoogleAnalyticsImporter\Tasks;

class ArchiveImportedData extends ConsoleCommand
{
protected function configure()
{
$this->setName('googleanalyticsimporter:archive-imported-data');
$this->setDescription('Initiates core:archive for an imported site. This is run automatically every day, but can be run manually if needed.' . ' All it really does is call core:archive w/ a few custom parameters so data from years back gets archived.');
$this->setDescription(
'Initiates core:archive for an imported site. This is run automatically every day, but can be run manually if needed.' . ' All it really does is call core:archive w/ a few custom parameters so data from years back gets archived.'
);
$this->addRequiredValueOption('idSite', null, 'The ID of the imported site to initiate archiving for.');
}
/**
* @return int
*/
protected function doExecute() : int
protected function doExecute(): int
{
$input = $this->getInput();
$output = $this->getOutput();
Expand Down
4 changes: 3 additions & 1 deletion Commands/GenerateGaTestData.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/

namespace Piwik\Plugins\GoogleAnalyticsImporter\Commands;

use Piwik\Common;
Expand All @@ -14,6 +15,7 @@
use Piwik\Http;
use Piwik\Plugin\ConsoleCommand;
use Piwik\Log\LoggerInterface;

class GenerateGaTestData extends ConsoleCommand
{
private $visitorIdSeeds = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25];
Expand Down Expand Up @@ -137,7 +139,7 @@ public function isEnabled()
{
return Development::isEnabled();
}
protected function doExecute() : int
protected function doExecute(): int
{
$input = $this->getInput();
$output = $this->getOutput();
Expand Down
21 changes: 17 additions & 4 deletions Commands/ImportGA4Reports.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/

namespace Piwik\Plugins\GoogleAnalyticsImporter\Commands;

use Piwik\Config;
Expand All @@ -28,6 +29,7 @@
use Piwik\Plugins\GoogleAnalyticsImporter\ImportWasCancelledException;
use Piwik\Plugins\GoogleAnalyticsImporter\Logger\LogToSingleFileProcessor;
use Piwik\Plugins\GoogleAnalyticsImporter\Tasks;

require_once __DIR__ . '/../vendor/autoload.php';
class ImportGA4Reports extends ConsoleCommand
{
Expand All @@ -39,16 +41,27 @@ protected function configure()
$this->addRequiredValueOption('streamIds', null, 'The streamId for which you want to pull data. For multiple streams, use comma separated streamIds. By default it pulls data for all streams');
$this->addRequiredValueOption('dates', null, 'The dates to import, eg, 2015-03-04,2015-04-12.');
$this->addRequiredValueOption('idsite', null, 'The site to import into. This will attempt to continue an existing import.');
$this->addRequiredValueOption('cvar-count', null, 'The number of custom variables to support (if not supplied defaults to however many are currently available). ' . 'NOTE: This option will attempt to set the number of custom variable slots which should be done with care on an existing system.');
$this->addRequiredValueOption(
'cvar-count',
null,
'The number of custom variables to support (if not supplied defaults to however many are currently available). ' .
'NOTE: This option will attempt to set the number of custom variable slots which should be done with care on an existing system.'
);
$this->addNoValueOption('skip-archiving', null, 'Skips launching archiving at the end of an import. Use this only if executing PHP from the command line results in an error on your system.');
$this->addNoValueOption('mobile-app', null, 'If this option is used, the Matomo measurable that is created will be a mobile app. Requires the MobileAppMeasurable be activated.');
$this->addRequiredValueOption('timezone', null, 'If your GA property\'s timezone is set to a value that is not a timezone recognized by PHP, you can specify a valid timezone manually with this option.');
$this->addRequiredValueOption('extra-custom-dimension', null, 'Map extra google analytics dimensions as matomo dimensions. This can be used to import dimensions like age & gender. Values should be like "gaDimension,dimensionScope", for example "userAgeBracket,visit".', [], \true);
$this->addRequiredValueOption(
'extra-custom-dimension',
null,
'Map extra google analytics dimensions as matomo dimensions. This can be used to import dimensions like age & gender. Values should be like "gaDimension,dimensionScope", for example "userAgeBracket,visit".',
[],
\true
);
}
/**
* @return int
*/
protected function doExecute() : int
protected function doExecute(): int
{
try {
return $this->executeImpl();
Expand All @@ -60,7 +73,7 @@ protected function doExecute() : int
return self::FAILURE;
}
}
protected function executeImpl() : int
protected function executeImpl(): int
{
$input = $this->getInput();
$output = $this->getOutput();
Expand Down
6 changes: 4 additions & 2 deletions Commands/ImportReports.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/

namespace Piwik\Plugins\GoogleAnalyticsImporter\Commands;

use Piwik\Config;
Expand All @@ -27,6 +28,7 @@
use Piwik\Plugins\WebsiteMeasurable\Type;
use Piwik\Site;
use Piwik\Timer;

require_once __DIR__ . '/../vendor/autoload.php';
// TODO: make sure same version of google api client is used in this & SearchEngineKeywordsPerformance
// (may have to add test in target plugin)
Expand All @@ -51,7 +53,7 @@ protected function configure()
/**
* @return int
*/
protected function doExecute() : int
protected function doExecute(): int
{
$this->getOutput()->writeln("GA3 Import disabled");
return self::FAILURE;
Expand All @@ -65,7 +67,7 @@ protected function doExecute() : int
return self::FAILURE;
}
}
protected function executeImpl() : int
protected function executeImpl(): int
{
$isAccountDeduced = \false;
$input = $this->getInput();
Expand Down
76 changes: 68 additions & 8 deletions Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,18 @@
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/

namespace Piwik\Plugins\GoogleAnalyticsImporter;

use Piwik\Common;
use Piwik\Container\StaticContainer;
use Piwik\DataTable\Renderer\Json;
use Piwik\Date;
use Piwik\Http;
use Piwik\Nonce;
use Piwik\Notification;
use Piwik\Piwik;
use Piwik\Plugin\Manager;
use Piwik\Plugins\ConnectAccounts\ConnectAccounts;
use Piwik\Plugins\ConnectAccounts\helpers\ConnectHelper;
use Piwik\Plugins\ConnectAccounts\Strategy\Google\GoogleConnect;
use Piwik\Plugins\GoogleAnalyticsImporter\Commands\ImportGA4Reports;
use Piwik\Plugins\GoogleAnalyticsImporter\Commands\ImportReports;
use Piwik\Plugins\GoogleAnalyticsImporter\Google\Authorization;
use Piwik\Plugins\GoogleAnalyticsImporter\Google\AuthorizationGA4;
use Piwik\Plugins\GoogleAnalyticsImporter\Input\EndDate;
Expand All @@ -34,9 +30,10 @@
use Piwik\Url;
use Piwik\Log\LoggerInterface;
use Piwik\Plugins\SitesManager\SitesManager;

class Controller extends \Piwik\Plugin\ControllerAdmin
{
const OAUTH_STATE_NONCE_NAME = 'GoogleAnalyticsImporter.oauthStateNonce';
public const OAUTH_STATE_NONCE_NAME = 'GoogleAnalyticsImporter.oauthStateNonce';
public function index($errorMessage = \false)
{
Piwik::checkUserHasSuperUserAccess();
Expand Down Expand Up @@ -105,7 +102,69 @@ public function index($errorMessage = \false)
}
$configureConnectionProps = \Piwik\Plugins\GoogleAnalyticsImporter\GoogleAnalyticsImporter::getConfigureConnectProps($nonce);
$isClientConfigurable = StaticContainer::get('GoogleAnalyticsImporter.isClientConfigurable');
return $this->renderTemplate('index', ['isClientConfigurable' => $isClientConfigurable, 'isConfigured' => $authorization->hasAccessToken(), 'auth_nonce' => Nonce::getNonce('gaimport.auth', 1200), 'hasClientConfiguration' => $hasClientConfiguration, 'nonce' => $nonce, 'statuses' => $statuses, 'stopImportNonce' => $stopImportNonce, 'startImportNonce' => $startImportNonce, 'changeImportEndDateNonce' => $changeImportEndDateNonce, 'resumeImportNonce' => $resumeImportNonce, 'scheduleReImportNonce' => $scheduleReImportNonce, 'maxEndDateDesc' => $maxEndDateDesc, 'importOptionsUA' => array('ua' => Piwik::translate('GoogleAnalyticsImporter_SelectImporterUATitle')), 'importOptionsGA4' => ['ga4' => Piwik::translate('GoogleAnalyticsImporter_SelectImporterGA4Title')], 'extraCustomDimensionsField' => ['field1' => ['key' => 'gaDimension', 'title' => Piwik::translate('GoogleAnalyticsImporter_GADimension'), 'uiControl' => 'text', 'availableValues' => null], 'field2' => ['key' => 'dimensionScope', 'title' => Piwik::translate('GoogleAnalyticsImporter_DimensionScope'), 'uiControl' => 'select', 'availableValues' => ['visit' => Piwik::translate('General_Visit'), 'action' => Piwik::translate('General_Action')]]], 'extraCustomDimensionsFieldGA4' => ['field1' => ['key' => 'ga4Dimension', 'title' => Piwik::translate('GoogleAnalyticsImporter_GA4Dimension'), 'uiControl' => 'text', 'availableValues' => null], 'field2' => ['key' => 'dimensionScope', 'title' => Piwik::translate('GoogleAnalyticsImporter_DimensionScope'), 'uiControl' => 'select', 'availableValues' => ['visit' => Piwik::translate('General_Visit'), 'action' => Piwik::translate('General_Action')]]], 'streamIdsFieldGA4' => ['field1' => ['key' => 'streamId', 'title' => Piwik::translate('GoogleAnalyticsImporter_StreamId'), 'uiControl' => 'text', 'availableValues' => null]], 'extensions' => self::getComponentExtensions(), 'configureConnectionProps' => $configureConnectionProps]);
return $this->renderTemplate(
'index',
[
'isClientConfigurable' => $isClientConfigurable,
'isConfigured' => $authorization->hasAccessToken(),
'auth_nonce' => Nonce::getNonce('gaimport.auth', 1200),
'hasClientConfiguration' => $hasClientConfiguration,
'nonce' => $nonce,
'statuses' => $statuses,
'stopImportNonce' => $stopImportNonce,
'startImportNonce' => $startImportNonce,
'changeImportEndDateNonce' => $changeImportEndDateNonce,
'resumeImportNonce' => $resumeImportNonce,
'scheduleReImportNonce' => $scheduleReImportNonce,
'maxEndDateDesc' => $maxEndDateDesc,
'importOptionsUA' => array(
'ua' => Piwik::translate('GoogleAnalyticsImporter_SelectImporterUATitle')),
'importOptionsGA4' => [
'ga4' => Piwik::translate('GoogleAnalyticsImporter_SelectImporterGA4Title')],
'extraCustomDimensionsField' => [
'field1' => [
'key' => 'gaDimension',
'title' => Piwik::translate('GoogleAnalyticsImporter_GADimension'),
'uiControl' => 'text',
'availableValues' => null
],
'field2' => [
'key' => 'dimensionScope',
'title' => Piwik::translate('GoogleAnalyticsImporter_DimensionScope'),
'uiControl' => 'select',
'availableValues' => [
'visit' => Piwik::translate('General_Visit'),
'action' => Piwik::translate('General_Action')]
]
],
'extraCustomDimensionsFieldGA4' => [
'field1' => [
'key' => 'ga4Dimension',
'title' => Piwik::translate('GoogleAnalyticsImporter_GA4Dimension'),
'uiControl' => 'text',
'availableValues' => null
],
'field2' => [
'key' => 'dimensionScope',
'title' => Piwik::translate('GoogleAnalyticsImporter_DimensionScope'),
'uiControl' => 'select',
'availableValues' => [
'visit' => Piwik::translate('General_Visit'),
'action' => Piwik::translate('General_Action')]
]
],
'streamIdsFieldGA4' => [
'field1' => [
'key' => 'streamId',
'title' => Piwik::translate('GoogleAnalyticsImporter_StreamId'),
'uiControl' => 'text',
'availableValues' => null
]
],
'extensions' => self::getComponentExtensions(),
'configureConnectionProps' => $configureConnectionProps
]
);
}
public function forwardToAuth()
{
Expand Down Expand Up @@ -457,10 +516,11 @@ public function displayConfigureImportNotification()
* @return array Map of component extensions. Like [ [ 'plugin' => 'PluginName', 'component' => 'ComponentName' ] ]
* See {@link https://developer.matomo.org/guides/in-depth-vue#allowing-plugins-to-add-content-to-your-vue-components the developer documentation} for more information.
*/
public static function getComponentExtensions($isNoDataPage = \false) : array
public static function getComponentExtensions($isNoDataPage = \false): array
{
$componentExtensions = [];
Piwik::postEvent('GoogleAnalyticsImporter.getGoogleConfigComponentExtensions', [&$componentExtensions, $isNoDataPage]);

return $componentExtensions;
}
private function getStreamIdsFromRequest()
Expand Down
2 changes: 2 additions & 0 deletions Diagnostic/RequiredExecutablesCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/

namespace Piwik\Plugins\GoogleAnalyticsImporter\Diagnostic;

use Piwik\CliMulti\CliPhp;
use Piwik\Plugins\Diagnostics\Diagnostic\Diagnostic;
use Piwik\Plugins\Diagnostics\Diagnostic\DiagnosticResult;
use Piwik\SettingsServer;
use Piwik\Translation\Translator;

class RequiredExecutablesCheck implements Diagnostic
{
/**
Expand Down
Loading
Loading