Skip to content

Commit

Permalink
Merge pull request #547 from matomo-org/spice-psr-check-coding-standard
Browse files Browse the repository at this point in the history
Adds test for phpcs using Matomo coding standards, #PG-3751
  • Loading branch information
AltamashShaikh authored Sep 26, 2024
2 parents b3c4c62 + ae4de50 commit e9b088f
Show file tree
Hide file tree
Showing 116 changed files with 918 additions and 269 deletions.
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: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
tools: cs2pr
- 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: 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
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
2 changes: 2 additions & 0 deletions Diagnostic/RequiredFunctionsCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/

namespace Piwik\Plugins\GoogleAnalyticsImporter\Diagnostic;

use Piwik\Plugins\Diagnostics\Diagnostic\Diagnostic;
use Piwik\Plugins\Diagnostics\Diagnostic\DiagnosticResult;
use Piwik\Translation\Translator;

class RequiredFunctionsCheck implements Diagnostic
{
/**
Expand Down
1 change: 1 addition & 0 deletions Exceptions/CloudApiQuotaExceeded.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Piwik\Plugins\GoogleAnalyticsImporter\Exceptions;

use Piwik\Piwik;

class CloudApiQuotaExceeded extends \RuntimeException
{
public function __construct($limit = 0)
Expand Down
Loading

0 comments on commit e9b088f

Please sign in to comment.