Skip to content

Commit 543671a

Browse files
authored
Merge pull request #448 from sil-org/psr12
update PHP version in composer.json; PSR12 changes
2 parents a7adb00 + 22063a8 commit 543671a

36 files changed

Lines changed: 250 additions & 224 deletions

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ auth.json
1111
vendor/
1212
*.aes
1313

14-
# PHP-CS-Fixer cache file.
14+
# PHP-CS-Fixer files.
1515
.php_cs.cache
1616
.php-cs-fixer.cache
17+
.php-cs-fixer.php
18+
.php-cs-fixer.dist.php
1719

1820
api.html
1921

app/common/components/EmailClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function email(array $properties): void
2828
throw new Exception(current($email->getFirstErrors()));
2929
}
3030

31-
if ((int)$email->send_after <= time() && (int)$email->delay_seconds <= 0) {
31+
if ((int) $email->send_after <= time() && (int) $email->delay_seconds <= 0) {
3232
/*
3333
* Attempt to send email immediately
3434
*/

app/common/components/EmailLogTarget.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ public function init()
2929
throw new InvalidConfigException('The "to" option must be set for EmailLogTarget::message.');
3030
}
3131

32-
$this->message['subject'] = $this->message['subject'] ?? 'System Alert';
33-
$this->message['cc'] = $this->message['cc'] ?? '';
34-
$this->message['bcc'] = $this->message['bcc'] ?? '';
32+
$this->message['subject'] ??= 'System Alert';
33+
$this->message['cc'] ??= '';
34+
$this->message['bcc'] ??= '';
3535
}
3636

3737

app/common/components/Emailer.php

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -244,27 +244,27 @@ public function init()
244244
$this->logger = new Psr3Yii2Logger();
245245
}
246246

247-
$this->subjectForAbandonedUsers = $this->subjectForAbandonedUsers ?? self::SUBJ_ABANDONED_USER_ACCOUNTS;
248-
$this->subjectForExtGroupSyncErrors = $this->subjectForExtGroupSyncErrors ?? self::SUBJ_EXT_GROUP_SYNC_ERRORS;
249-
$this->subjectForGetBackupCodes = $this->subjectForGetBackupCodes ?? self::SUBJ_GET_BACKUP_CODES;
250-
$this->subjectForInvite = $this->subjectForInvite ?? self::SUBJ_INVITE;
251-
$this->subjectForLostSecurityKey = $this->subjectForLostSecurityKey ?? self::SUBJ_LOST_SECURITY_KEY;
252-
$this->subjectForMethodPurged = $this->subjectForMethodPurged ?? self::SUBJ_METHOD_PURGED;
253-
$this->subjectForMethodReminder = $this->subjectForMethodReminder ?? self::SUBJ_METHOD_REMINDER;
254-
$this->subjectForMethodVerify = $this->subjectForMethodVerify ?? self::SUBJ_METHOD_VERIFY;
255-
$this->subjectForMfaDisabled = $this->subjectForMfaDisabled ?? self::SUBJ_MFA_DISABLED;
256-
$this->subjectForMfaEnabled = $this->subjectForMfaEnabled ?? self::SUBJ_MFA_ENABLED;
257-
$this->subjectForMfaOptionAdded = $this->subjectForMfaOptionAdded ?? self::SUBJ_MFA_OPTION_ADDED;
258-
$this->subjectForMfaOptionRemoved = $this->subjectForMfaOptionRemoved ?? self::SUBJ_MFA_OPTION_REMOVED;
259-
$this->subjectForMfaRateLimit = $this->subjectForMfaRateLimit ?? self::SUBJ_MFA_RATE_LIMIT;
260-
$this->subjectForMfaRecovery = $this->subjectForMfaRecovery ?? self::SUBJ_MFA_RECOVERY;
261-
$this->subjectForMfaRecoveryHelp = $this->subjectForMfaRecoveryHelp ?? self::SUBJ_MFA_RECOVERY_HELP;
262-
$this->subjectForPasswordChanged = $this->subjectForPasswordChanged ?? self::SUBJ_PASSWORD_CHANGED;
263-
$this->subjectForPasswordExpired = $this->subjectForPasswordExpired ?? self::SUBJ_PASSWORD_EXPIRED;
264-
$this->subjectForPasswordExpiring = $this->subjectForPasswordExpiring ?? self::SUBJ_PASSWORD_EXPIRING;
265-
$this->subjectForPasswordPwned = $this->subjectForPasswordPwned ?? self::SUBJ_PASSWORD_PWNED;
266-
$this->subjectForRefreshBackupCodes = $this->subjectForRefreshBackupCodes ?? self::SUBJ_REFRESH_BACKUP_CODES;
267-
$this->subjectForWelcome = $this->subjectForWelcome ?? self::SUBJ_WELCOME;
247+
$this->subjectForAbandonedUsers ??= self::SUBJ_ABANDONED_USER_ACCOUNTS;
248+
$this->subjectForExtGroupSyncErrors ??= self::SUBJ_EXT_GROUP_SYNC_ERRORS;
249+
$this->subjectForGetBackupCodes ??= self::SUBJ_GET_BACKUP_CODES;
250+
$this->subjectForInvite ??= self::SUBJ_INVITE;
251+
$this->subjectForLostSecurityKey ??= self::SUBJ_LOST_SECURITY_KEY;
252+
$this->subjectForMethodPurged ??= self::SUBJ_METHOD_PURGED;
253+
$this->subjectForMethodReminder ??= self::SUBJ_METHOD_REMINDER;
254+
$this->subjectForMethodVerify ??= self::SUBJ_METHOD_VERIFY;
255+
$this->subjectForMfaDisabled ??= self::SUBJ_MFA_DISABLED;
256+
$this->subjectForMfaEnabled ??= self::SUBJ_MFA_ENABLED;
257+
$this->subjectForMfaOptionAdded ??= self::SUBJ_MFA_OPTION_ADDED;
258+
$this->subjectForMfaOptionRemoved ??= self::SUBJ_MFA_OPTION_REMOVED;
259+
$this->subjectForMfaRateLimit ??= self::SUBJ_MFA_RATE_LIMIT;
260+
$this->subjectForMfaRecovery ??= self::SUBJ_MFA_RECOVERY;
261+
$this->subjectForMfaRecoveryHelp ??= self::SUBJ_MFA_RECOVERY_HELP;
262+
$this->subjectForPasswordChanged ??= self::SUBJ_PASSWORD_CHANGED;
263+
$this->subjectForPasswordExpired ??= self::SUBJ_PASSWORD_EXPIRED;
264+
$this->subjectForPasswordExpiring ??= self::SUBJ_PASSWORD_EXPIRING;
265+
$this->subjectForPasswordPwned ??= self::SUBJ_PASSWORD_PWNED;
266+
$this->subjectForRefreshBackupCodes ??= self::SUBJ_REFRESH_BACKUP_CODES;
267+
$this->subjectForWelcome ??= self::SUBJ_WELCOME;
268268

