Skip to content

Commit

Permalink
Making PHPCS changes
Browse files Browse the repository at this point in the history
  • Loading branch information
snake14 committed Oct 20, 2024
1 parent 16f18f2 commit 06d66c1
Show file tree
Hide file tree
Showing 36 changed files with 125 additions and 79 deletions.
2 changes: 1 addition & 1 deletion AllowListIpRange.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand Down Expand Up @@ -33,5 +34,4 @@ public function isAllowed($ip)

return false;
}

}
19 changes: 10 additions & 9 deletions BanIpNotificationEmail.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand All @@ -9,7 +10,6 @@
namespace Piwik\Plugins\TrackingSpamPrevention;

use Piwik\Common;
use Piwik\Config;
use Piwik\Log;
use Piwik\Mail;
use Piwik\Piwik;
Expand All @@ -27,15 +27,17 @@ public function send($ipRange, $ip, $email, $maxActionsAllowed, $locationData, $
$mail->addTo($email);
$mail->setSubject('An IP was banned as too many actions were tracked.');
$mail->setDefaultFromPiwik();
if (empty($mail->getFromName()) || in_array($mail->getFromName(), [
if (
empty($mail->getFromName()) || in_array($mail->getFromName(), [
'CoreHome_WebAnalyticsReports',
'TagManager_MatomoTagName'
])) {
])
) {
$mail->setFrom($mail->getFrom(), 'Web Analytics Reports');
}

$mailBody = 'This is for your information. The following IP was banned because visit tried to track more than ' . Common::sanitizeInputValue($maxActionsAllowed) . ' actions:';
$mailBody .= PHP_EOL.PHP_EOL.'"' . Common::sanitizeInputValue($ipRange) . '"'.PHP_EOL;
$mailBody .= PHP_EOL . PHP_EOL . '"' . Common::sanitizeInputValue($ipRange) . '"' . PHP_EOL;
$instanceId = SettingsPiwik::getPiwikInstanceId();


Expand All @@ -58,12 +60,12 @@ public function send($ipRange, $ip, $email, $maxActionsAllowed, $locationData, $
}

if (!empty($instanceId)) {
$mailBody .= PHP_EOL.'Instance ID: ' . Common::sanitizeInputValue($instanceId);
$mailBody .= PHP_EOL . 'Instance ID: ' . Common::sanitizeInputValue($instanceId);
}
$mailBody .= PHP_EOL.'Current date (UTC): ' . Common::sanitizeInputValue($nowDateTime) . '
$mailBody .= PHP_EOL . 'Current date (UTC): ' . Common::sanitizeInputValue($nowDateTime) . '
IP as detected in header: ' . Common::sanitizeInputValue($ip) . '
GET request info: ' . json_encode($get) . '
POST request info: ' . json_encode($post). PHP_EOL;
POST request info: ' . json_encode($post) . PHP_EOL;

if (!empty($locationData)) {
$mailBody .= 'Geo IP info: ' . json_encode($locationData) . PHP_EOL;
Expand All @@ -82,9 +84,8 @@ public function send($ipRange, $ip, $email, $maxActionsAllowed, $locationData, $
$mail->send();
}

$a=$mail->getBodyText();
$a = $mail->getBodyText();

return $mail->getBodyText();
}

}
2 changes: 1 addition & 1 deletion BlockedGeoIp.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand Down Expand Up @@ -75,5 +76,4 @@ public function isExcludedProvider($ip, $language)

return false;
}

}
7 changes: 4 additions & 3 deletions BlockedIpRanges.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand All @@ -19,7 +20,7 @@

