From 328a98f90a38ecbdd10453eb9e833a8ede6a524b Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Wed, 13 Jul 2022 13:23:48 +0200 Subject: [PATCH] apply PSR-12 rules --- .php-cs-fixer.php | 13 ++++++++ .../Controller/Admin/AdminOrder.php | 24 +++++++-------- .../Controller/Admin/AdminUser.php | 22 +++++++------- src/Application/Model/Configuration.php | 4 +-- .../abortSendingExceptionInterface.php | 3 +- .../Exceptions/noRecipientFoundException.php | 6 ++-- .../Exceptions/successfullySentException.php | 8 ++--- src/Application/Model/MessageClient.php | 2 +- src/Application/Model/MessageSender.php | 17 ++++++----- src/Application/Model/OrderRecipients.php | 11 +++---- src/Application/Model/RequestFactory.php | 8 ++--- src/Application/Model/Sms.php | 30 +++++++++---------- src/Application/Model/UserRecipients.php | 12 ++++---- src/IntelliSenseHelper.php | 10 +++++-- src/Modules/Application/Model/OrderModel.php | 4 +-- src/Modules/Core/EmailCore.php | 4 +-- src/metadata.php | 2 +- 17 files changed, 100 insertions(+), 80 deletions(-) create mode 100644 .php-cs-fixer.php diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php new file mode 100644 index 0000000..244806f --- /dev/null +++ b/.php-cs-fixer.php @@ -0,0 +1,13 @@ +in(__DIR__) +; + +$config = new PhpCsFixer\Config(); +return $config->setRules([ + '@PHP70Migration' => true, + '@PSR12' => true + ]) + ->setFinder($finder) +; \ No newline at end of file diff --git a/src/Application/Controller/Admin/AdminOrder.php b/src/Application/Controller/Admin/AdminOrder.php index bf1fedd..0479b86 100644 --- a/src/Application/Controller/Admin/AdminOrder.php +++ b/src/Application/Controller/Admin/AdminOrder.php @@ -56,7 +56,7 @@ class AdminOrder extends AdminController public function getRecipientFromCurrentOrder() { try { - return oxNew( OrderRecipients::class, $this->order )->getSmsRecipient(); + return oxNew(OrderRecipients::class, $this->order)->getSmsRecipient(); } catch (noRecipientFoundException $e) { Registry::getUtilsView()->addErrorToDisplay( Registry::getLang()->translateString($e->getMessage()) @@ -70,7 +70,7 @@ class AdminOrder extends AdminController */ public function send() { - $messageBody = Registry::getRequest()->getRequestEscapedParameter( 'messagebody' ); + $messageBody = Registry::getRequest()->getRequestEscapedParameter('messagebody'); if (strlen($messageBody) <= 1) { Registry::getUtilsView()->addErrorToDisplay( @@ -83,16 +83,16 @@ class AdminOrder extends AdminController $order->load($this->getEditObjectId()); try { - $sms = oxNew( Sms::class, $messageBody ); - if ( $sms->sendOrderMessage( $order ) ) { - $this->setRemark( $sms->getRecipientsList(), $sms->getMessage() ); + $sms = oxNew(Sms::class, $messageBody); + if ($sms->sendOrderMessage($order)) { + $this->setRemark($sms->getRecipientsList(), $sms->getMessage()); Registry::getUtilsView()->addErrorToDisplay( - oxNew(successfullySentException::class, $sms->getResponse()->getSmsCount() ) + oxNew(successfullySentException::class, $sms->getResponse()->getSmsCount()) ); } else { Registry::getUtilsView()->addErrorToDisplay( sprintf( - Registry::getLang()->translateString( 'D3LM_EXC_MESSAGE_UNEXPECTED_ERR_SEND' ), + Registry::getLang()->translateString('D3LM_EXC_MESSAGE_UNEXPECTED_ERR_SEND'), $sms->getResponse()->getErrorMessage() ) ); @@ -107,14 +107,14 @@ class AdminOrder extends AdminController * * @throws Exception */ - protected function setRemark( $recipients, $messageBody ) + protected function setRemark($recipients, $messageBody) { - $remark = oxNew( Remark::class ); - $remark->assign( [ + $remark = oxNew(Remark::class); + $remark->assign([ 'oxtype' => AdminUser::REMARK_IDENT, 'oxparentid' => $this->order->getUser()->getId(), 'oxtext' => $recipients.PHP_EOL.$messageBody - ] ); + ]); $remark->save(); } -} \ No newline at end of file +} diff --git a/src/Application/Controller/Admin/AdminUser.php b/src/Application/Controller/Admin/AdminUser.php index 957bcb6..2edd82f 100644 --- a/src/Application/Controller/Admin/AdminUser.php +++ b/src/Application/Controller/Admin/AdminUser.php @@ -27,8 +27,8 @@ use OxidEsales\Eshop\Core\Registry; class AdminUser extends AdminController { - const REMARK_IDENT = 'LMSMS'; - + public const REMARK_IDENT = 'LMSMS'; + protected $_sThisTemplate = 'd3adminuser.tpl'; /** @@ -57,7 +57,7 @@ class AdminUser extends AdminController public function getRecipientFromCurrentUser() { try { - return oxNew( UserRecipients::class, $this->user )->getSmsRecipient(); + return oxNew(UserRecipients::class, $this->user)->getSmsRecipient(); } catch (noRecipientFoundException $e) { Registry::getUtilsView()->addErrorToDisplay( Registry::getLang()->translateString($e->getMessage()) @@ -71,7 +71,7 @@ class AdminUser extends AdminController */ public function send() { - $messageBody = Registry::getRequest()->getRequestEscapedParameter( 'messagebody' ); + $messageBody = Registry::getRequest()->getRequestEscapedParameter('messagebody'); if (strlen($messageBody) <= 1) { Registry::getUtilsView()->addErrorToDisplay( @@ -85,7 +85,7 @@ class AdminUser extends AdminController $sms = oxNew(Sms::class, $messageBody); if ($sms->sendUserAccountMessage($user)) { - $this->setRemark( $sms->getRecipientsList(), $sms->getMessage() ); + $this->setRemark($sms->getRecipientsList(), $sms->getMessage()); Registry::getUtilsView()->addErrorToDisplay( sprintf( Registry::getLang()->translateString('D3LM_EXC_SMS_SUCC_SENT'), @@ -95,7 +95,7 @@ class AdminUser extends AdminController } else { Registry::getUtilsView()->addErrorToDisplay( sprintf( - Registry::getLang()->translateString( 'D3LM_EXC_MESSAGE_UNEXPECTED_ERR_SEND' ), + Registry::getLang()->translateString('D3LM_EXC_MESSAGE_UNEXPECTED_ERR_SEND'), $sms->getResponse()->getErrorMessage() ) ); @@ -107,14 +107,14 @@ class AdminUser extends AdminController * * @throws Exception */ - protected function setRemark( $recipients, $messageBody ) + protected function setRemark($recipients, $messageBody) { - $remark = oxNew( Remark::class ); - $remark->assign( [ + $remark = oxNew(Remark::class); + $remark->assign([ 'oxtype' => AdminUser::REMARK_IDENT, 'oxparentid' => $this->getEditObjectId(), 'oxtext' => $recipients.PHP_EOL.$messageBody - ] ); + ]); $remark->save(); } -} \ No newline at end of file +} diff --git a/src/Application/Model/Configuration.php b/src/Application/Model/Configuration.php index 09699dc..3a52c73 100644 --- a/src/Application/Model/Configuration.php +++ b/src/Application/Model/Configuration.php @@ -37,7 +37,7 @@ class Configuration */ public function getTestMode(): bool { - return (bool) Registry::getConfig()->getConfigParam( 'd3linkmobility_debug'); + return (bool) Registry::getConfig()->getConfigParam('d3linkmobility_debug'); } /** @@ -63,4 +63,4 @@ class Configuration return strtoupper($country); } -} \ No newline at end of file +} diff --git a/src/Application/Model/Exceptions/abortSendingExceptionInterface.php b/src/Application/Model/Exceptions/abortSendingExceptionInterface.php index b2de845..1c3e20d 100644 --- a/src/Application/Model/Exceptions/abortSendingExceptionInterface.php +++ b/src/Application/Model/Exceptions/abortSendingExceptionInterface.php @@ -16,4 +16,5 @@ declare(strict_types=1); namespace D3\Linkmobility4OXID\Application\Model\Exceptions; interface abortSendingExceptionInterface -{} \ No newline at end of file +{ +} diff --git a/src/Application/Model/Exceptions/noRecipientFoundException.php b/src/Application/Model/Exceptions/noRecipientFoundException.php index 150cf0a..f1edbc2 100644 --- a/src/Application/Model/Exceptions/noRecipientFoundException.php +++ b/src/Application/Model/Exceptions/noRecipientFoundException.php @@ -20,8 +20,8 @@ use OxidEsales\Eshop\Core\Exception\StandardException; class noRecipientFoundException extends StandardException implements abortSendingExceptionInterface { - public function __construct( $sMessage = "D3LM_EXC_NO_RECIPIENT_SET", $iCode = 0, Exception $previous = null ) + public function __construct($sMessage = "D3LM_EXC_NO_RECIPIENT_SET", $iCode = 0, Exception $previous = null) { - parent::__construct( $sMessage, $iCode, $previous ); + parent::__construct($sMessage, $iCode, $previous); } -} \ No newline at end of file +} diff --git a/src/Application/Model/Exceptions/successfullySentException.php b/src/Application/Model/Exceptions/successfullySentException.php index 9fe76dd..a219dd8 100644 --- a/src/Application/Model/Exceptions/successfullySentException.php +++ b/src/Application/Model/Exceptions/successfullySentException.php @@ -26,10 +26,10 @@ class successfullySentException extends Exception * @param int $code * @param Throwable|null $previous */ - public function __construct( $messageCount = 1, $code = 0, Throwable $previous = null ) + public function __construct($messageCount = 1, $code = 0, Throwable $previous = null) { - $message = sprintf( Registry::getLang()->translateString( 'D3LM_EXC_SMS_SUCC_SENT' ), $messageCount); + $message = sprintf(Registry::getLang()->translateString('D3LM_EXC_SMS_SUCC_SENT'), $messageCount); - parent::__construct( $message, $code, $previous ); + parent::__construct($message, $code, $previous); } -} \ No newline at end of file +} diff --git a/src/Application/Model/MessageClient.php b/src/Application/Model/MessageClient.php index 2e15342..fc1b213 100644 --- a/src/Application/Model/MessageClient.php +++ b/src/Application/Model/MessageClient.php @@ -29,4 +29,4 @@ class MessageClient $client->setLogger(Registry::getLogger()); return $client; } -} \ No newline at end of file +} diff --git a/src/Application/Model/MessageSender.php b/src/Application/Model/MessageSender.php index ccd9c66..d40c82e 100644 --- a/src/Application/Model/MessageSender.php +++ b/src/Application/Model/MessageSender.php @@ -64,11 +64,12 @@ class MessageSender } try { - $sms = oxNew( Sms::class, $messageBody ); - if ( $sms->sendOrderMessage( $order ) ) { - $this->setRemark( $order->getId(), $sms->getRecipientsList(), $sms->getMessage() ); + $sms = oxNew(Sms::class, $messageBody); + if ($sms->sendOrderMessage($order)) { + $this->setRemark($order->getId(), $sms->getRecipientsList(), $sms->getMessage()); } - } catch (noRecipientFoundException $e) {} + } catch (noRecipientFoundException $e) { + } } /** @@ -77,12 +78,12 @@ class MessageSender */ protected function setRemark($orderId, $recipients, $message) { - $remark = oxNew( Remark::class ); - $remark->assign( [ + $remark = oxNew(Remark::class); + $remark->assign([ 'oxtype' => AdminUser::REMARK_IDENT, 'oxparentid' => $orderId, 'oxtext' => $recipients.PHP_EOL.$message - ] ); + ]); $remark->save(); } -} \ No newline at end of file +} diff --git a/src/Application/Model/OrderRecipients.php b/src/Application/Model/OrderRecipients.php index 1d128e3..6e466b6 100644 --- a/src/Application/Model/OrderRecipients.php +++ b/src/Application/Model/OrderRecipients.php @@ -39,8 +39,7 @@ class OrderRecipients */ public function getSmsRecipient(): Recipient { - foreach ($this->getSmsRecipientFields() as $phoneFieldName => $countryIdFieldName) - { + foreach ($this->getSmsRecipientFields() as $phoneFieldName => $countryIdFieldName) { $content = trim($this->order->getFieldData($phoneFieldName)); if (strlen($content)) { @@ -72,7 +71,7 @@ class OrderRecipients /** * @return array */ - public function getSanitizedCustomFields() : array + public function getSanitizedCustomFields(): array { $customFields = (array) Registry::getConfig()->getConfigParam('d3linkmobility_smsOrderRecipientsFields'); array_walk($customFields, [$this, 'checkFieldExists']); @@ -85,9 +84,11 @@ class OrderRecipients $checkPhoneFieldName = trim($checkPhoneFieldName); $allFieldNames = oxNew(Order::class)->getFieldNames(); - array_walk($allFieldNames, function(&$value) {$value = strtolower($value);}); + array_walk($allFieldNames, function (&$value) { + $value = strtolower($value); + }); $checkPhoneFieldName = in_array(strtolower($checkPhoneFieldName), $allFieldNames) && in_array(strtolower($checkCountryFieldName), $allFieldNames) ? $checkPhoneFieldName : null; } -} \ No newline at end of file +} diff --git a/src/Application/Model/RequestFactory.php b/src/Application/Model/RequestFactory.php index b366b01..7f0004c 100644 --- a/src/Application/Model/RequestFactory.php +++ b/src/Application/Model/RequestFactory.php @@ -23,15 +23,15 @@ class RequestFactory extends \D3\LinkmobilityClient\SMS\RequestFactory { public function getSmsRequest(): SmsRequestInterface { - $configuration = oxNew( Configuration::class ); + $configuration = oxNew(Configuration::class); $request = parent::getSmsRequest(); $request->setTestMode($configuration->getTestMode()) ->setSenderAddress( - oxNew( Sender::class, $configuration->getSmsSenderNumber(), $configuration->getSmsSenderCountry() ) + oxNew(Sender::class, $configuration->getSmsSenderNumber(), $configuration->getSmsSenderCountry()) ) - ->setSenderAddressType( RequestInterface::SENDERADDRESSTYPE_INTERNATIONAL ); + ->setSenderAddressType(RequestInterface::SENDERADDRESSTYPE_INTERNATIONAL); return $request; } -} \ No newline at end of file +} diff --git a/src/Application/Model/Sms.php b/src/Application/Model/Sms.php index 7ac80c9..092a14c 100644 --- a/src/Application/Model/Sms.php +++ b/src/Application/Model/Sms.php @@ -51,7 +51,7 @@ class Sms { try { return $this->sendCustomRecipientMessage( - [ oxNew( UserRecipients::class, $user )->getSmsRecipient() ] + [ oxNew(UserRecipients::class, $user)->getSmsRecipient() ] ); } catch (noRecipientFoundException $e) { Registry::getLogger()->warning($e->getMessage()); @@ -72,7 +72,7 @@ class Sms try { Registry::getLogger()->debug('startRequest', ['orderId' => $order->getId()]); $return = $this->sendCustomRecipientMessage( - [ oxNew( OrderRecipients::class, $order )->getSmsRecipient() ] + [ oxNew(OrderRecipients::class, $order)->getSmsRecipient() ] ); Registry::getLogger()->debug('finishRequest', ['orderId' => $order->getId()]); return $return; @@ -91,12 +91,12 @@ class Sms { try { $this->setRecipients($recipientsArray); - $configuration = oxNew( Configuration::class ); - $client = oxNew( MessageClient::class )->getClient(); + $configuration = oxNew(Configuration::class); + $client = oxNew(MessageClient::class)->getClient(); /** @var SmsRequestInterface $request */ - $request = oxNew( RequestFactory::class, $this->getMessage(), $client )->getSmsRequest(); - $request->setTestMode( $configuration->getTestMode() )->setMethod( RequestInterface::METHOD_POST ) + $request = oxNew(RequestFactory::class, $this->getMessage(), $client)->getSmsRequest(); + $request->setTestMode($configuration->getTestMode())->setMethod(RequestInterface::METHOD_POST) ->setSenderAddress( oxNew( Sender::class, @@ -104,19 +104,19 @@ class Sms $configuration->getSmsSenderCountry() ) ) - ->setSenderAddressType( RequestInterface::SENDERADDRESSTYPE_INTERNATIONAL ); + ->setSenderAddressType(RequestInterface::SENDERADDRESSTYPE_INTERNATIONAL); $recipientsList = $request->getRecipientsList(); foreach ($recipientsArray as $recipient) { - $recipientsList->add( $recipient ); + $recipientsList->add($recipient); } - $response = $client->request( $request ); + $response = $client->request($request); $this->response = $response; if (false === $response->isSuccessful()) { - Registry::getLogger()->warning( $response->getErrorMessage(), [$request->getBody()] ); + Registry::getLogger()->warning($response->getErrorMessage(), [$request->getBody()]); } return $response->isSuccessful(); @@ -129,7 +129,7 @@ class Sms } catch (ApiException $e) { Registry::getLogger()->warning($e->getMessage()); Registry::getUtilsView()->addErrorToDisplay($e); - } catch ( InvalidArgumentException $e) { + } catch (InvalidArgumentException $e) { Registry::getLogger()->warning($e->getMessage()); Registry::getUtilsView()->addErrorToDisplay($e); } @@ -150,7 +150,7 @@ class Sms $this->recipients = $recipients; } - public function getRecipientsList() : string + public function getRecipientsList(): string { $list = []; /** @var Recipient $recipient */ @@ -166,7 +166,7 @@ class Sms * * @return string */ - protected function sanitizeMessage($message) : string + protected function sanitizeMessage($message): string { $message = trim(strip_tags($message)); $message = $this->removeLineBreaks ? str_replace(["\r", "\n"], ' ', $message) : $message; @@ -174,8 +174,8 @@ class Sms return $this->removeMultipleSpaces ? preg_replace($regexp, ' ', $message) : $message; } - public function getMessage() : string + public function getMessage(): string { return $this->message; } -} \ No newline at end of file +} diff --git a/src/Application/Model/UserRecipients.php b/src/Application/Model/UserRecipients.php index ad5a66e..3d72c0f 100644 --- a/src/Application/Model/UserRecipients.php +++ b/src/Application/Model/UserRecipients.php @@ -39,11 +39,9 @@ class UserRecipients */ public function getSmsRecipient(): Recipient { - foreach ($this->getSmsRecipientFields() as $fieldName) - { + foreach ($this->getSmsRecipientFields() as $fieldName) { $content = trim($this->user->getFieldData($fieldName)); if (strlen($content)) { - $country = oxNew(Country::class); $country->load($this->user->getFieldData('oxcountryid')); @@ -73,7 +71,7 @@ class UserRecipients /** * @return array */ - public function getSanitizedCustomFields() : array + public function getSanitizedCustomFields(): array { $customFields = (array) Registry::getConfig()->getConfigParam('d3linkmobility_smsUserRecipientsFields'); array_walk($customFields, [$this, 'checkFieldExists']); @@ -88,8 +86,10 @@ class UserRecipients $checkFieldName = trim($checkFieldName); $allFieldNames = oxNew(User::class)->getFieldNames(); - array_walk($allFieldNames, function(&$value) {$value = strtolower($value);}); + array_walk($allFieldNames, function (&$value) { + $value = strtolower($value); + }); $checkFieldName = in_array(strtolower($checkFieldName), $allFieldNames) ? $checkFieldName : null; } -} \ No newline at end of file +} diff --git a/src/IntelliSenseHelper.php b/src/IntelliSenseHelper.php index 69d995c..b097939 100644 --- a/src/IntelliSenseHelper.php +++ b/src/IntelliSenseHelper.php @@ -17,12 +17,16 @@ namespace D3\Linkmobility4OXID\Modules\Aplication\Model { use OxidEsales\Eshop\Application\Model\Order; - class OrderModel_parent extends Order{} + class OrderModel_parent extends Order + { + } } namespace D3\Linkmobility4OXID\Modules\Core { use OxidEsales\Eshop\Core\Email; - class EmailCore_parent extends Email{} -} \ No newline at end of file + class EmailCore_parent extends Email + { + } +} diff --git a/src/Modules/Application/Model/OrderModel.php b/src/Modules/Application/Model/OrderModel.php index 10fbc89..f8b2199 100644 --- a/src/Modules/Application/Model/OrderModel.php +++ b/src/Modules/Application/Model/OrderModel.php @@ -24,8 +24,8 @@ class OrderModel extends OrderModel_parent parent::cancelOrder(); if ($this->getFieldData('oxstorno') === 1) { - $Email = oxNew( Email::class ); + $Email = oxNew(Email::class); $Email->d3SendCancelMessage($this); } } -} \ No newline at end of file +} diff --git a/src/Modules/Core/EmailCore.php b/src/Modules/Core/EmailCore.php index 7d3184f..62c4af3 100644 --- a/src/Modules/Core/EmailCore.php +++ b/src/Modules/Core/EmailCore.php @@ -128,7 +128,7 @@ class EmailCore extends EmailCore_parent * * @return TemplateRendererInterface */ - protected function d3GetTplRenderer() : TemplateRendererInterface + protected function d3GetTplRenderer(): TemplateRendererInterface { $bridge = ContainerFactory::getInstance()->getContainer() ->get(TemplateRendererBridgeInterface::class); @@ -136,4 +136,4 @@ class EmailCore extends EmailCore_parent return $bridge->getTemplateRenderer(); } -} \ No newline at end of file +} diff --git a/src/metadata.php b/src/metadata.php index fa51c1e..725899a 100644 --- a/src/metadata.php +++ b/src/metadata.php @@ -123,4 +123,4 @@ $aModule = [ 'value' => false ] ] -]; \ No newline at end of file +];