269269
$this->subjects = [
270270
EmailLog::MESSAGE_TYPE_ABANDONED_USERS => $this->subjectForAbandonedUsers,
@@ -290,7 +290,7 @@ public function init()
290290
EmailLog::MESSAGE_TYPE_WELCOME => $this->subjectForWelcome,
291291
];
292292

293-
$this->hrNotificationsEmail = $this->hrNotificationsEmail ?? '';
293+
$this->hrNotificationsEmail ??= '';
294294

295295
$this->assertConfigIsValid();
296296

@@ -688,8 +688,8 @@ public function sendMethodReminderEmails()
688688
$methods = Method::findAll(['verified' => 0]);
689689
foreach ($methods as $method) {
690690
$user = $method->user;
691-
if (!MySqlDateTime::dateIsRecent($method->created, 3) &&
692-
!$this->hasUserReceivedMessageRecently($user->id, EmailLog::MESSAGE_TYPE_METHOD_REMINDER)
691+
if (!MySqlDateTime::dateIsRecent($method->created, 3)
692+
&& !$this->hasUserReceivedMessageRecently($user->id, EmailLog::MESSAGE_TYPE_METHOD_REMINDER)
693693
) {
694694
$this->sendMessageTo(
695695
EmailLog::MESSAGE_TYPE_METHOD_REMINDER,
@@ -724,7 +724,7 @@ public function sendPasswordExpiringEmails()
724724
$users = User::getUsersForEmail('password-expiring', $this->emailRepeatDelayDays);
725725

726726
$this->logger->info(json_encode(array_merge($logData, [
727-
'users' => count($users)
727+
'users' => count($users),
728728
])));
729729

730730
$numEmailsSent = 0;
@@ -765,7 +765,7 @@ public function sendPasswordExpiredEmails()
765765
$users = User::getUsersForEmail('password-expired', $this->emailRepeatDelayDays);
766766

767767
$this->logger->info(json_encode(array_merge($logData, [
768-
'users' => count($users)
768+
'users' => count($users),
769769
])));
770770

771771
$numEmailsSent = 0;

app/common/components/MfaApiClient.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,15 +205,15 @@ private function callApi(string $path, string $method, array $body = [], array $
205205
$path,
206206
[
207207
'json' => $body,
208-
'headers' => array_merge($this->headers, $additionalHeaders)
208+
'headers' => array_merge($this->headers, $additionalHeaders),
209209
]
210210
);
211211
} catch (\Exception $e) {
212212
if ($e instanceof ConnectException || $e instanceof ServerException) {
213213
\Yii::error([
214214
'action' => 'calling 2sv api',
215215
'status' => 'error',
216-
'error' => 'connection error: ' . $e->getMessage()
216+
'error' => 'connection error: ' . $e->getMessage(),
217217
]);
218218
}
219219

app/common/components/SesMailer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ protected function sendMessage($message)
7373
\Yii::error([
7474
'action' => 'sendMessage',
7575
'type' => get_class($e),
76-
'message' => $e->getMessage()
76+
'message' => $e->getMessage(),
7777
]);
7878
return false;
7979
}

app/common/exceptions/InvalidCodeException.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,4 @@
22

33
namespace common\exceptions;
44

5-
class InvalidCodeException extends \Exception
6-
{
7-
}
5+
class InvalidCodeException extends \Exception {}

app/common/helpers/Utils.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public static function getRandomDigits($length = 4)
4444
*/
4545
public static function getFriendlyDate($timestamp = null)
4646
{
47-
$timestamp = $timestamp ?? time();
47+
$timestamp ??= time();
4848
$timestamp = is_int($timestamp) ? $timestamp : strtotime($timestamp);
4949
if ($timestamp === false) {
5050
throw new \Exception('Unable to parse date to timestamp', 1468865838);
@@ -60,7 +60,7 @@ public static function getFriendlyDate($timestamp = null)
6060
*/
6161
public static function getIso8601($timestamp = null)
6262
{
63-
$timestamp = $timestamp ?? time();
63+
$timestamp ??= time();
6464
$timestamp = is_int($timestamp) ? $timestamp : strtotime($timestamp);
6565
if ($timestamp === false) {
6666
throw new \Exception('Unable to parse date to timestamp', 1546977533);
@@ -90,7 +90,7 @@ public static function maskEmail($email)
9090
throw new BadRequestHttpException('Invalid email address provided.', 1461459797);
9191
}
9292

93-
list($part1, $domain) = explode('@', $email);
93+
[$part1, $domain] = explode('@', $email);
9494
$newEmail = '';
9595
$useRealChar = true;
9696

app/common/models/Authentication.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ public function __construct(
4040
protected function authenticateByPassword(string $username, string $password)
4141
{
4242
/* @var $user User */
43-
$user = User::findByUsername($username) ??
44-
User::findByEmail($username) ?? // maybe we got an email
45-
new User();
43+
$user = User::findByUsername($username)
44+
?? User::findByEmail($username) // maybe we got an email
45+
?? new User();
4646

4747
$user->scenario = User::SCENARIO_AUTHENTICATE;
4848
$user->password = $password;

app/common/models/Email.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function retry(): int
119119
'attempts_count' => $this->attempts_count,
120120
'last_attempt' => $this->updated_at,
121121
'error' => $e->getMessage(),
122-
'code' => $e->getCode()
122+
'code' => $e->getCode(),
123123
];
124124
\Yii::error($log);
125125

@@ -130,8 +130,8 @@ public function retry(): int
130130
'error' => $this->getFirstErrors(),
131131
]);
132132
throw new ServerErrorHttpException(
133-
'Unable to save email after failing to retry sending. Error: ' .
134-
print_r($this->getFirstErrors(), true),
133+
'Unable to save email after failing to retry sending. Error: '
134+
. print_r($this->getFirstErrors(), true),
135135
1741067362
136136
);
137137
}
@@ -148,11 +148,11 @@ public function getMessage()
148148
$mailer = \Yii::$app->mailer->compose(
149149
[
150150
'html' => '@common/mail/html',
151-
'text' => '@common/mail/text'
151+
'text' => '@common/mail/text',
152152
],
153153
[
154154
'html' => $this->html_body,
155-
'text' => $this->text_body
155+
'text' => $this->text_body,
156156
]
157157
);
158158
$from = \Yii::$app->params['fromEmail'];

0 commit comments

Comments
 (0)