From e533b349fe3b4900cc80809a35ad89ef6b4f5ef3 Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Tue, 19 Nov 2024 10:50:33 +0100 Subject: [PATCH] improve code style by CS Fixer # Conflicts: # composer.json # migration/data/Version20241023154223.php # migration/data/Version20241028172608.php --- .noencode | 2 +- .php-cs-fixer.php | 34 ++++++++++ .../Admin/ManufacturerInfoLongdesc.php | 63 +++++++++++-------- Application/Model/Constants.php | 20 ++++-- .../de/d3manufacturerinformation_lang.php | 21 +++++-- .../en/d3manufacturerinformation_lang.php | 21 +++++-- IntelliSenseHelper.php | 26 ++++---- .../Model/D3ManufacturerLongDesc.php | 28 ++++++--- .../Model/ManufacturerInfoList.php | 20 ++++-- composer.json | 10 +-- metadata.php | 18 +++--- 11 files changed, 188 insertions(+), 75 deletions(-) create mode 100644 .php-cs-fixer.php diff --git a/.noencode b/.noencode index a64141a..f6cc7ca 100644 --- a/.noencode +++ b/.noencode @@ -1 +1 @@ -copyAsIsFiles=metadata.php, IntelliSenseHelper.php, migration, Application/views \ No newline at end of file +copyAsIsFiles=metadata.php, .php-cs-fixer.php, IntelliSenseHelper.php, migration, Application/views \ No newline at end of file diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php new file mode 100644 index 0000000..c5b302c --- /dev/null +++ b/.php-cs-fixer.php @@ -0,0 +1,34 @@ +in(__DIR__) +; + +$header = << +@link https://www.oxidmodule.com +EOF; + +$config = new PhpCsFixer\Config(); +return $config->setRules([ + '@PHP80Migration' => true, + '@PSR12' => true, + 'header_comment' => [ + 'comment_type' => 'PHPDoc', + 'header' => $header, + 'location' => 'after_open', + 'separate' => 'both', + ], + 'php_unit_test_class_requires_covers' => true, + 'doctrine_annotation_indentation' => true, + ]) + ->setFinder($finder) +; \ No newline at end of file diff --git a/Application/Controller/Admin/ManufacturerInfoLongdesc.php b/Application/Controller/Admin/ManufacturerInfoLongdesc.php index ea9cf4f..b5f8687 100644 --- a/Application/Controller/Admin/ManufacturerInfoLongdesc.php +++ b/Application/Controller/Admin/ManufacturerInfoLongdesc.php @@ -1,5 +1,18 @@ + * @link https://www.oxidmodule.com + */ + declare(strict_types=1); namespace D3\ManufacturerInformation\Application\Controller\Admin; @@ -18,27 +31,27 @@ class ManufacturerInfoLongdesc extends AdminDetailsController public function render() { parent::render(); - + $this->_aViewData['edit'] = $oManufacturer = oxNew(\OxidEsales\Eshop\Application\Model\Manufacturer::class); - + $sOXID = $this->_aViewData["oxid"] = $this->getEditObjectId(); if (isset($sOXID) && $sOXID != "-1") { // load object $d3manufacturerlang = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("catlang"); - + if (!isset($d3manufacturerlang)) { $d3manufacturerlang = $this->_iEditLang; } - + $this->_aViewData["catlang"] = $d3manufacturerlang; - + $oManufacturer->loadInLang($d3manufacturerlang, $sOXID); - + //Disable editing for derived items if ($oManufacturer->isDerived()) { $this->_aViewData['readonly'] = true; } - + foreach (\OxidEsales\Eshop\Core\Registry::getLang()->getLanguageNames() as $id => $language) { $oLang = new \stdClass(); $oLang->sLangDesc = $language; @@ -46,12 +59,12 @@ class ManufacturerInfoLongdesc extends AdminDetailsController $this->_aViewData["otherlang"][$id] = clone $oLang; } } - + $this->_aViewData["editor"] = $this->generateTextEditor("100%", 280, $oManufacturer, "oxmanufacturers__d3description", "list.tpl.css"); - + return "d3manufacturerlongdesc.tpl"; } - + /** * @return void * @throws \Exception @@ -59,32 +72,32 @@ class ManufacturerInfoLongdesc extends AdminDetailsController public function save() { parent::save(); - + $iManufacturerLang = intval(\OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("catlang")); $sOXID = $this->getEditObjectId(); $this->setEditObjectId($sOXID); - + if ($sOXID == "-1") { return; } - + /** @var Manufacturer|D3ManufacturerLongDesc $oManufacturer */ $oManufacturer = oxNew(Manufacturer::class); $oManufacturer->loadInLang($iManufacturerLang, $sOXID); - + if (!$oManufacturer->load($sOXID)) { return; } - + $aParams = Registry::getRequest()->getRequestEscapedParameter("editval"); $oManufacturer->assign($aParams); - + if (false === is_null($this->d3GetLongdescParamValue())) { $oManufacturer->d3SetLongdesc($this->d3GetLongdescParamValue()); $oManufacturer->save(); } } - + /** * Returns string which must be edited by editor * @@ -97,22 +110,22 @@ class ManufacturerInfoLongdesc extends AdminDetailsController protected function _getEditValue($oManufacturer, $sField) // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore { $sEditObjectValue = ''; - + if ($oManufacturer and $oManufacturer->getId()) { $sEditObjectValue = $this->_processEditValue($oManufacturer->getFieldData(Constants::D3_OXMANUFACTURERS_LONGDESC_FIELDNAME)); } - + return $sEditObjectValue; } - + /** * @return string */ - public function d3GetLongdescParamValue() :string + public function d3GetLongdescParamValue(): string { return (string) $aParams = Registry::getRequest()->getRequestEscapedParameter("editval")['oxmanufacturers__d3description']; } - + /** * inhaltliche Uebernahme analog Article_Main * wird genutzt zum Abspeichern der Artikel-Langbeschreibung @@ -125,7 +138,7 @@ class ManufacturerInfoLongdesc extends AdminDetailsController { $aSearch = ['&nbsp;', '&', '"', '&lang=', '

 

