apply static code analysis changes

This commit is contained in:
Daniel Seifert 2023-01-10 23:33:48 +01:00
parent fb124c1f1a
commit 2312af010a
Signed by: DanielS
GPG Key ID: 6A513E13AEE66170
13 changed files with 87 additions and 44 deletions

View File

@ -4,7 +4,10 @@ parameters:
- ../../oxid-esales/oxideshop-ce/source/oxfunctions.php - ../../oxid-esales/oxideshop-ce/source/oxfunctions.php
paths: paths:
- src - src
excludePaths:
- src/tests
level: 9 level: 9
phpVersion: 70100 phpVersion: 70100
ignoreErrors: ignoreErrors:
- '#Psr\\Container\\ContainerExceptionInterface is not subtype of Throwable#' - '#Psr\\Container\\ContainerExceptionInterface is not subtype of Throwable#'
- '#Cannot cast mixed to string.#'

View File

@ -44,11 +44,14 @@ class AdminOrder extends AdminController
public function __construct() public function __construct()
{ {
$this->item = d3GetOxidDIC()->get('d3ox.linkmobility.'.Order::class); /** @var Order $item */
d3GetOxidDIC()->set(OrderRecipients::class.'.args.order', $this->item); $item = d3GetOxidDIC()->get('d3ox.linkmobility.'.Order::class);
$this->itemRecipients = d3GetOxidDIC()->get(OrderRecipients::class); $this->item = $item;
d3GetOxidDIC()->set(OrderRecipients::class.'.args.order', $item);
$this->item->load($this->getEditObjectId()); /** @var OrderRecipients $itemRecipients */
$itemRecipients = d3GetOxidDIC()->get(OrderRecipients::class);
$this->itemRecipients = $itemRecipients;
$item->load($this->getEditObjectId());
$this->addTplParam('recipient', $this->getRecipientFromCurrentItem()); $this->addTplParam('recipient', $this->getRecipientFromCurrentItem());
@ -81,6 +84,7 @@ class AdminOrder extends AdminController
} catch (noRecipientFoundException $e) { } catch (noRecipientFoundException $e) {
/** @var Language $lang */ /** @var Language $lang */
$lang = d3GetOxidDIC()->get('d3ox.linkmobility.'.Language::class); $lang = d3GetOxidDIC()->get('d3ox.linkmobility.'.Language::class);
/** @var string $message */
$message = $lang->translateString($e->getMessage()); $message = $lang->translateString($e->getMessage());
/** @var UtilsView $utilsView */ /** @var UtilsView $utilsView */
$utilsView = d3GetOxidDIC()->get('d3ox.linkmobility.'.UtilsView::class); $utilsView = d3GetOxidDIC()->get('d3ox.linkmobility.'.UtilsView::class);
@ -101,7 +105,7 @@ class AdminOrder extends AdminController
try { try {
$utilsView->addErrorToDisplay($this->sendMessage()); $utilsView->addErrorToDisplay($this->sendMessage());
} catch (noRecipientFoundException|InvalidArgumentException $e) { } catch (noRecipientFoundException|InvalidArgumentException $e) {
$utilsView->addErrorToDisplay($e); $utilsView->addErrorToDisplay($e->getMessage());
} }
} }

View File

