Skip to content

Commit

Permalink
Dev: Use string type-hint instead of type-cast
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Mar 29, 2023
1 parent 0748098 commit 4450ae8
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion application/controllers/admin/UserAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function personalsettings()
$repeatPassword = Yii::app()->request->getPost('repeatpassword');

if ($newPassword !== '' && $repeatPassword !== '') {
$error = $oUserModel->validateNewPassword($newPassword, $oldPassword, $repeatPassword);
$error = $oUserModel->validateNewPassword($newPassword, $oldPassword ?? '', $repeatPassword);

if ($error !== '') {
Yii::app()->setFlashMessage(gT($error), 'error');
Expand Down
2 changes: 1 addition & 1 deletion application/models/FailedLoginAttempt.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ private function isWhitelisted(string $ip, string $attemptType): bool
}

// Validating
$whiteListEntries = preg_split('/\n|,/', (string) $whiteList);
$whiteListEntries = preg_split('/\n|,/', $whiteList);
foreach ($whiteListEntries as $whiteListEntry) {
if (empty($whiteListEntry)) {
continue;
Expand Down
2 changes: 1 addition & 1 deletion application/models/InstallerConfigForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ public function setupTables()
} catch (Exception $e) {
return array($e->getMessage());
}
$fileName = dirname((string) APPPATH) . '/installer/create-database.php';
$fileName = dirname(APPPATH) . '/installer/create-database.php';
require_once($fileName);
try {
populateDatabase($this->db);
Expand Down
4 changes: 2 additions & 2 deletions application/models/SettingGlobal.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ public static function increaseAssetsversionnumber()
$iAssetNumber = self::generateAssetVersionNumber(Yii::app()->getConfig("assetsversionnumber"));

foreach ($versionlines as $line) {
if (strpos((string) $line, 'assetsversionnumber') !== false) {
if (strpos($line, 'assetsversionnumber') !== false) {
$line = '$config[\'assetsversionnumber\'] = \'' . $iAssetNumber . '\';' . "\r\n";
}
fwrite($handle, (string) $line);
fwrite($handle, $line);
}
fclose($handle);
Yii::app()->setConfig("assetsversionnumber", $iAssetNumber);
Expand Down
26 changes: 13 additions & 13 deletions application/models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,14 @@ public function checkPassword($sPassword)
/**
* @todo document me
*/
public function checkPasswordStrength($password)
public function checkPasswordStrength(string $password)
{
$settings = Yii::app()->getConfig("passwordValidationRules");
$length = strlen((string) $password);
$lowercase = preg_match_all('@[a-z]@', (string) $password);
$uppercase = preg_match_all('@[A-Z]@', (string) $password);
$number = preg_match_all('@[0-9]@', (string) $password);
$specialChars = preg_match_all('@[^\w]@', (string) $password);
$length = strlen($password);
$lowercase = preg_match_all('@[a-z]@', $password);
$uppercase = preg_match_all('@[A-Z]@', $password);
$number = preg_match_all('@[0-9]@', $password);
$specialChars = preg_match_all('@[^\w]@', $password);

$error = "";
if ((int) $settings['min'] > 0) {
Expand Down Expand Up @@ -325,12 +325,12 @@ public function checkPasswordStrength($password)
* -- newpassword and repeatpassword are identical
* -- newpassword is not empty
*
* @param $newPassword
* @param $oldPassword
* @param $repeatPassword
* @param string $newPassword
* @param string $oldPassword
* @param string $repeatPassword
* @return string empty string means everything is ok, otherwise error message is returned
*/
public function validateNewPassword($newPassword, $oldPassword, $repeatPassword)
public function validateNewPassword(string $newPassword, string $oldPassword, string $repeatPassword)
{
$errorMsg = '';

Expand All @@ -342,14 +342,14 @@ public function validateNewPassword($newPassword, $oldPassword, $repeatPassword)
if (!$this->checkPassword($oldPassword)) {
// Always check password
$errorMsg = gT("Your new password was not saved because the old password was wrong.");
} elseif (trim((string) $oldPassword) === trim((string) $newPassword)) {
} elseif (trim($oldPassword) === trim($newPassword)) {
//First test if old and new password are identical => no need to save it (or ?)
$errorMsg = gT("Your new password was not saved because it matches the old password.");
} elseif (trim((string) $newPassword) !== trim((string) $repeatPassword)) {
} elseif (trim($newPassword) !== trim($repeatPassword)) {
//Then test the new password and the repeat password for identity
$errorMsg = gT("Your new password was not saved because the passwords did not match.");
//Now check if the old password matches the old password saved
} elseif (empty(trim((string) $newPassword))) {
} elseif (empty(trim($newPassword))) {
$errorMsg = gT("The new password can not be empty.");
}
}
Expand Down

0 comments on commit 4450ae8

Please sign in to comment.