From 817f9e68a2299bb4d43f0101dbe4fb9863932fb7 Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Sun, 7 Aug 2022 22:18:23 +0200 Subject: [PATCH] fix code style --- .gitignore | 1 + .php-cs-fixer.php | 12 ++++ composer.json | 4 ++ .../d3linkmobility_ordermanager_action.php | 59 ++++++++++--------- .../Model/Exceptions/emptyMesageException.php | 2 +- .../d3linkmobility_ordermanager_sender.php | 8 +-- .../de/d3_linkmobility_ordermanager_lang.php | 4 +- src/IntelliSenseHelper.php | 6 +- .../d3ordermanager_conf_linkmobility.php | 2 +- src/metadata.php | 6 +- 10 files changed, 62 insertions(+), 42 deletions(-) create mode 100644 .gitignore create mode 100644 .php-cs-fixer.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3d0b430 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.php_cs.cache diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php new file mode 100644 index 0000000..4263c3d --- /dev/null +++ b/.php-cs-fixer.php @@ -0,0 +1,12 @@ +in(__DIR__) +; + +$config = new PhpCsFixer\Config(); +return $config->setRules([ + '@PHP73Migration' => true, + '@PSR12' => true +]) + ->setFinder($finder); \ No newline at end of file diff --git a/composer.json b/composer.json index 27ef969..4e69ea5 100644 --- a/composer.json +++ b/composer.json @@ -36,6 +36,10 @@ "d3/ordermanager": "^5.0", "d3/linkmobility4oxid": "^1.0" }, + "require-dev": { + "php": "^7.4", + "friendsofphp/php-cs-fixer": "^3.9" + }, "autoload": { "psr-4": { "D3\\Linkmobility4Ordermanager\\": "../../../source/modules/d3/linkmobility4ordermanager" diff --git a/src/Application/Model/Actions/d3linkmobility_ordermanager_action.php b/src/Application/Model/Actions/d3linkmobility_ordermanager_action.php index 5ee0a7f..f810dfa 100644 --- a/src/Application/Model/Actions/d3linkmobility_ordermanager_action.php +++ b/src/Application/Model/Actions/d3linkmobility_ordermanager_action.php @@ -38,28 +38,28 @@ use OxidEsales\Eshop\Core\Registry; class d3linkmobility_ordermanager_action extends d3ordermanager_action_abstract { public $sTplName = 'd3linkmobility_ordermanager_action.tpl'; - CONST ACTIVE_SWITCH = 'blActionLinkmobility_status'; + public const ACTIVE_SWITCH = 'blActionLinkmobility_status'; public $sTitleIdent = 'D3_LINKMOBILITY_ORDERMANAGER_ACTION'; - CONST SOURCE_TEMPLATE = 'template'; - CONST SOURCE_CMS = 'cms'; + public const SOURCE_TEMPLATE = 'template'; + public const SOURCE_CMS = 'cms'; /** * @return array */ - public final function isAllowedInEditions(): array + final public function isAllowedInEditions(): array { return [ d3ordermanager_conf::SERIAL_BIT_FREE_EDITION, d3ordermanager_conf::SERIAL_BIT_STANDARD_EDITION, - d3ordermanager_conf::SERIAL_BIT_PREMIUM_EDITION + d3ordermanager_conf::SERIAL_BIT_PREMIUM_EDITION, ]; } /** * @return string */ - public function getUnvalidConfigurationMessageIdent() : string + public function getUnvalidConfigurationMessageIdent(): string { if ($this->hasRequiredValuesNoSource(false)) { return 'D3_ORDERMANAGER_ACTION_LINKMOBILITYMESSAGE_ERR_NOVALIDSOURCE'; @@ -117,7 +117,8 @@ class d3linkmobility_ordermanager_action extends d3ordermanager_action_abstract { $aMailDesc = []; ($this->getManager()->getValue('blLinkMobilityMessageToCustomer') ? $aMailDesc[] = 'Customer' : ''); - ($this->getManager()->getValue('blLinkMobilityMessageToCustom') ? + ( + $this->getManager()->getValue('blLinkMobilityMessageToCustom') ? $aMailDesc[] = 'Custom: ' . $this->getManager()->getValue('sLinkMobilityMessageToCustomAddress') : '' ); @@ -144,7 +145,7 @@ class d3linkmobility_ordermanager_action extends d3ordermanager_action_abstract */ protected function hasRequiredValuesNoSource(bool $blExpected): bool { - $source = (string) $this->getManager()->getValue( 'sLinkMobilityMessageFromSource' ); + $source = (string) $this->getManager()->getValue('sLinkMobilityMessageFromSource'); $return = strlen(trim($source)) && in_array(trim($source), [self::SOURCE_CMS, self::SOURCE_TEMPLATE]); @@ -159,21 +160,21 @@ class d3linkmobility_ordermanager_action extends d3ordermanager_action_abstract */ protected function hasRequiredValuesTplSource(bool $blExpected): bool { - $source = (string) $this->getManager()->getValue( 'sLinkMobilityMessageFromSource' ); + $source = (string) $this->getManager()->getValue('sLinkMobilityMessageFromSource'); if (trim($source) !== self::SOURCE_TEMPLATE) { return false; } - $template = (string) $this->getManager()->getValue( 'sLinkMobilityMessageFromTemplatename' ); - $theme = (string) $this->getManager()->getValue( 'sLinkMobilityMessageFromTheme' ); + $template = (string) $this->getManager()->getValue('sLinkMobilityMessageFromTemplatename'); + $theme = (string) $this->getManager()->getValue('sLinkMobilityMessageFromTheme'); if ($blExpected === true) { - return (bool) strlen( trim( $template ) ) === true && - (bool) strlen( trim( $theme ) ) === true; + return (bool) strlen(trim($template)) === true && + (bool) strlen(trim($theme)) === true; } else { - return (bool) strlen( trim( $template ) ) === false || - (bool) strlen( trim( $theme ) ) === false; + return (bool) strlen(trim($template)) === false || + (bool) strlen(trim($theme)) === false; } } @@ -184,7 +185,7 @@ class d3linkmobility_ordermanager_action extends d3ordermanager_action_abstract */ protected function hasRequiredValuesCmsSource(bool $blExpected): bool { - $source = (string) $this->getManager()->getValue( 'sLinkMobilityMessageFromSource' ); + $source = (string) $this->getManager()->getValue('sLinkMobilityMessageFromSource'); if (trim($source) !== self::SOURCE_CMS) { return false; @@ -192,14 +193,14 @@ class d3linkmobility_ordermanager_action extends d3ordermanager_action_abstract /** @var Content $content */ $content = oxNew(Content::class); - $contentname = (string) $this->getManager()->getValue( 'sLinkMobilityMessageFromContentname' ); + $contentname = (string) $this->getManager()->getValue('sLinkMobilityMessageFromContentname'); if ($blExpected === true) { - return (bool) strlen( trim( $contentname ) ) === true && - $content->exists(trim( $contentname )) === true; + return (bool) strlen(trim($contentname)) === true && + $content->exists(trim($contentname)) === true; } else { - return (bool) strlen( trim( $contentname ) ) === false || - $content->exists(trim( $contentname )) === false; + return (bool) strlen(trim($contentname)) === false || + $content->exists(trim($contentname)) === false; } } @@ -208,14 +209,14 @@ class d3linkmobility_ordermanager_action extends d3ordermanager_action_abstract */ protected function hasRequiredValuesRecipient(): bool { - $toCust = (bool) $this->getManager()->getValue( 'blLinkMobilityMessageToCustomer' ); - $toCustom = (bool) $this->getManager()->getValue( 'blLinkMobilityMessageToCustom' ); - $toCustomAddress = (string) $this->getManager()->getValue( 'sLinkMobilityMessageToCustomAddress' ); + $toCust = (bool) $this->getManager()->getValue('blLinkMobilityMessageToCustomer'); + $toCustom = (bool) $this->getManager()->getValue('blLinkMobilityMessageToCustom'); + $toCustomAddress = (string) $this->getManager()->getValue('sLinkMobilityMessageToCustomAddress'); return $toCust || ( - $toCustom && - (bool) strlen( trim( $toCustomAddress ) ) - ); + $toCustom && + (bool) strlen(trim($toCustomAddress)) + ); } /** @@ -272,8 +273,8 @@ class d3linkmobility_ordermanager_action extends d3ordermanager_action_abstract /** * @return string */ - public function getActiveSwitchParameter() : string + public function getActiveSwitchParameter(): string { return self::ACTIVE_SWITCH; } -} \ No newline at end of file +} diff --git a/src/Application/Model/Exceptions/emptyMesageException.php b/src/Application/Model/Exceptions/emptyMesageException.php index 7cacf32..693611d 100644 --- a/src/Application/Model/Exceptions/emptyMesageException.php +++ b/src/Application/Model/Exceptions/emptyMesageException.php @@ -24,4 +24,4 @@ class emptyMesageException extends StandardException $sMessage = 'empty message content in task '.$sMessage; parent::__construct($sMessage, $iCode, $previous); } -} \ No newline at end of file +} diff --git a/src/Application/Model/d3linkmobility_ordermanager_sender.php b/src/Application/Model/d3linkmobility_ordermanager_sender.php index d65d57d..6390ff2 100644 --- a/src/Application/Model/d3linkmobility_ordermanager_sender.php +++ b/src/Application/Model/d3linkmobility_ordermanager_sender.php @@ -123,7 +123,7 @@ class d3linkmobility_ordermanager_sender // ToDo: check in TWIG and change to a generic solution (e.g. path names in template name) // Smarty only if (method_exists($templateEngine, '__set')) { - $templateEngine->__set( 'template_dir', $this->getTemplateDir4OrderManager( $oManager ) ); + $templateEngine->__set('template_dir', $this->getTemplateDir4OrderManager($oManager)); } foreach ($viewData as $id => $value) { @@ -190,7 +190,7 @@ class d3linkmobility_ordermanager_sender * @param Manager $oManager * @return string */ - public function getTemplateDir4OrderManager( Manager $oManager ): string + public function getTemplateDir4OrderManager(Manager $oManager): string { if ($oManager->getValue('sLinkMobilityMessageFromTheme') == 'module') { $sModuleId = $oManager->getValue('sLinkMobilityMessageFromModulePath'); @@ -261,7 +261,7 @@ class d3linkmobility_ordermanager_sender if (strlen($customAddresses)) { foreach (explode(';', $customAddresses) as $addressGroups) { - list($phoneNumber, $countryId) = explode('@', trim($addressGroups)); + [$phoneNumber, $countryId] = explode('@', trim($addressGroups)); $addresses[trim($phoneNumber)] = trim($countryId); } } @@ -300,4 +300,4 @@ class d3linkmobility_ordermanager_sender { return $this->manager; } -} \ No newline at end of file +} diff --git a/src/Application/views/admin/de/d3_linkmobility_ordermanager_lang.php b/src/Application/views/admin/de/d3_linkmobility_ordermanager_lang.php index dfc2183..80ffc65 100644 --- a/src/Application/views/admin/de/d3_linkmobility_ordermanager_lang.php +++ b/src/Application/views/admin/de/d3_linkmobility_ordermanager_lang.php @@ -17,7 +17,7 @@ declare(strict_types=1); $sLangName = 'Deutsch'; -$aLang = array( +$aLang = [ 'charset' => 'UTF-8', 'D3_LINKMOBILITY_ORDERMANAGER_ACTION' => 'SMS senden (via LINK Mobility)', @@ -53,6 +53,6 @@ $aLang = array( 'D3_ORDERMANAGER_JOBDESC_SENDLMMESSAGE_EMPTYMESSAGE' => 'SMS wurde wegen leerer Nachricht nicht gesendet', 'D3_ORDERMANAGER_JOBDESC_SENDLMMESSAGE_NORECIPIENT' => 'SMS wurde wegen fehlender Empfänger nicht gesendet', 'D3_ORDERMANAGER_JOBDESC_SENDLMMESSAGE_RECIPIENTERROR' => 'SMS Empfänger %1$s (%2$s) konnte nicht verwendet werden', -); +]; // @codeCoverageIgnoreEnd diff --git a/src/IntelliSenseHelper.php b/src/IntelliSenseHelper.php index a826637..7f0c185 100644 --- a/src/IntelliSenseHelper.php +++ b/src/IntelliSenseHelper.php @@ -17,5 +17,7 @@ namespace D3\Linkmobility4Ordermanager\Modules\Ordermanager\Application\Model { use D3\Ordermanager\Application\Model\d3ordermanager_conf; - class d3ordermanager_conf_linkmobility_parent extends d3ordermanager_conf {} -} \ No newline at end of file + class d3ordermanager_conf_linkmobility_parent extends d3ordermanager_conf + { + } +} diff --git a/src/Modules/Ordermanager/Application/Model/d3ordermanager_conf_linkmobility.php b/src/Modules/Ordermanager/Application/Model/d3ordermanager_conf_linkmobility.php index 8030035..3ead595 100644 --- a/src/Modules/Ordermanager/Application/Model/d3ordermanager_conf_linkmobility.php +++ b/src/Modules/Ordermanager/Application/Model/d3ordermanager_conf_linkmobility.php @@ -53,4 +53,4 @@ class d3ordermanager_conf_linkmobility extends d3ordermanager_conf_linkmobility_ return $moduleStateService->isActive('d3linkmobility', Registry::getConfig()->getShopId()); } -} \ No newline at end of file +} diff --git a/src/metadata.php b/src/metadata.php index ea1dbe4..9e9fab0 100644 --- a/src/metadata.php +++ b/src/metadata.php @@ -36,13 +36,13 @@ $aModule = [ 'email' => 'support@shopmodule.com', 'url' => 'https://www.oxidmodule.com/', 'extend' => [ - d3ordermanager_conf::class => d3ordermanager_conf_linkmobility::class + d3ordermanager_conf::class => d3ordermanager_conf_linkmobility::class, ], 'controllers' => [], 'templates' => [ - 'd3linkmobility_ordermanager_action.tpl' => 'd3/linkmobility4ordermanager/Application/views/admin/tpl/d3linkmobility_ordermanager_action.tpl' + 'd3linkmobility_ordermanager_action.tpl' => 'd3/linkmobility4ordermanager/Application/views/admin/tpl/d3linkmobility_ordermanager_action.tpl', ], 'events' => [], 'blocks' => [], - 'settings' => [] + 'settings' => [], ];