@ -46,10 +46,14 @@ class AdminUser extends AdminController
public function __construct() public function __construct()
{ {
$this->item = d3GetOxidDIC()->get('d3ox.linkmobility.'.User::class); /** @var User $item */
d3GetOxidDIC()->set(UserRecipients::class.".args.user", $this->item); $item = d3GetOxidDIC()->get('d3ox.linkmobility.'.User::class);
$this->itemRecipients = d3GetOxidDIC()->get(UserRecipients::class); $this->item = $item;
$this->item->load($this->getEditObjectId()); d3GetOxidDIC()->set(UserRecipients::class.".args.user", $item);
/** @var UserRecipients $itemRecipients */
$itemRecipients = d3GetOxidDIC()->get(UserRecipients::class);
$this->itemRecipients = $itemRecipients;
$item->load($this->getEditObjectId());
$this->addTplParam('recipient', $this->getRecipientFromCurrentItem()); $this->addTplParam('recipient', $this->getRecipientFromCurrentItem());
@ -82,6 +86,7 @@ class AdminUser extends AdminController
} catch (noRecipientFoundException $e) { } catch (noRecipientFoundException $e) {
/** @var Language $lang */ /** @var Language $lang */
$lang = d3GetOxidDIC()->get('d3ox.linkmobility.'.Language::class); $lang = d3GetOxidDIC()->get('d3ox.linkmobility.'.Language::class);
/** @var string $message */
$message = $lang->translateString($e->getMessage()); $message = $lang->translateString($e->getMessage());
/** @var UtilsView $utilsView */ /** @var UtilsView $utilsView */
$utilsView = d3GetOxidDIC()->get('d3ox.linkmobility.'.UtilsView::class); $utilsView = d3GetOxidDIC()->get('d3ox.linkmobility.'.UtilsView::class);
@ -102,7 +107,7 @@ class AdminUser extends AdminController
try { try {
$utilsView->addErrorToDisplay($this->sendMessage()); $utilsView->addErrorToDisplay($this->sendMessage());
} catch (noRecipientFoundException|InvalidArgumentException $e) { } catch (noRecipientFoundException|InvalidArgumentException $e) {
$utilsView->addErrorToDisplay($e); $utilsView->addErrorToDisplay($e->getMessage());
} }
} }

View File

