Skip to content

Commit

Permalink
fixes PSR error
Browse files Browse the repository at this point in the history
  • Loading branch information
AltamashShaikh committed Oct 16, 2024
1 parent 433ba59 commit 117d7de
Show file tree
Hide file tree
Showing 29 changed files with 128 additions and 67 deletions.
3 changes: 0 additions & 3 deletions API.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ private function filterAdditionalEmails($additionalEmails)
}

foreach ($additionalEmails as &$email) {

$email = trim($email);
if (empty($email)) {
$email = false;
Expand All @@ -173,7 +172,6 @@ private function filterPhoneNumbers($phoneNumbers)
$availablePhoneNumbers = (new \Piwik\Plugins\MobileMessaging\Model())->getActivatedPhoneNumbers(Piwik::getCurrentUserLogin());

foreach ($phoneNumbers as $key => &$phoneNumber) {

$phoneNumber = trim($phoneNumber);

if (!in_array($phoneNumber, $availablePhoneNumbers)) {
Expand Down Expand Up @@ -278,5 +276,4 @@ public function getTriggeredAlerts($idSites)

return $this->getModel()->getTriggeredAlerts($idSites, $login);
}

}
4 changes: 1 addition & 3 deletions Controller.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 @@ -105,7 +106,6 @@ private function findSiteName($alert)
$idSite = $this->findSiteId($alert);

if (!empty($idSite)) {

return Site::getNameFor($idSite);
}
}
Expand Down Expand Up @@ -157,14 +157,12 @@ public function formatAlerts($triggeredAlerts, $format)
return $view->render();

case 'sms':

$view = new View('@CustomAlerts/smsTriggeredAlerts');
$view->triggeredAlerts = $this->enrichTriggeredAlerts($triggeredAlerts);

return $view->render();

case 'text':

$view = new View('@CustomAlerts/textTriggeredAlerts');
$view->triggeredAlerts = $this->enrichTriggeredAlerts($triggeredAlerts);

Expand Down
1 change: 0 additions & 1 deletion CustomAlerts.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

use Piwik\Common;
use Piwik\Container\StaticContainer;
use Piwik\Option;
use Piwik\Piwik;
use Piwik\Plugins\SitesManager\API as SitesManagerApi;
use Piwik\Scheduler\Task;
Expand Down
1 change: 1 addition & 0 deletions Menu.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand Down
2 changes: 0 additions & 2 deletions Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*/
class Model
{

public static function install()
{
$tableAlert = "`idalert` INT NOT NULL PRIMARY KEY ,
Expand Down Expand Up @@ -434,5 +433,4 @@ public function deleteTriggeredAlertsForSite($idSite)
{
$this->getDb()->query("DELETE FROM " . Common::prefixTable("alert_triggered") . " WHERE idsite = ?", $idSite);
}

}
2 changes: 0 additions & 2 deletions Notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ private function groupAlertsPerEmailRecipient($triggeredAlerts)
$alertsPerEmail = array();

foreach ($triggeredAlerts as $triggeredAlert) {

$emails = $this->getEmailRecipientsForAlert($triggeredAlert);

foreach ($emails as $mail) {
Expand Down Expand Up @@ -189,7 +188,6 @@ private function groupAlertsPerSmsRecipient($triggeredAlerts)
$recipients = array();

foreach ($triggeredAlerts as $triggeredAlert) {

$phoneNumbers = $triggeredAlert['phone_numbers'];

if (empty($phoneNumbers)) {
Expand Down
2 changes: 0 additions & 2 deletions Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Piwik\Context;
use Piwik\DataTable;
use Piwik\Date;
use Piwik\Option;
use Piwik\Piwik;
use Piwik\Plugins\API\ProcessedReport;
use Piwik\Scheduler\RetryableException;
Expand Down Expand Up @@ -453,5 +452,4 @@ protected function triggerAlert($alert, $idSite, $valueNew, $valueOld)
{
$this->getModel()->triggerAlert($alert['idalert'], $idSite, $valueNew, $valueOld, Date::now()->getDatetime());
}

}
3 changes: 2 additions & 1 deletion Tasks.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 @@ -67,4 +68,4 @@ private function runAlerts($period, $idSite)
$this->processor->processAlerts($period, (int) $idSite);
$this->notifier->sendNewAlerts($period, (int) $idSite);
}
}
}
1 change: 1 addition & 0 deletions Updates/0.0.2.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand Down
1 change: 1 addition & 0 deletions Updates/0.0.3.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand Down
1 change: 1 addition & 0 deletions Updates/0.0.4.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand Down
1 change: 1 addition & 0 deletions Updates/0.0.5.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand Down
1 change: 1 addition & 0 deletions Updates/0.0.6.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand Down
1 change: 1 addition & 0 deletions Updates/0.0.7.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand Down
7 changes: 5 additions & 2 deletions Updates/0.0.8.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,8 +40,10 @@ public function getMigrations(Updater $updater)
$triggeredTable = Common::prefixTable('alert_triggered');

return array(
$this->migration->db->sql("RENAME TABLE `" . Common::prefixTable('alert_log') . "` TO `" . Common::prefixTable('alert_triggered') . "`",
array(DbMigration::ERROR_CODE_DUPLICATE_COLUMN, DbMigration::ERROR_CODE_TABLE_NOT_EXISTS, DbMigration::ERROR_CODE_TABLE_EXISTS)),
$this->migration->db->sql(
"RENAME TABLE `" . Common::prefixTable('alert_log') . "` TO `" . Common::prefixTable('alert_triggered') . "`",
array(DbMigration::ERROR_CODE_DUPLICATE_COLUMN, DbMigration::ERROR_CODE_TABLE_NOT_EXISTS, DbMigration::ERROR_CODE_TABLE_EXISTS)
),
$this->migration->db->addColumns('alert_triggered', array(
'name' => 'VARCHAR(100) NOT NULL',
'login' => 'VARCHAR(100) NOT NULL',
Expand Down
1 change: 1 addition & 0 deletions Updates/0.1.10.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand Down
1 change: 1 addition & 0 deletions Updates/0.1.17.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand Down
1 change: 1 addition & 0 deletions Updates/0.1.8.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand Down
1 change: 0 additions & 1 deletion Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public function filterPhoneNumbers($phoneNumbers)
$availablePhoneNumbers = (new \Piwik\Plugins\MobileMessaging\Model())->getActivatedPhoneNumbers(Piwik::getCurrentUserLogin());

foreach ($phoneNumbers as $key => &$phoneNumber) {

$phoneNumber = trim($phoneNumber);

if (!in_array($phoneNumber, $availablePhoneNumbers)) {
Expand Down
1 change: 1 addition & 0 deletions tests/Fixtures/CustomAlerts.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand Down
48 changes: 36 additions & 12 deletions tests/Integration/ApiTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand All @@ -18,7 +19,6 @@
*/
class ApiTest extends BaseTest
{

public function setUp(): void
{
parent::setUp();
Expand All @@ -39,17 +39,29 @@ protected function createAlert(
$reportCondition = 'matches_exactly',
$emails = array('[email protected]', '[email protected]'),
$comparedTo = 1
)
{
) {
if (is_null($idSites)) {
$idSites = $this->idSite;
}

// those should be dropped by the api as they do not exist in Piwik
$phoneNumbers = array('+1234567890', '1234567890');

$id = $this->api->addAlert($name, $idSites, $period, 0, $emails, $phoneNumbers, $metric, $metricCondition,
$metricMatched = 5, $comparedTo, $report, $reportCondition, 'Piwik');
$id = $this->api->addAlert(
$name,
$idSites,
$period,
0,
$emails,
$phoneNumbers,
$metric,
$metricCondition,
$metricMatched = 5,
$comparedTo,
$report,
$reportCondition,
'Piwik'
);
return $id;
}

Expand Down Expand Up @@ -164,8 +176,7 @@ protected function assertIsAlert(
$report = 'MultiSites_getOne',
$reportCondition = 'matches_exactly',
$reportMatched = 'Piwik'
)
{
) {
if (is_null($idSites)) {
$idSites = array($this->idSite);
}
Expand Down Expand Up @@ -211,8 +222,7 @@ protected function editAlert(
$metricCondition = 'less_than',
$reportCondition = 'matches_exactly',
$emails = array('[email protected]', '[email protected]')
)
{
) {
if (is_null($idSites)) {
$idSites = $this->idSite;
}
Expand All @@ -221,8 +231,22 @@ protected function editAlert(
$phoneNumbers = array('+1234567890', '1234567890');
$comparedTo = 1;

$id = $this->api->editAlert($id, $name, $idSites, $period, 0, $emails, $phoneNumbers, $metric, $metricCondition,
$metricMatched = 5, $comparedTo, $report, $reportCondition, 'Piwik');
$id = $this->api->editAlert(
$id,
$name,
$idSites,
$period,
0,
$emails,
$phoneNumbers,
$metric,
$metricCondition,
$metricMatched = 5,
$comparedTo,
$report,
$reportCondition,
'Piwik'
);
return $id;
}

Expand Down Expand Up @@ -571,4 +595,4 @@ public function test_getTriggeredAlerts_ShouldReturnAllThatMatchesLoginAndIdSite
$triggeredAlerts = $this->api->getTriggeredAlerts(array(1));
$this->assertCount(0, $triggeredAlerts);
}
}
}
3 changes: 2 additions & 1 deletion tests/Integration/BaseTest.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,4 +76,4 @@ protected function setUser()
FakeAccess::$idSitesView = array(99);
FakeAccess::$identity = 'aUser';
}
}
}
7 changes: 2 additions & 5 deletions tests/Integration/ControllerTest.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 @@ -108,8 +109,7 @@ private function buildAlert(
$report = 'MultiSites_getOne',
$reportCondition = 'matches_exactly',
$reportMatched = 'Piwik'
)
{
) {
return array(
'idalert' => $id,
'idsite' => $idSite,
Expand Down Expand Up @@ -192,7 +192,6 @@ public function test_formatAlerts_asHtml()
FORMATTED;

$this->assertEquals($expected, $rendered, "Got following HTML response: " . var_export($rendered, true));

}

public function test_formatAlertsNoConditions_asHtml()
Expand Down Expand Up @@ -227,7 +226,6 @@ public function test_formatAlertsNoConditions_asHtml()
FORMATTED;

$this->assertEquals($expected, $rendered, "Got following HTML response: " . var_export($rendered, true));

}

public function test_enrichTriggeredAlerts_shouldEnrichAlerts_IfReportExistsAndMetricIsValid()
Expand Down Expand Up @@ -341,5 +339,4 @@ public function test_enrichTriggeredAlerts_shouldEnrichAlerts_IfReportExistsAndM

$this->assertEquals($alerts, $enriched);
}

}
20 changes: 17 additions & 3 deletions tests/Integration/CustomAlertsTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Matomo - free/libre analytics platform
*
Expand All @@ -10,7 +11,6 @@

use Piwik\Container\StaticContainer;
use Piwik\Date;
use Piwik\Option;
use Piwik\Piwik;
use Piwik\Plugins\CustomAlerts\CustomAlerts;
use Piwik\Scheduler\Task;
Expand Down Expand Up @@ -89,8 +89,22 @@ private function createAlert($name, $phoneNumbers, $idSites = array(1), $login =
$login = Piwik::getCurrentUserLogin();
}

$id = $this->model->createAlert($name, $idSites, $login, 'week', 0, $emails, $phoneNumbers, 'nb_visits',
'less_than', 5, $comparedTo = 7, $report, 'matches_exactly', 'Piwik');
$id = $this->model->createAlert(
$name,
$idSites,
$login,
'week',
0,
$emails,
$phoneNumbers,
'nb_visits',
'less_than',
5,
$comparedTo = 7,
$report,
'matches_exactly',
'Piwik'
);

return $this->model->getAlert($id);
}
Expand Down
Loading

0 comments on commit 117d7de

Please sign in to comment.