From 4e8bae08e77ed707fc28f8b98ada30b62a5fbfc7 Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Sat, 1 Oct 2022 14:44:36 +0200 Subject: [PATCH] fix small code issues --- composer.json | 3 ++- phpstan.neon | 8 ++++++++ src/Application/Controller/Admin/d3user_totp.php | 2 +- src/Application/Controller/d3_account_totp.php | 7 ++++--- src/Application/Controller/d3totplogin.php | 12 ++++++------ src/Application/Model/d3backupcode.php | 5 ++++- src/Application/Model/d3totp.php | 12 ++++++------ .../Application/Component/d3_totp_UserComponent.php | 2 +- .../Application/Controller/d3_totp_getUserTrait.php | 2 +- 9 files changed, 33 insertions(+), 20 deletions(-) create mode 100644 phpstan.neon diff --git a/composer.json b/composer.json index add5e2a..45ec44a 100644 --- a/composer.json +++ b/composer.json @@ -46,7 +46,8 @@ "laminas/laminas-math": "^3.2" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^2.19" + "friendsofphp/php-cs-fixer": "^2.19", + "phpstan/phpstan": "^1.8" }, "suggest": { "d3/modcfg": "Provides automatic installation routines" diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..a4b4634 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,8 @@ +parameters: + scanFiles: + - src/IntelliSenseHelper.php + - ../../oxid-esales/oxideshop-ce/source/oxfunctions.php + paths: + - src + level: 5 + phpVersion: 70300 \ No newline at end of file diff --git a/src/Application/Controller/Admin/d3user_totp.php b/src/Application/Controller/Admin/d3user_totp.php index c5b9ce5..82e5acf 100644 --- a/src/Application/Controller/Admin/d3user_totp.php +++ b/src/Application/Controller/Admin/d3user_totp.php @@ -43,7 +43,7 @@ class d3user_totp extends AdminDetailsController $soxId = $this->getEditObjectId(); - if (isset($soxId) && $soxId != "-1") { + if ($soxId && $soxId != "-1") { /** @var d3_totp_user $oUser */ $oUser = $this->getUserObject(); if ($oUser->load($soxId)) { diff --git a/src/Application/Controller/d3_account_totp.php b/src/Application/Controller/d3_account_totp.php index 98f38c4..98c3d16 100644 --- a/src/Application/Controller/d3_account_totp.php +++ b/src/Application/Controller/d3_account_totp.php @@ -20,6 +20,7 @@ use D3\Totp\Application\Model\d3totp; use D3\Totp\Modules\Application\Model\d3_totp_user; use Exception; use OxidEsales\Eshop\Application\Controller\AccountController; +use OxidEsales\Eshop\Application\Model\User; use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException; use OxidEsales\Eshop\Core\Registry; use OxidEsales\Eshop\Core\UtilsView; @@ -34,9 +35,9 @@ class d3_account_totp extends AccountController { $sRet = parent::render(); - // is logged in ? + /** @var User|null $oUser */ $oUser = $this->getUser(); - if (!$oUser) { + if (false === $oUser instanceof User) { return $this->_sThisTemplate = $this->_sThisLoginTemplate; } @@ -127,7 +128,7 @@ class d3_account_totp extends AccountController $oUser = $this->getUser(); /** @var d3totp $oTotp */ $oTotp = $this->getTotpObject(); - if ($oUser && $oUser->getId()) { + if ($oUser instanceof User && $oUser->getId()) { $oTotp->loadByUserId($oUser->getId()); $oTotp->delete(); } diff --git a/src/Application/Controller/d3totplogin.php b/src/Application/Controller/d3totplogin.php index e403f6d..31e9dc1 100644 --- a/src/Application/Controller/d3totplogin.php +++ b/src/Application/Controller/d3totplogin.php @@ -47,7 +47,7 @@ class d3totplogin extends FrontendController /** * @return Utils */ - public function getUtils() + public function getUtils(): Utils { return Registry::getUtils(); } @@ -72,7 +72,7 @@ class d3totplogin extends FrontendController /** * @return d3backupcodelist */ - public function getBackupCodeListObject() + public function getBackupCodeListObject(): d3backupcodelist { return oxNew(d3backupcodelist::class); } @@ -82,7 +82,7 @@ class d3totplogin extends FrontendController return Registry::getSession()->getVariable(d3totp::TOTP_SESSION_CURRENTCLASS); } - public function previousClassIsOrderStep() + public function previousClassIsOrderStep(): bool { $sClassKey = Registry::getSession()->getVariable(d3totp::TOTP_SESSION_CURRENTCLASS); $resolvedClass = Registry::getControllerClassNameResolver()->getClassNameById($sClassKey); @@ -96,7 +96,7 @@ class d3totplogin extends FrontendController /** * @return bool */ - public function getIsOrderStep() + public function getIsOrderStep(): bool { return $this->previousClassIsOrderStep(); } @@ -106,11 +106,11 @@ class d3totplogin extends FrontendController * * @return array */ - public function getBreadCrumb() + public function getBreadCrumb(): array { $aPaths = []; $aPath = []; - $iBaseLanguage = Registry::getLang()->getBaseLanguage(); + $iBaseLanguage = (int) Registry::getLang()->getBaseLanguage(); $aPath['title'] = Registry::getLang()->translateString('D3_TOTP_BREADCRUMB', $iBaseLanguage, false); $aPath['link'] = $this->getLink(); diff --git a/src/Application/Model/d3backupcode.php b/src/Application/Model/d3backupcode.php index 5a53a60..30c5336 100644 --- a/src/Application/Model/d3backupcode.php +++ b/src/Application/Model/d3backupcode.php @@ -67,7 +67,10 @@ class d3backupcode extends BaseModel public function d3GetUser() { - if ($this->getUser()) { + /** @var User|null $user */ + $user = $this->getUser(); + + if ($user instanceof User) { return $this->getUser(); } diff --git a/src/Application/Model/d3totp.php b/src/Application/Model/d3totp.php index 47275df..7c0a97b 100644 --- a/src/Application/Model/d3totp.php +++ b/src/Application/Model/d3totp.php @@ -46,7 +46,7 @@ class d3totp extends BaseModel { $this->init($this->tableName); - return parent::__construct(); + parent::__construct(); } /** @@ -124,9 +124,9 @@ class d3totp extends BaseModel } /** - * @return string + * @return string|null */ - public function getSavedSecret() + public function getSavedSecret(): ?string { $seed_enc = $this->getFieldData('seed'); @@ -197,7 +197,7 @@ class d3totp extends BaseModel /** * @param $totp * @param $seed - * @return string + * @return bool * @throws DatabaseConnectionException * @throws d3totp_wrongOtpException */ @@ -212,7 +212,7 @@ class d3totp extends BaseModel if ($blNotVerified) { throw oxNew(d3totp_wrongOtpException::class); } - } elseif ($blNotVerified && $seed) { + } elseif ($blNotVerified && $seed !== null) { throw oxNew(d3totp_wrongOtpException::class); } @@ -282,6 +282,6 @@ class d3totp extends BaseModel $oBackupCodeList = $this->d3GetBackupCodeListObject(); $oBackupCodeList->deleteAllFromUser($this->getFieldData('oxuserid')); - return parent::delete(); + return parent::delete($oxid); } } diff --git a/src/Modules/Application/Component/d3_totp_UserComponent.php b/src/Modules/Application/Component/d3_totp_UserComponent.php index b9b4efc..33b20d1 100644 --- a/src/Modules/Application/Component/d3_totp_UserComponent.php +++ b/src/Modules/Application/Component/d3_totp_UserComponent.php @@ -37,7 +37,7 @@ class d3_totp_UserComponent extends d3_totp_UserComponent_parent $oUser = $this->getUser(); - if ($oUser && $oUser->getId()) { + if ($oUser instanceof User && $oUser->getId()) { $totp = $this->d3GetTotpObject(); $totp->loadByUserId($oUser->getId()); diff --git a/src/Modules/Application/Controller/d3_totp_getUserTrait.php b/src/Modules/Application/Controller/d3_totp_getUserTrait.php index cd0f068..6064844 100644 --- a/src/Modules/Application/Controller/d3_totp_getUserTrait.php +++ b/src/Modules/Application/Controller/d3_totp_getUserTrait.php @@ -31,7 +31,7 @@ trait d3_totp_getUserTrait { $oUser = parent::getUser(); - if ($oUser && $oUser->getId()) { + if ($oUser instanceof User && $oUser->getId()) { $totp = $this->d3GetTotpObject(); $totp->loadByUserId($oUser->getId());