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

Apply coding style around FunctionCallSignature #8 #21934

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 5 additions & 2 deletions plugins/UserId/Reports/GetUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@ public function configureView(ViewDataTable $view)
$view->config->show_insights = false;
$view->config->show_pivot_by_subtable = false;
$view->config->no_data_message = Piwik::translate('CoreHome_ThereIsNoDataForThisReport') . '<br><br>'
. sprintf(Piwik::translate('UserId_ThereIsNoDataForThisReportHelp'),
"<a target='_blank' rel='noreferrer noopener' href='" . Url::addCampaignParametersToMatomoLink('https://matomo.org/docs/user-id/') . "'>", "</a>");
. sprintf(
Piwik::translate('UserId_ThereIsNoDataForThisReportHelp'),
"<a target='_blank' rel='noreferrer noopener' href='" . Url::addCampaignParametersToMatomoLink('https://matomo.org/docs/user-id/') . "'>",
"</a>"
);

if ($view->isViewDataTableId(HtmlTable::ID)) {
$view->config->disable_row_evolution = false;
Expand Down
24 changes: 16 additions & 8 deletions plugins/UsersManager/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -521,12 +521,16 @@ public function recordAnonymousUserSettings()
$anonymousDefaultReport = Common::getRequestVar('anonymousDefaultReport');
$anonymousDefaultDate = Common::getRequestVar('anonymousDefaultDate');
$userLogin = 'anonymous';
APIUsersManager::getInstance()->setUserPreference($userLogin,
APIUsersManager::getInstance()->setUserPreference(
$userLogin,
APIUsersManager::PREFERENCE_DEFAULT_REPORT,
$anonymousDefaultReport);
APIUsersManager::getInstance()->setUserPreference($userLogin,
$anonymousDefaultReport
);
APIUsersManager::getInstance()->setUserPreference(
$userLogin,
APIUsersManager::PREFERENCE_DEFAULT_REPORT_DATE,
$anonymousDefaultDate);
$anonymousDefaultDate
);
$toReturn = $response->getResponse();
} catch (Exception $e) {
$toReturn = $response->getResponseException($e);
Expand Down Expand Up @@ -566,12 +570,16 @@ public function recordUserSettings()
'use12HourClock' => $timeFormat,
]);