class BlockedIpRanges
{
const OPTION_KEY = 'TrackingSpamBlockedIpRanges';
public const OPTION_KEY = 'TrackingSpamBlockedIpRanges';

/**
* @var IpRangeProviderInterface[]
Expand Down Expand Up @@ -155,7 +156,8 @@ public function banIp($ip)
return $ranges;
}

public function unsetAllIpRanges() {
public function unsetAllIpRanges()
{
$this->setBlockedRanges([]);
}

Expand Down Expand Up @@ -190,5 +192,4 @@ public function updateBlockedIpRanges()
}
$this->setBlockedRanges($indexedRange);
}

}
18 changes: 15 additions & 3 deletions BlockedIpRanges/Aws.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand All @@ -16,8 +17,20 @@ public function getRanges(): array
{
$ranges = [];

$aws = Http::sendHttpRequest('https://ip-ranges.amazonaws.com/ip-ranges.json', 120, null, null, 0,
false, false, false, 'GET', null, null, false);
$aws = Http::sendHttpRequest(
'https://ip-ranges.amazonaws.com/ip-ranges.json',
120,
null,
null,
0,
false,
false,
false,
'GET',
null,
null,
false
);

if (empty($aws)) {
throw new \Exception('Failed to retrieve AWS IP ranges');
Expand Down Expand Up @@ -52,5 +65,4 @@ public function getRanges(): array

return $ranges;
}

}
12 changes: 8 additions & 4 deletions BlockedIpRanges/Azure.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand Down Expand Up @@ -41,7 +42,7 @@ public function getRanges(): array
$ranges[] = $ip;
}
}

return $ranges;
}

Expand All @@ -61,8 +62,12 @@ public function getDownloadUrl()
$prefixStrLen = mb_strlen($prefixUrl, 'UTF-8');
$posStart = mb_strpos($contentDownloadPage, $prefixUrl . 'https://download.microsoft.com/download/', 0, 'UTF-8');
$posEnd = mb_strpos($contentDownloadPage, '.json"', $posStart + $prefixStrLen, 'UTF-8'); // we don't want to match the " in href="
$contentDownloadPage = mb_substr($contentDownloadPage, $posStart + $prefixStrLen,
$posEnd - $posStart - $prefixStrLen, 'UTF-8');
$contentDownloadPage = mb_substr(
$contentDownloadPage,
$posStart + $prefixStrLen,
$posEnd - $posStart - $prefixStrLen,
'UTF-8'
);
$downloadUrl = trim($contentDownloadPage, '="' . "'") . '.json';
$downloadUrl = trim($downloadUrl);

Expand All @@ -76,5 +81,4 @@ public function getDownloadUrl()

return $downloadUrl;
}

}
2 changes: 1 addition & 1 deletion BlockedIpRanges/DigitalOcean.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand Down Expand Up @@ -42,5 +43,4 @@ public function getRanges(): array

return $ranges;
}

}
3 changes: 1 addition & 2 deletions BlockedIpRanges/ExceptionRange.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand All @@ -13,10 +14,8 @@
*/
class ExceptionRange implements IpRangeProviderInterface
{

public function getRanges(): array
{
throw new \Exception('Failed to get any range');
}

}
2 changes: 1 addition & 1 deletion BlockedIpRanges/Gcloud.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand Down Expand Up @@ -47,5 +48,4 @@ public function getRanges(): array

return $ranges;
}

}
2 changes: 1 addition & 1 deletion BlockedIpRanges/IpRangeProviderInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand All @@ -11,5 +12,4 @@
interface IpRangeProviderInterface
{
public function getRanges(): array;

}
2 changes: 1 addition & 1 deletion BlockedIpRanges/Oracle.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand Down Expand Up @@ -47,5 +48,4 @@ public function getRanges(): array

return $ranges;
}

}
2 changes: 1 addition & 1 deletion BlockedIpRanges/VariableRange.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand Down Expand Up @@ -27,5 +28,4 @@ public function getRanges(): array
{
return $this->ranges;
}

}
2 changes: 1 addition & 1 deletion BrowserDetection.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand Down Expand Up @@ -47,5 +48,4 @@ public function isLibrary($userAgent)

return $staticContainer->isLibrary();
}

}
3 changes: 2 additions & 1 deletion Commands/BlockGeoIpOrganisation.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand Down Expand Up @@ -39,7 +40,7 @@ protected function doExecute(): int

$name = $input->getOption('organisation-name');
$pluginConfig[Configuration::KEY_GEOIP_MATCH_PROVIDERS][] = mb_strtolower(trim($name));

$pluginConfig[Configuration::KEY_GEOIP_MATCH_PROVIDERS] = array_values(array_unique($pluginConfig[Configuration::KEY_GEOIP_MATCH_PROVIDERS]));

$config->TrackingSpamPrevention = $pluginConfig;
Expand Down
14 changes: 8 additions & 6 deletions Configuration.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
<?php