@ -133,8 +133,8 @@ class Configuration
} }
/** /**
* @param array $customFields * @param string[] $customFields
* @return array * @return string[]
*/ */
public function sanitizeKeys(array $customFields): array public function sanitizeKeys(array $customFields): array
{ {

View File

@ -29,8 +29,10 @@ class successfullySentException extends StandardException
*/ */
public function __construct($messageCount = 1, $code = 0, Exception $previous = null) public function __construct($messageCount = 1, $code = 0, Exception $previous = null)
{ {
/** @var Language $language */
$language = d3GetOxidDIC()->get('d3ox.linkmobility.'.Language::class);
/** @var string $format */ /** @var string $format */
$format = d3GetOxidDIC()->get('d3ox.linkmobility.'.Language::class)->translateString('D3LM_EXC_SMS_SUCC_SENT'); $format = $language->translateString('D3LM_EXC_SMS_SUCC_SENT');
$message = sprintf($format, $messageCount); $message = sprintf($format, $messageCount);
parent::__construct($message, $code, $previous); parent::__construct($message, $code, $previous);

View File

@ -16,6 +16,7 @@ declare(strict_types=1);
namespace D3\Linkmobility4OXID\Application\Model\MessageTypes; namespace D3\Linkmobility4OXID\Application\Model\MessageTypes;
use D3\LinkmobilityClient\RecipientsList\RecipientsList; use D3\LinkmobilityClient\RecipientsList\RecipientsList;
use D3\LinkmobilityClient\RecipientsList\RecipientsListInterface;
use D3\LinkmobilityClient\Response\ResponseInterface; use D3\LinkmobilityClient\Response\ResponseInterface;
use D3\LinkmobilityClient\ValueObject\Recipient; use D3\LinkmobilityClient\ValueObject\Recipient;
use Exception; use Exception;
@ -37,7 +38,7 @@ abstract class AbstractMessage
/** @var ResponseInterface */ /** @var ResponseInterface */
protected $response; protected $response;
/** @var RecipientsList */ /** @var RecipientsListInterface */
protected $recipients; protected $recipients;
/** /**
@ -66,6 +67,7 @@ abstract class AbstractMessage
*/ */
protected function setRemark(string $userId, string $recipients, string $message): void protected function setRemark(string $userId, string $recipients, string $message): void
{ {
/** @var Remark $remark */
$remark = d3GetOxidDIC()->get('d3ox.linkmobility.'.Remark::class); $remark = d3GetOxidDIC()->get('d3ox.linkmobility.'.Remark::class);
$remark->assign([ $remark->assign([
'oxtype' => self::REMARK_IDENT, 'oxtype' => self::REMARK_IDENT,
@ -84,10 +86,10 @@ abstract class AbstractMessage
} }
/** /**
* @param RecipientsList $recipients * @param RecipientsListInterface $recipients
* @return void * @return void
*/ */
protected function setRecipients(RecipientsList $recipients) protected function setRecipients(RecipientsListInterface $recipients)
{ {
$this->recipients = $recipients; $this->recipients = $recipients;
} }

View File

@ -60,7 +60,9 @@ class Sms extends AbstractMessage
return $return; return $return;
} catch (noRecipientFoundException $e) { } catch (noRecipientFoundException $e) {
$this->getLogger()->warning($e->getMessage()); $this->getLogger()->warning($e->getMessage());
d3GetOxidDIC()->get('d3ox.linkmobility.'.UtilsView::class)->addErrorToDisplay($e); /** @var UtilsView $utilsView */
$utilsView = d3GetOxidDIC()->get('d3ox.linkmobility.'.UtilsView::class);
$utilsView->addErrorToDisplay($e);
} }
return false; return false;
@ -107,7 +109,9 @@ class Sms extends AbstractMessage
return $return; return $return;
} catch (noRecipientFoundException $e) { } catch (noRecipientFoundException $e) {
$this->getLogger()->warning($e->getMessage()); $this->getLogger()->warning($e->getMessage());
d3GetOxidDIC()->get('d3ox.linkmobility.'.UtilsView::class)->addErrorToDisplay($e); /** @var UtilsView $utilsView */
$utilsView = d3GetOxidDIC()->get('d3ox.linkmobility.'.UtilsView::class);
$utilsView->addErrorToDisplay($e);
} }
return false; return false;
@ -146,11 +150,11 @@ class Sms extends AbstractMessage
} }
/** /**
* @param RecipientsList $recipientsList * @param RecipientsListInterface $recipientsList
* *
* @return bool * @return bool
*/ */
public function sendCustomRecipientMessage(RecipientsList $recipientsList): bool public function sendCustomRecipientMessage(RecipientsListInterface $recipientsList): bool
{ {
try { try {
$this->response = $response = $this->submitMessage($recipientsList); $this->response = $response = $this->submitMessage($recipientsList);
@ -159,7 +163,9 @@ class Sms extends AbstractMessage
} catch (abortSendingExceptionInterface|GuzzleException|ApiException|InvalidArgumentException $e) { } catch (abortSendingExceptionInterface|GuzzleException|ApiException|InvalidArgumentException $e) {
$this->getLogger()->warning($e->getMessage()); $this->getLogger()->warning($e->getMessage());
// Oxid does not accept throwable interface only exceptions according to definition // Oxid does not accept throwable interface only exceptions according to definition
d3GetOxidDIC()->get('d3ox.linkmobility.'.UtilsView::class)->addErrorToDisplay($e->getMessage()); /** @var UtilsView $utilsView */
$utilsView = d3GetOxidDIC()->get('d3ox.linkmobility.'.UtilsView::class);
$utilsView->addErrorToDisplay($e->getMessage());
} }
return false; return false;
@ -192,12 +198,12 @@ class Sms extends AbstractMessage
} }
/** /**
* @param RecipientsList $recipientsList * @param RecipientsListInterface $recipientsList
* @return ResponseInterface * @return ResponseInterface
* @throws ApiException * @throws ApiException
* @throws GuzzleException * @throws GuzzleException
*/ */
protected function submitMessage(RecipientsList $recipientsList): ResponseInterface protected function submitMessage(RecipientsListInterface $recipientsList): ResponseInterface
{ {
$this->setRecipients($recipientsList); $this->setRecipients($recipientsList);
/** @var Configuration $configuration */ /** @var Configuration $configuration */

View File

@ -53,19 +53,20 @@ class OrderRecipients
} }
/** /**
* @param $phoneFieldName * @param string $phoneFieldName
* @param $countryIdFieldName * @param string $countryIdFieldName
* @return Recipient|null * @return Recipient|null
*/ */
protected function getSmsRecipientByField($phoneFieldName, $countryIdFieldName): ?Recipient protected function getSmsRecipientByField(string $phoneFieldName, string $countryIdFieldName): ?Recipient
{ {
/** @var Country $country */
$country = d3GetOxidDIC()->get('d3ox.linkmobility.'.Country::class);
try { try {
/** @var string $content */ /** @var string $content */
$content = $this->order->getFieldData($phoneFieldName) ?: ''; $content = $this->order->getFieldData($phoneFieldName) ?: '';
$content = trim($content); $content = trim($content);
if (strlen($content)) { if (strlen($content)) {
$country = d3GetOxidDIC()->get('d3ox.linkmobility.'.Country::class);
/** @var string $countryId */ /** @var string $countryId */
$countryId = $this->order->getFieldData(trim($countryIdFieldName)); $countryId = $this->order->getFieldData(trim($countryIdFieldName));
$country->load($countryId); $country->load($countryId);
@ -77,7 +78,9 @@ class OrderRecipients
return $recipient; return $recipient;
} }
} catch (NumberParseException|RecipientException $e) { } catch (NumberParseException|RecipientException $e) {
d3GetOxidDIC()->get(LoggerHandler::class)->getLogger()->info( /** @var LoggerHandler $loggerHandler */
$loggerHandler = d3GetOxidDIC()->get(LoggerHandler::class);
$loggerHandler->getLogger()->info(
$e->getMessage(), $e->getMessage(),
[$content, $country->getFieldData('oxisoalpha2')] [$content, $country->getFieldData('oxisoalpha2')]
); );

View File

@ -30,14 +30,15 @@ class RequestFactory extends \D3\LinkmobilityClient\SMS\RequestFactory
$configuration = d3GetOxidDIC()->get(Configuration::class); $configuration = d3GetOxidDIC()->get(Configuration::class);
/** parent call */ /** parent call */
/** @var SmsRequestInterface $request */
$request = $this->d3CallMockableFunction([\D3\LinkmobilityClient\SMS\RequestFactory::class, 'getSmsRequest']); $request = $this->d3CallMockableFunction([\D3\LinkmobilityClient\SMS\RequestFactory::class, 'getSmsRequest']);
d3GetOxidDIC()->setParameter(Sender::class.'.args.number', $configuration->getSmsSenderNumber()); d3GetOxidDIC()->setParameter(Sender::class.'.args.number', $configuration->getSmsSenderNumber());
d3GetOxidDIC()->setParameter(Sender::class.'.args.iso2countrycode', $configuration->getSmsSenderCountry()); d3GetOxidDIC()->setParameter(Sender::class.'.args.iso2countrycode', $configuration->getSmsSenderCountry());
/** @var Sender $sender */
$sender = d3GetOxidDIC()->get(Sender::class);
$request->setTestMode($configuration->getTestMode()) $request->setTestMode($configuration->getTestMode())
->setSenderAddress( ->setSenderAddress($sender)
d3GetOxidDIC()->get(Sender::class)
)
->setSenderAddressType(RequestInterface::SENDERADDRESSTYPE_INTERNATIONAL); ->setSenderAddressType(RequestInterface::SENDERADDRESSTYPE_INTERNATIONAL);
return $request; return $request;

View File

@ -53,18 +53,20 @@ class UserRecipients
} }
/** /**
* @param $fieldName * @param string $fieldName
* @return Recipient|null * @return Recipient|null
*/ */
protected function getSmsRecipientByField($fieldName): ?Recipient protected function getSmsRecipientByField(string $fieldName): ?Recipient
{ {
/** @var Country $country */
$country = d3GetOxidDIC()->get('d3ox.linkmobility.'.Country::class);
try { try {
/** @var string $content */ /** @var string $content */
$content = $this->user->getFieldData($fieldName) ?: ''; $content = $this->user->getFieldData($fieldName) ?: '';
$content = trim($content); $content = trim($content);
if (strlen($content)) { if (strlen($content)) {
$country = d3GetOxidDIC()->get('d3ox.linkmobility.'.Country::class);
/** @var string $countryId */ /** @var string $countryId */
$countryId = $this->user->getFieldData('oxcountryid'); $countryId = $this->user->getFieldData('oxcountryid');
$country->load($countryId); $country->load($countryId);
@ -75,7 +77,9 @@ class UserRecipients
return $recipient; return $recipient;
} }
} catch (NumberParseException|RecipientException $e) { } catch (NumberParseException|RecipientException $e) {
d3GetOxidDIC()->get(LoggerHandler::class)->getLogger()->info( /** @var LoggerHandler $loggerHandler */
$loggerHandler = d3GetOxidDIC()->get(LoggerHandler::class);
$loggerHandler->getLogger()->info(
$e->getMessage(), $e->getMessage(),
[$content, $country->getFieldData('oxisoalpha2')] [$content, $country->getFieldData('oxisoalpha2')]
); );

View File

@ -47,6 +47,7 @@ class EmailCore extends EmailCore_parent
public function sendOrderEmailToUser($order, $subject = null) public function sendOrderEmailToUser($order, $subject = null)
{ {
// $ret = parent::sendOrderEmailToUser($order, $subject); // $ret = parent::sendOrderEmailToUser($order, $subject);
/** @var bool $ret */
$ret = $this->d3CallMockableFunction([EmailCore_parent::class, 'sendOrderEmailToUser'], [$order, $subject]); $ret = $this->d3CallMockableFunction([EmailCore_parent::class, 'sendOrderEmailToUser'], [$order, $subject]);
$this->d3SendOrderFinishedMessageToUser($order); $this->d3SendOrderFinishedMessageToUser($order);
@ -65,6 +66,7 @@ class EmailCore extends EmailCore_parent
public function sendSendedNowMail($order, $subject = null) public function sendSendedNowMail($order, $subject = null)
{ {
// $ret = parent::sendSendedNowMail($order, $subject); // $ret = parent::sendSendedNowMail($order, $subject);
/** @var bool $ret */
$ret = $this->d3CallMockableFunction([EmailCore_parent::class, 'sendSendedNowMail'], [$order, $subject]); $ret = $this->d3CallMockableFunction([EmailCore_parent::class, 'sendSendedNowMail'], [$order, $subject]);
$this->d3SendedNowMessage($order); $this->d3SendedNowMessage($order);
@ -82,6 +84,7 @@ class EmailCore extends EmailCore_parent
*/ */
public function d3SendOrderFinishedMessageToUser(Order $order): void public function d3SendOrderFinishedMessageToUser(Order $order): void
{ {
/** @var MessageSender $messageSender */
$messageSender = d3GetOxidDIC()->get(MessageSender::class); $messageSender = d3GetOxidDIC()->get(MessageSender::class);
$messageSender->sendOrderFinishedMessage($order, $this->d3GetOrderFinishedSmsMessageBody($order)); $messageSender->sendOrderFinishedMessage($order, $this->d3GetOrderFinishedSmsMessageBody($order));
} }
@ -111,6 +114,7 @@ class EmailCore extends EmailCore_parent
*/ */
public function d3SendedNowMessage(Order $order): void public function d3SendedNowMessage(Order $order): void
{ {
/** @var MessageSender $messageSender */
$messageSender = d3GetOxidDIC()->get(MessageSender::class); $messageSender = d3GetOxidDIC()->get(MessageSender::class);
$messageSender->sendSendedNowMessage($order, $this->d3GetSendedNowSmsMessageBody($order)); $messageSender->sendSendedNowMessage($order, $this->d3GetSendedNowSmsMessageBody($order));
} }
@ -140,6 +144,7 @@ class EmailCore extends EmailCore_parent
*/ */
public function d3SendCancelMessage(Order $order): void public function d3SendCancelMessage(Order $order): void
{ {
/** @var MessageSender $messageSender */
$messageSender = d3GetOxidDIC()->get(MessageSender::class); $messageSender = d3GetOxidDIC()->get(MessageSender::class);
$messageSender->sendCancelOrderMessage($order, $this->d3GetCancelOrderSmsMessageBody($order)); $messageSender->sendCancelOrderMessage($order, $this->d3GetCancelOrderSmsMessageBody($order));
} }

View File

@ -17,8 +17,10 @@ namespace D3\Linkmobility4OXID\Setup;
use D3\Linkmobility4OXID\Application\Model\MessageTypes\AbstractMessage; use D3\Linkmobility4OXID\Application\Model\MessageTypes\AbstractMessage;
use Doctrine\DBAL\Driver\Exception as DoctrineDriverException; use Doctrine\DBAL\Driver\Exception as DoctrineDriverException;
use Doctrine\DBAL\Driver\ResultStatement;
use Doctrine\DBAL\Exception as DoctrineException; use Doctrine\DBAL\Exception as DoctrineException;
use Doctrine\DBAL\Query\QueryBuilder; use Doctrine\DBAL\Query\QueryBuilder;
use Doctrine\DBAL\Statement;
use Monolog\Logger; use Monolog\Logger;
use OxidEsales\Eshop\Core\Database\Adapter\DatabaseInterface; use OxidEsales\Eshop\Core\Database\Adapter\DatabaseInterface;
use OxidEsales\Eshop\Core\Database\Adapter\Doctrine\Database; use OxidEsales\Eshop\Core\Database\Adapter\Doctrine\Database;
@ -30,6 +32,7 @@ use OxidEsales\Eshop\Core\Exception\StandardException;
use OxidEsales\Eshop\Core\Registry; use OxidEsales\Eshop\Core\Registry;
use OxidEsales\Eshop\Core\UtilsView; use OxidEsales\Eshop\Core\UtilsView;
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory; use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
use OxidEsales\EshopCommunity\Internal\Framework\Database\QueryBuilderFactory;
use OxidEsales\EshopCommunity\Internal\Framework\Database\QueryBuilderFactoryInterface; use OxidEsales\EshopCommunity\Internal\Framework\Database\QueryBuilderFactoryInterface;
use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface; use Psr\Container\ContainerInterface;
@ -55,7 +58,7 @@ class Actions
$logger->error($e->getMessage()); $logger->error($e->getMessage());
/** @var UtilsView $utilsView */ /** @var UtilsView $utilsView */
$utilsView = d3GetOxidDIC()->get('d3ox.linkmobility.'.UtilsView::class); $utilsView = d3GetOxidDIC()->get('d3ox.linkmobility.'.UtilsView::class);
$utilsView->addErrorToDisplay($e); $utilsView->addErrorToDisplay($e->getMessage());
} }
} }
@ -64,7 +67,7 @@ class Actions
/** /**
* Regenerate views for changed tables * Regenerate views for changed tables
*/ */
public function regenerateViews() public function regenerateViews(): void
{ {
/** @var DbMetaDataHandler $oDbMetaDataHandler */ /** @var DbMetaDataHandler $oDbMetaDataHandler */
$oDbMetaDataHandler = d3GetOxidDIC()->get('d3ox.linkmobility.'.DbMetaDataHandler::class); $oDbMetaDataHandler = d3GetOxidDIC()->get('d3ox.linkmobility.'.DbMetaDataHandler::class);
@ -101,8 +104,10 @@ class Actions
*/ */
protected function getRemarkTypeFieldType(): string protected function getRemarkTypeFieldType(): string
{ {
/** @var QueryBuilderFactory $queryBuilderFactory */
$queryBuilderFactory = $this->getContainer()->get(QueryBuilderFactoryInterface::class);
/** @var QueryBuilder $qb */ /** @var QueryBuilder $qb */
$qb = $this->getContainer()->get(QueryBuilderFactoryInterface::class)->create(); $qb = $queryBuilderFactory->create();
$qb->select('column_type') $qb->select('column_type')
->from('INFORMATION_SCHEMA.COLUMNS') ->from('INFORMATION_SCHEMA.COLUMNS')
->where( ->where(
@ -122,7 +127,10 @@ class Actions
) )
); );
return (string) $qb->execute()->fetchOne(); /** @var Statement $statement */
$statement = $qb->execute();
return (string) $statement->fetchOne();
} }
/** /**
@ -150,7 +158,7 @@ class Actions
} }
/** /**
* @return array * @return string[]
* @throws DoctrineDriverException * @throws DoctrineDriverException
* @throws DoctrineException * @throws DoctrineException
*/ */

View File

@ -33,7 +33,7 @@ class Events
* @throws ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface * @throws NotFoundExceptionInterface
*/ */
public static function onActivate() public static function onActivate(): void
{ {
/** @var Actions $actions */ /** @var Actions $actions */
$actions = d3GetOxidDIC()->get(Actions::class); $actions = d3GetOxidDIC()->get(Actions::class);
@ -41,7 +41,7 @@ class Events
$actions->regenerateViews(); $actions->regenerateViews();
} }
public static function onDeactivate() public static function onDeactivate(): void
{ {
} }
} }