fix small code issues

This commit is contained in:
Daniel Seifert 2022-10-01 14:44:36 +02:00
parent ecb8b61923
commit 4e8bae08e7
Signed by: DanielS
GPG Key ID: 6A513E13AEE66170
9 changed files with 33 additions and 20 deletions

View File

@ -46,7 +46,8 @@
"laminas/laminas-math": "^3.2" "laminas/laminas-math": "^3.2"
}, },
"require-dev": { "require-dev": {
"friendsofphp/php-cs-fixer": "^2.19" "friendsofphp/php-cs-fixer": "^2.19",
"phpstan/phpstan": "^1.8"
}, },
"suggest": { "suggest": {
"d3/modcfg": "Provides automatic installation routines" "d3/modcfg": "Provides automatic installation routines"

8
phpstan.neon Normal file
View File

@ -0,0 +1,8 @@
parameters:
scanFiles:
- src/IntelliSenseHelper.php
- ../../oxid-esales/oxideshop-ce/source/oxfunctions.php
paths:
- src
level: 5
phpVersion: 70300

View File

@ -43,7 +43,7 @@ class d3user_totp extends AdminDetailsController
$soxId = $this->getEditObjectId(); $soxId = $this->getEditObjectId();
if (isset($soxId) && $soxId != "-1") { if ($soxId && $soxId != "-1") {
/** @var d3_totp_user $oUser */ /** @var d3_totp_user $oUser */
$oUser = $this->getUserObject(); $oUser = $this->getUserObject();
if ($oUser->load($soxId)) { if ($oUser->load($soxId)) {

View File

@ -20,6 +20,7 @@ use D3\Totp\Application\Model\d3totp;
use D3\Totp\Modules\Application\Model\d3_totp_user; use D3\Totp\Modules\Application\Model\d3_totp_user;
use Exception; use Exception;
use OxidEsales\Eshop\Application\Controller\AccountController; use OxidEsales\Eshop\Application\Controller\AccountController;
use OxidEsales\Eshop\Application\Model\User;
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException; use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
use OxidEsales\Eshop\Core\Registry; use OxidEsales\Eshop\Core\Registry;
use OxidEsales\Eshop\Core\UtilsView; use OxidEsales\Eshop\Core\UtilsView;
@ -34,9 +35,9 @@ class d3_account_totp extends AccountController
{ {
$sRet = parent::render(); $sRet = parent::render();
// is logged in ? /** @var User|null $oUser */
$oUser = $this->getUser(); $oUser = $this->getUser();
if (!$oUser) { if (false === $oUser instanceof User) {
return $this->_sThisTemplate = $this->_sThisLoginTemplate; return $this->_sThisTemplate = $this->_sThisLoginTemplate;
} }
@ -127,7 +128,7 @@ class d3_account_totp extends AccountController
$oUser = $this->getUser(); $oUser = $this->getUser();
/** @var d3totp $oTotp */ /** @var d3totp $oTotp */
$oTotp = $this->getTotpObject(); $oTotp = $this->getTotpObject();
if ($oUser && $oUser->getId()) { if ($oUser instanceof User && $oUser->getId()) {
$oTotp->loadByUserId($oUser->getId()); $oTotp->loadByUserId($oUser->getId());
$oTotp->delete(); $oTotp->delete();
} }

View File

@ -47,7 +47,7 @@ class d3totplogin extends FrontendController
/** /**
* @return Utils * @return Utils
*/ */
public function getUtils() public function getUtils(): Utils
{ {
return Registry::getUtils(); return Registry::getUtils();
} }
@ -72,7 +72,7 @@ class d3totplogin extends FrontendController
/** /**
* @return d3backupcodelist * @return d3backupcodelist
*/ */
public function getBackupCodeListObject() public function getBackupCodeListObject(): d3backupcodelist
{ {
return oxNew(d3backupcodelist::class); return oxNew(d3backupcodelist::class);
} }
@ -82,7 +82,7 @@ class d3totplogin extends FrontendController
return Registry::getSession()->getVariable(d3totp::TOTP_SESSION_CURRENTCLASS); return Registry::getSession()->getVariable(d3totp::TOTP_SESSION_CURRENTCLASS);
} }
public function previousClassIsOrderStep() public function previousClassIsOrderStep(): bool
{ {
$sClassKey = Registry::getSession()->getVariable(d3totp::TOTP_SESSION_CURRENTCLASS); $sClassKey = Registry::getSession()->getVariable(d3totp::TOTP_SESSION_CURRENTCLASS);
$resolvedClass = Registry::getControllerClassNameResolver()->getClassNameById($sClassKey); $resolvedClass = Registry::getControllerClassNameResolver()->getClassNameById($sClassKey);
@ -96,7 +96,7 @@ class d3totplogin extends FrontendController
/** /**
* @return bool * @return bool
*/ */
public function getIsOrderStep() public function getIsOrderStep(): bool
{ {
return $this->previousClassIsOrderStep(); return $this->previousClassIsOrderStep();
} }
@ -106,11 +106,11 @@ class d3totplogin extends FrontendController
* *
* @return array * @return array
*/ */
public function getBreadCrumb() public function getBreadCrumb(): array
{ {
$aPaths = []; $aPaths = [];
$aPath = []; $aPath = [];
$iBaseLanguage = Registry::getLang()->getBaseLanguage(); $iBaseLanguage = (int) Registry::getLang()->getBaseLanguage();
$aPath['title'] = Registry::getLang()->translateString('D3_TOTP_BREADCRUMB', $iBaseLanguage, false); $aPath['title'] = Registry::getLang()->translateString('D3_TOTP_BREADCRUMB', $iBaseLanguage, false);
$aPath['link'] = $this->getLink(); $aPath['link'] = $this->getLink();

View File

@ -67,7 +67,10 @@ class d3backupcode extends BaseModel
public function d3GetUser() public function d3GetUser()
{ {
if ($this->getUser()) { /** @var User|null $user */
$user = $this->getUser();
if ($user instanceof User) {
return $this->getUser(); return $this->getUser();
} }

View File

@ -46,7 +46,7 @@ class d3totp extends BaseModel
{ {
$this->init($this->tableName); $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'); $seed_enc = $this->getFieldData('seed');
@ -197,7 +197,7 @@ class d3totp extends BaseModel
/** /**
* @param $totp * @param $totp
* @param $seed * @param $seed
* @return string * @return bool
* @throws DatabaseConnectionException * @throws DatabaseConnectionException
* @throws d3totp_wrongOtpException * @throws d3totp_wrongOtpException
*/ */
@ -212,7 +212,7 @@ class d3totp extends BaseModel
if ($blNotVerified) { if ($blNotVerified) {
throw oxNew(d3totp_wrongOtpException::class); throw oxNew(d3totp_wrongOtpException::class);
} }
} elseif ($blNotVerified && $seed) { } elseif ($blNotVerified && $seed !== null) {
throw oxNew(d3totp_wrongOtpException::class); throw oxNew(d3totp_wrongOtpException::class);
} }
@ -282,6 +282,6 @@ class d3totp extends BaseModel
$oBackupCodeList = $this->d3GetBackupCodeListObject(); $oBackupCodeList = $this->d3GetBackupCodeListObject();
$oBackupCodeList->deleteAllFromUser($this->getFieldData('oxuserid')); $oBackupCodeList->deleteAllFromUser($this->getFieldData('oxuserid'));
return parent::delete(); return parent::delete($oxid);
} }
} }

View File

@ -37,7 +37,7 @@ class d3_totp_UserComponent extends d3_totp_UserComponent_parent
$oUser = $this->getUser(); $oUser = $this->getUser();
if ($oUser && $oUser->getId()) { if ($oUser instanceof User && $oUser->getId()) {
$totp = $this->d3GetTotpObject(); $totp = $this->d3GetTotpObject();
$totp->loadByUserId($oUser->getId()); $totp->loadByUserId($oUser->getId());

View File

@ -31,7 +31,7 @@ trait d3_totp_getUserTrait
{ {
$oUser = parent::getUser(); $oUser = parent::getUser();
if ($oUser && $oUser->getId()) { if ($oUser instanceof User && $oUser->getId()) {
$totp = $this->d3GetTotpObject(); $totp = $this->d3GetTotpObject();
$totp->loadByUserId($oUser->getId()); $totp->loadByUserId($oUser->getId());