/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/

namespace Piwik\Plugins\TrackingSpamPrevention;

use Piwik\Config;

class Configuration
{
const DEFAULT_RANGE_THROW_EXCEPTION = 0;
const DEFAULT_RANGE_ALLOW_LIST = [''];
const DEFAULT_GEOIP_MATCH_PROVIDERS = ['alicloud', 'alibaba cloud', 'digitalocean', 'digital ocean'];
public const DEFAULT_RANGE_THROW_EXCEPTION = 0;
public const DEFAULT_RANGE_ALLOW_LIST = [''];
public const DEFAULT_GEOIP_MATCH_PROVIDERS = ['alicloud', 'alibaba cloud', 'digitalocean', 'digital ocean'];

const KEY_RANGE_THROW_EXCEPTION = 'block_cloud_sync_throw_exception_on_error';
const KEY_RANGE_ALLOW_LIST = 'iprange_allowlist';
const KEY_GEOIP_MATCH_PROVIDERS = 'block_geoip_organisations';
public const KEY_RANGE_THROW_EXCEPTION = 'block_cloud_sync_throw_exception_on_error';
public const KEY_RANGE_ALLOW_LIST = 'iprange_allowlist';
public const KEY_GEOIP_MATCH_PROVIDERS = 'block_geoip_organisations';

public function install()
{
Expand Down
2 changes: 2 additions & 0 deletions Settings/BlockCloudsSetting.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?php

/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/

namespace Piwik\Plugins\TrackingSpamPrevention\Settings;

use Piwik\Settings\Plugin\SystemSetting;
Expand Down
17 changes: 11 additions & 6 deletions SystemSettings.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand Down Expand Up @@ -116,7 +117,8 @@ public function save()
}
}

private function createExcludedCountriesSetting() {
private function createExcludedCountriesSetting()
{
return $this->makeSetting('excluded_countries', [], FieldConfig::TYPE_ARRAY, function (FieldConfig $field) {
$field->title = Piwik::translate('TrackingSpamPrevention_SettingExcludedCountriesTitle');
$field->description = Piwik::translate('TrackingSpamPrevention_SettingExcludedCountriesDescription');
Expand Down Expand Up @@ -161,7 +163,8 @@ public function transformCountryList($value)
return $value;
}

private function createIncludedCountriesSetting() {
private function createIncludedCountriesSetting()
{
return $this->makeSetting('included_countries', [], FieldConfig::TYPE_ARRAY, function (FieldConfig $field) {
$field->title = Piwik::translate('TrackingSpamPrevention_SettingIncludedCountriesTitle');
$field->description = Piwik::translate('TrackingSpamPrevention_SettingIncludedCountriesDescription');
Expand Down Expand Up @@ -190,7 +193,8 @@ private function createIncludedCountriesSetting() {
});
}

private function createBlockServerSideLibrariesSetting() {
private function createBlockServerSideLibrariesSetting()
{
return $this->makeSetting('blockServerSideLibraries', false, FieldConfig::TYPE_BOOL, function (FieldConfig $field) {
$field->title = Piwik::translate('TrackingSpamPrevention_SettingBlockServerSideLibrariesTitle');
$field->inlineHelp = Piwik::translate('TrackingSpamPrevention_SettingBlockServerSideLibrariesDescription', array('<strong>','</strong>','<br>'));
Expand All @@ -199,7 +203,8 @@ private function createBlockServerSideLibrariesSetting() {
}


private function listCountries() {
private function listCountries()
{
$regionDataProvider = StaticContainer::get(RegionDataProvider::class);
$countryList = $regionDataProvider->getCountryList();
array_walk($countryList, function (&$item, $key) {
Expand All @@ -219,7 +224,8 @@ public function getIncludedCountryCodes()
return $this->settingToCountryCodes($this->includedCountries);
}

private function settingToCountryCodes(Setting $setting) {
private function settingToCountryCodes(Setting $setting)
{
$val = $setting->getValue();

if (empty($val) || !is_array($val)) {
Expand All @@ -234,5 +240,4 @@ private function settingToCountryCodes(Setting $setting) {
}
return $codes;
}

}
Loading

0 comments on commit 06d66c1

Please sign in to comment.