APIUsersManager::getInstance()->setUserPreference($userLogin,
APIUsersManager::getInstance()->setUserPreference(
$userLogin,
APIUsersManager::PREFERENCE_DEFAULT_REPORT,
$defaultReport);
APIUsersManager::getInstance()->setUserPreference($userLogin,
$defaultReport
);
APIUsersManager::getInstance()->setUserPreference(
$userLogin,
APIUsersManager::PREFERENCE_DEFAULT_REPORT_DATE,
$defaultDate);
$defaultDate
);
$toReturn = $response->getResponse();
} catch (Exception $e) {
$toReturn = $response->getResponseException($e);
Expand Down
73 changes: 49 additions & 24 deletions plugins/UsersManager/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,10 @@ public function generateRandomTokenAuth()

private function generateTokenAuth()
{
return md5(Common::getRandomString(32,
'abcdef1234567890') . microtime(true) . Common::generateUniqId() . SettingsPiwik::getSalt());
return md5(Common::getRandomString(
32,
'abcdef1234567890'
) . microtime(true) . Common::generateUniqId() . SettingsPiwik::getSalt());
}

/**
Expand Down Expand Up @@ -340,8 +342,11 @@ public function addTokenAuth(
throw new \Exception('User ' . $login . ' does not exist');
}

BaseValidator::check('Description', $description,
[new NotEmpty(), new CharacterLength(1, self::MAX_LENGTH_TOKEN_DESCRIPTION)]);
BaseValidator::check(
'Description',
$description,
[new NotEmpty(), new CharacterLength(1, self::MAX_LENGTH_TOKEN_DESCRIPTION)]
);

if (empty($dateExpired)) {
$dateExpired = null;
Expand All @@ -354,8 +359,10 @@ public function addTokenAuth(
$tokenAuth = $this->hashTokenAuth($tokenAuth);

$db = $this->getDb();
$db->query($insertSql,
[$login, $description, $tokenAuth, $dateCreated, $dateExpired, $isSystemToken, self::TOKEN_HASH_ALGO, $secureOnly]);
$db->query(
$insertSql,
[$login, $description, $tokenAuth, $dateCreated, $dateExpired, $isSystemToken, self::TOKEN_HASH_ALGO, $secureOnly]
);

return $db->lastInsertId();
}
Expand All @@ -372,8 +379,10 @@ public function getUserTokenDescriptionByIdTokenAuth($idTokenAuth, $login)
{
$db = $this->getDb();

$token = $db->fetchRow("SELECT description FROM " . $this->tokenTable . " WHERE `idusertokenauth` = ? and login = ? LIMIT 1",
array($idTokenAuth, $login));
$token = $db->fetchRow(
"SELECT description FROM " . $this->tokenTable . " WHERE `idusertokenauth` = ? and login = ? LIMIT 1",
array($idTokenAuth, $login)
);

return $token ? $token['description'] : '';
}
Expand Down Expand Up @@ -425,25 +434,31 @@ public function deleteExpiredTokens($expiredSince)
{
$db = $this->getDb();

return $db->query("DELETE FROM " . $this->tokenTable . " WHERE `date_expired` is not null and date_expired < ?",
$expiredSince);
return $db->query(
"DELETE FROM " . $this->tokenTable . " WHERE `date_expired` is not null and date_expired < ?",
$expiredSince
);
}

public function getExpiredInvites($expiredSince)
{
$db = $this->getDb();

return $db->fetchAll("SELECT * FROM " . $this->userTable . " WHERE `invite_expired_at` is not null and invite_expired_at < ?",
$expiredSince);
return $db->fetchAll(
"SELECT * FROM " . $this->userTable . " WHERE `invite_expired_at` is not null and invite_expired_at < ?",
$expiredSince
);
}

public function checkUserHasUnexpiredToken($login)
{
$db = $this->getDb();
$expired = $this->getQueryNotExpiredToken();
$bind = array_merge(array($login), $expired['bind']);
return $db->fetchOne("SELECT idusertokenauth FROM " . $this->tokenTable . " WHERE `login` = ? and " . $expired['sql'],
$bind);
return $db->fetchOne(
"SELECT idusertokenauth FROM " . $this->tokenTable . " WHERE `login` = ? and " . $expired['sql'],
$bind
);
}

public function deleteAllTokensForUser($login)
Expand All @@ -461,8 +476,10 @@ public function getAllNonSystemTokensForLogin($login)
$expired = $this->getQueryNotExpiredToken();
$bind = array_merge(array($login), $expired['bind']);

return $db->fetchAll("SELECT * FROM " . $this->tokenTable . " WHERE `login` = ? and system_token = 0 and " . $expired['sql'] . ' order by idusertokenauth ASC',
$bind);
return $db->fetchAll(
"SELECT * FROM " . $this->tokenTable . " WHERE `login` = ? and system_token = 0 and " . $expired['sql'] . ' order by idusertokenauth ASC',
$bind
);
}

public function getAllHashedTokensForLogins($logins)
Expand All @@ -477,17 +494,21 @@ public function getAllHashedTokensForLogins($logins)
$expired = $this->getQueryNotExpiredToken();
$bind = array_merge($logins, $expired['bind']);

$tokens = $db->fetchAll("SELECT password FROM " . $this->tokenTable . " WHERE `login` IN (" . $placeholder . ") and " . $expired['sql'],
$bind);
$tokens = $db->fetchAll(
"SELECT password FROM " . $this->tokenTable . " WHERE `login` IN (" . $placeholder . ") and " . $expired['sql'],
$bind
);
return array_column($tokens, 'password');
}

public function deleteToken($idTokenAuth, $login)
{
$db = $this->getDb();

return $db->query("DELETE FROM " . $this->tokenTable . " WHERE `idusertokenauth` = ? and login = ?",
array($idTokenAuth, $login));
return $db->query(
"DELETE FROM " . $this->tokenTable . " WHERE `idusertokenauth` = ? and login = ?",
array($idTokenAuth, $login)
);
}

public function setTokenAuthWasUsed($tokenAuth, $dateLastUsed)
Expand Down Expand Up @@ -522,8 +543,10 @@ private function updateTokenAuthTable($idTokenAuth, $fields)
$bind[] = $idTokenAuth;

$db = $this->getDb();
$db->query(sprintf('UPDATE `%s` SET %s WHERE `idusertokenauth` = ?', $this->tokenTable, implode(', ', $set)),
$bind);
$db->query(
sprintf('UPDATE `%s` SET %s WHERE `idusertokenauth` = ?', $this->tokenTable, implode(', ', $set)),
$bind
);
}

public function getUserByEmail($userEmail)
Expand Down Expand Up @@ -737,8 +760,10 @@ public function deleteUserAccess($userLogin, $idSites = null)
$db->query("DELETE FROM " . Common::prefixTable("access") . " WHERE login = ?", $userLogin);
} else {
foreach ($idSites as $idsite) {
$db->query("DELETE FROM " . Common::prefixTable("access") . " WHERE idsite = ? AND login = ?",
[$idsite, $userLogin]);
$db->query(
"DELETE FROM " . Common::prefixTable("access") . " WHERE idsite = ? AND login = ?",
[$idsite, $userLogin]
);
}
}
}
Expand Down
22 changes: 16 additions & 6 deletions plugins/UsersManager/UsersManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,14 @@ public function addSystemSummaryItems(&$systemSummary)
$numUsers--;
}

$systemSummary[] = new SystemSummary\Item($key = 'users', Piwik::translate('General_NUsers', $numUsers),
$value = null, array('module' => 'UsersManager', 'action' => 'index'), $icon = 'icon-user', $order = 5);
$systemSummary[] = new SystemSummary\Item(
$key = 'users',
Piwik::translate('General_NUsers', $numUsers),
$value = null,
array('module' => 'UsersManager', 'action' => 'index'),
$icon = 'icon-user',
$order = 5
);
}

public function onPlatformInitialized()
Expand Down Expand Up @@ -175,12 +181,16 @@ public static function checkPassword($password)
Piwik::postEvent('UsersManager.checkPassword', array($password));

if (!self::isValidPasswordString($password)) {
throw new Exception(Piwik::translate('UsersManager_ExceptionInvalidPassword',
array(self::PASSWORD_MIN_LENGTH)));
throw new Exception(Piwik::translate(
'UsersManager_ExceptionInvalidPassword',
array(self::PASSWORD_MIN_LENGTH)
));
}
if (mb_strlen($password) > self::PASSWORD_MAX_LENGTH) {
throw new Exception(Piwik::translate('UsersManager_ExceptionInvalidPasswordTooLong',
array(self::PASSWORD_MAX_LENGTH)));
throw new Exception(Piwik::translate(
'UsersManager_ExceptionInvalidPasswordTooLong',
array(self::PASSWORD_MAX_LENGTH)
));
}
}

Expand Down
11 changes: 9 additions & 2 deletions plugins/UsersManager/tests/Integration/TokenSecureOnlyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,15 @@ private static function createUserAndTokens()
UsersManagerAPI::getInstance()->setUserAccess('user1', 'view', [1]);

$userModel = new UsersManagerModel();
$userModel->addTokenAuth('user1', self::$tokenSecureOnly, 'Secure Only', '2020-01-02 03:04:05',
null, false, true);
$userModel->addTokenAuth(
'user1',
self::$tokenSecureOnly,
'Secure Only',
'2020-01-02 03:04:05',
null,
false,
true
);
}
}

Expand Down
32 changes: 21 additions & 11 deletions plugins/UsersManager/tests/Integration/UsersManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,11 @@ public function testAddUserWrongEmail()
public function testAddUserLongPassword()
{
$login = "geggeqgeqag";
$this->api->addUser($login,
"geqgeagaegeqgeagaegeqgeagaegeqgeagaegeqgeagaegeqgeagaegeqgeagaegeqgeagaegeqgeagaegeqgeagaegeqgeagaeg",
"[email protected]");
$this->api->addUser(
$login,
"geqgeagaegeqgeagaegeqgeagaegeqgeagaegeqgeagaegeqgeagaegeqgeagaegeqgeagaegeqgeagaegeqgeagaegeqgeagaeg",
"[email protected]"
);
$user = $this->api->getUser($login);
$this->assertEquals($login, $user['login']);
}
Expand All @@ -269,8 +271,10 @@ public function testAddUser()
$user = $this->model->getUser($login);

// check that the date registered is correct
$this->assertTrue($time <= strtotime($user['date_registered']) && strtotime($user['date_registered']) <= time(),
"the date_registered " . strtotime($user['date_registered']) . " is different from the time() " . time());
$this->assertTrue(
$time <= strtotime($user['date_registered']) && strtotime($user['date_registered']) <= time(),
"the date_registered " . strtotime($user['date_registered']) . " is different from the time() " . time()
);

// check that password and token are properly set
$this->assertEquals(60, strlen($user['password']));
Expand Down Expand Up @@ -487,10 +491,14 @@ public function testGetUsers()
);
$expectedUsers = array($user1, $user2, $user3);
$this->assertEquals($expectedUsers, $users);
$this->assertEquals(array($user1),
$this->_removeNonTestableFieldsFromUsers($this->api->getUsers('gegg4564eqgeqag')));
$this->assertEquals(array($user1, $user2),
$this->_removeNonTestableFieldsFromUsers($this->api->getUsers('gegg4564eqgeqag,geggeqge632ge56a4qag')));
$this->assertEquals(
array($user1),
$this->_removeNonTestableFieldsFromUsers($this->api->getUsers('gegg4564eqgeqag'))
);
$this->assertEquals(
array($user1, $user2),
$this->_removeNonTestableFieldsFromUsers($this->api->getUsers('gegg4564eqgeqag,geggeqge632ge56a4qag'))
);
}

public function testGetUsers_withViewAccess_shouldThrowAnException()
Expand Down Expand Up @@ -1168,8 +1176,10 @@ private function addSites($numberOfSites)

for ($index = 0; $index < $numberOfSites; $index++) {
$name = "test" . ($index + 1);
$idSites[] = APISitesManager::getInstance()->addSite($name,
array("http://piwik.net", "http://piwik.com/test/"));
$idSites[] = APISitesManager::getInstance()->addSite(
$name,
array("http://piwik.net", "http://piwik.com/test/")
);
}

return $idSites;
Expand Down
9 changes: 7 additions & 2 deletions plugins/VisitFrequency/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,13 @@ public function getEvolutionGraph()
}
}

$view = $this->getLastUnitGraphAcrossPlugins($this->pluginName, __FUNCTION__, $columns,
$selectableColumns, $documentation);
$view = $this->getLastUnitGraphAcrossPlugins(
$this->pluginName,
__FUNCTION__,
$columns,
$selectableColumns,
$documentation
);

if (empty($view->config->columns_to_display)) {
$view->config->columns_to_display = array('nb_visits_returning');
Expand Down
16 changes: 14 additions & 2 deletions plugins/VisitorInterest/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,13 @@ public function getNumberOfVisitsPerPage($idSite, $period, $date, $segment = fal
public function getNumberOfVisitsByDaysSinceLast($idSite, $period, $date, $segment = false)
{
$dataTable = $this->getDataTable(
Archiver::DAYS_SINCE_LAST_RECORD_NAME, $idSite, $period, $date, $segment, Metrics::INDEX_NB_VISITS);
Archiver::DAYS_SINCE_LAST_RECORD_NAME,
$idSite,
$period,
$date,
$segment,
Metrics::INDEX_NB_VISITS
);
$dataTable->queueFilter('AddSegmentByRangeLabel', array('daysSinceLastVisit'));
$dataTable->queueFilter('BeautifyRangeLabels', array(Piwik::translate('Intl_OneDay'), Piwik::translate('Intl_NDays')));
return $dataTable;
Expand All @@ -85,7 +91,13 @@ public function getNumberOfVisitsByDaysSinceLast($idSite, $period, $date, $segme
public function getNumberOfVisitsByVisitCount($idSite, $period, $date, $segment = false)
{
$dataTable = $this->getDataTable(
Archiver::VISITS_COUNT_RECORD_NAME, $idSite, $period, $date, $segment, Metrics::INDEX_NB_VISITS);
Archiver::VISITS_COUNT_RECORD_NAME,
$idSite,
$period,
$date,
$segment,
Metrics::INDEX_NB_VISITS
);

$dataTable->queueFilter('AddSegmentByRangeLabel', array('visitCount'));
$dataTable->queueFilter('BeautifyRangeLabels', array(
Expand Down
Loading
Loading