', '

 

']; $aReplace = [' ', '&', '"', '&lang=', '', '']; - + return str_replace($aSearch, $aReplace, $sValue); } -} \ No newline at end of file +} diff --git a/Application/Model/Constants.php b/Application/Model/Constants.php index 32162ba..1ab39cd 100644 --- a/Application/Model/Constants.php +++ b/Application/Model/Constants.php @@ -1,14 +1,26 @@ + * @link https://www.oxidmodule.com + */ + declare(strict_types=1); namespace D3\ManufacturerInformation\Application\Model; - class Constants { public const OXID_MODULE_ID = 'd3manufacturerinformation'; - + // Tables and Database public const D3_OXMANUFACTURERS_LONGDESC_FIELDNAME = 'd3description'; -} \ No newline at end of file +} diff --git a/Application/views/admin/de/d3manufacturerinformation_lang.php b/Application/views/admin/de/d3manufacturerinformation_lang.php index 1ee2580..e4e5a6b 100644 --- a/Application/views/admin/de/d3manufacturerinformation_lang.php +++ b/Application/views/admin/de/d3manufacturerinformation_lang.php @@ -1,13 +1,26 @@ + * @link https://www.oxidmodule.com + */ + $sLangName = "Deutsch"; // ------------------------------- // RESOURCE IDENTITFIER = STRING // ------------------------------- -$aLang = array( +$aLang = [ 'charset' => 'UTF-8', - + 'mxd3manufacturerinfolongdesc' => 'Langtext', 'SHOP_MODULE_GROUP_d3manufacturerinformation_main' => 'Einstellungen', - 'SHOP_MODULE_d3manufacturerinformation_showManufacturertextOnDetailsPage' => 'vorhandene Herstellertexte auf Artikeldetails als Tab anzeigen' -); \ No newline at end of file + 'SHOP_MODULE_d3manufacturerinformation_showManufacturertextOnDetailsPage' => 'vorhandene Herstellertexte auf Artikeldetails als Tab anzeigen', +]; diff --git a/Application/views/admin/en/d3manufacturerinformation_lang.php b/Application/views/admin/en/d3manufacturerinformation_lang.php index e15933f..834195b 100644 --- a/Application/views/admin/en/d3manufacturerinformation_lang.php +++ b/Application/views/admin/en/d3manufacturerinformation_lang.php @@ -1,13 +1,26 @@ + * @link https://www.oxidmodule.com + */ + $sLangName = "Deutsch"; // ------------------------------- // RESOURCE IDENTITFIER = STRING // ------------------------------- -$aLang = array( +$aLang = [ 'charset' => 'UTF-8', - + 'mxd3manufacturerinfolongdesc' => 'Text', 'SHOP_MODULE_GROUP_d3manufacturerinformation_main' => 'Settings', - 'SHOP_MODULE_d3manufacturerinformation_showManufacturertextOnDetailsPage' => 'display existing manufacturer texts on item details as a tab' -); \ No newline at end of file + 'SHOP_MODULE_d3manufacturerinformation_showManufacturertextOnDetailsPage' => 'display existing manufacturer texts on item details as a tab', +]; diff --git a/IntelliSenseHelper.php b/IntelliSenseHelper.php index 66574fa..254eae4 100644 --- a/IntelliSenseHelper.php +++ b/IntelliSenseHelper.php @@ -1,21 +1,23 @@ - * @link http://www.oxidmodule.com + * @author D3 Data Development - Max Buhe, Daniel Seifert + * @link https://www.oxidmodule.com */ namespace D3\ManufacturerInformation\Modules\Application\Model{ - + use OxidEsales\Eshop\Application\Model\Manufacturer; - - class D3ManufacturerLongDesc_parent extends Manufacturer {} -} \ No newline at end of file + + class D3ManufacturerLongDesc_parent extends Manufacturer + { + } +} diff --git a/Modules/Application/Model/D3ManufacturerLongDesc.php b/Modules/Application/Model/D3ManufacturerLongDesc.php index 27056e1..0327775 100644 --- a/Modules/Application/Model/D3ManufacturerLongDesc.php +++ b/Modules/Application/Model/D3ManufacturerLongDesc.php @@ -1,10 +1,22 @@ + * @link https://www.oxidmodule.com + */ + declare(strict_types=1); namespace D3\ManufacturerInformation\Modules\Application\Model; - use D3\ManufacturerInformation\Application\Model\Constants; use OxidEsales\Eshop\Application\Model\Manufacturer; use OxidEsales\Eshop\Core\Field; @@ -16,20 +28,20 @@ class D3ManufacturerLongDesc extends D3ManufacturerLongDesc_parent * @param string $sValue * @return void */ - public function d3SetLongdesc(string $sValue) :bool + public function d3SetLongdesc(string $sValue): bool { - if ($this->getId() and $this->isLoaded()){ + if ($this->getId() and $this->isLoaded()) { try { $this->assign([Constants::D3_OXMANUFACTURERS_LONGDESC_FIELDNAME => $sValue]); $this->save(); - }catch (\Exception $exception){ + } catch (\Exception $exception) { Registry::getLogger()->error($exception->getMessage()); } } - + return true; } - + /** * @return Field */ @@ -38,4 +50,4 @@ class D3ManufacturerLongDesc extends D3ManufacturerLongDesc_parent $longName = $this->getCoreTableName().'__'.strtolower(Constants::D3_OXMANUFACTURERS_LONGDESC_FIELDNAME); return $this->$longName; } -} \ No newline at end of file +} diff --git a/Modules/Application/Model/ManufacturerInfoList.php b/Modules/Application/Model/ManufacturerInfoList.php index 1de07c1..35ae19d 100644 --- a/Modules/Application/Model/ManufacturerInfoList.php +++ b/Modules/Application/Model/ManufacturerInfoList.php @@ -1,10 +1,22 @@ + * @link https://www.oxidmodule.com + */ + declare(strict_types=1); namespace D3\ManufacturerInformation\Modules\Application\Model; - use D3\ManufacturerInformation\Application\Model\Constants; use OxidEsales\Eshop\Application\Model\Manufacturer; use OxidEsales\Eshop\Application\Model\ManufacturerList; @@ -19,7 +31,7 @@ class ManufacturerInfoList extends ManufacturerInfoList_parent protected function _addCategoryFields($oManufacturer) { parent::_addCategoryFields($oManufacturer); - + $oManufacturer->oxcategories__oxlongdesc = new Field($oManufacturer->getFieldData(Constants::D3_OXMANUFACTURERS_LONGDESC_FIELDNAME), Field::T_RAW); } -} \ No newline at end of file +} diff --git a/composer.json b/composer.json index c8578ef..46ead9f 100644 --- a/composer.json +++ b/composer.json @@ -27,11 +27,7 @@ "php": ">=7.0", "oxid-esales/oxideshop-ce": "v6.0 - v6.5.6" }, - "require-dev": { - "phpunit/phpunit" : "^9.5", - "friendsofphp/php-cs-fixer": "^3.9", - "phpstan/phpstan": "^1.8" - }, + "require-dev": {}, "extra": { "oxideshop": { "blacklist-filter": [ @@ -47,5 +43,9 @@ "psr-4": { "D3\\ManufacturerInformation\\": "../../../source/modules/d3/manufacturerinformation" } + }, + "scripts": { + "php-cs-fixer_audit": "./vendor/bin/php-cs-fixer list-files --config=./vendor/d3/manufacturerinformation/.php-cs-fixer.php", + "php-cs-fixer_fix": "./vendor/bin/php-cs-fixer fix --config=./vendor/d3/manufacturerinformation/.php-cs-fixer.php" } } diff --git a/metadata.php b/metadata.php index 1784b21..5b13b9a 100644 --- a/metadata.php +++ b/metadata.php @@ -1,18 +1,20 @@ + * @author D3 Data Development - Max Buhe, Daniel Seifert * @link https://www.oxidmodule.com */ declare(strict_types=1); - + use D3\ManufacturerInformation\Application\Controller\Admin\ManufacturerInfoLongdesc; use D3\ManufacturerInformation\Application\Model\Constants; use D3\ManufacturerInformation\Events\Events; @@ -42,11 +44,11 @@ $aModule = [ 'email' => 'support@shopmodule.com', 'url' => 'https://www.oxidmodule.com/', 'controllers' => [ - "d3manufacturerinfolongdesc" => ManufacturerInfoLongdesc::class + "d3manufacturerinfolongdesc" => ManufacturerInfoLongdesc::class, ], 'extend' => [ OEManufacturer::class => D3ManufacturerLongDesc::class, - OEManufacturerList::class => ManufacturerInfoList::class + OEManufacturerList::class => ManufacturerInfoList::class, ], 'events' => [ 'onActivate' => Events::class.'::activate', @@ -60,7 +62,7 @@ $aModule = [ 'group' => $sModuleId.'_main', 'name' => $sModuleId.'_showManufacturertextOnDetailsPage', 'type' => 'bool', - 'value' => true + 'value' => true, ], ], 'blocks' => [ @@ -74,5 +76,5 @@ $aModule = [ 'block' => 'details_tabs_invite', 'file' => 'Application/views/blocks/page/details/inc/details_tabs_invite.html.tpl', ], - ] + ], ];