From 5949a29b89190653ae7b9a0428f43c0008b1e401 Mon Sep 17 00:00:00 2001 From: Mark Magyar <14284867+xHeaven@users.noreply.github.com> Date: Sat, 27 May 2023 21:18:20 +0200 Subject: [PATCH] use null coalescing operator instead of if checks --- lib/TwoFactorAuth.php | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/lib/TwoFactorAuth.php b/lib/TwoFactorAuth.php index 88ea174..14573ab 100644 --- a/lib/TwoFactorAuth.php +++ b/lib/TwoFactorAuth.php @@ -168,10 +168,7 @@ class TwoFactorAuth public function getQrCodeProvider(): IQRCodeProvider { // Set default QR Code provider if none was specified - if ($this->qrcodeprovider === null) { - return $this->qrcodeprovider = new QRServerProvider(); - } - return $this->qrcodeprovider; + return $this->qrcodeprovider ?? ($this->qrcodeprovider = new QRServerProvider()); } /** @@ -200,10 +197,7 @@ class TwoFactorAuth public function getTimeProvider(): ITimeProvider { // Set default time provider if none was specified - if ($this->timeprovider === null) { - return $this->timeprovider = new LocalMachineTimeProvider(); - } - return $this->timeprovider; + return $this->timeprovider ?? ($this->timeprovider = new LocalMachineTimeProvider()); } /** @@ -229,7 +223,7 @@ class TwoFactorAuth private function getTime(?int $time = null): int { - return ($time === null) ? $this->getTimeProvider()->getTime() : $time; + return $time ?? $this->getTimeProvider()->getTime(); } private function getTimeSlice(?int $time = null, int $offset = 0): int