From 77bd789f14f2a397001ce8a2cdd18d20aabd6434 Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Fri, 3 Jan 2025 15:11:14 +0100 Subject: [PATCH] improve code --- .../Controller/Admin/ManufacturerInfoLongdesc.php | 12 ++++++------ Modules/Application/Model/D3ManufacturerLongDesc.php | 7 ++++--- Modules/Application/Model/ManufacturerInfoList.php | 11 ++++++++++- migration/data/Version20241023154223.php | 3 ++- migration/data/Version20241028172608.php | 6 +++++- 5 files changed, 27 insertions(+), 12 deletions(-) diff --git a/Application/Controller/Admin/ManufacturerInfoLongdesc.php b/Application/Controller/Admin/ManufacturerInfoLongdesc.php index b25cc39..d140641 100644 --- a/Application/Controller/Admin/ManufacturerInfoLongdesc.php +++ b/Application/Controller/Admin/ManufacturerInfoLongdesc.php @@ -94,8 +94,8 @@ class ManufacturerInfoLongdesc extends AdminDetailsController $aParams = Registry::getRequest()->getRequestEscapedParameter("editval"); $oManufacturer->assign($aParams); - if (false === is_null($this->d3GetLongdescParamValue($oManufacturer))) { - $oManufacturer->d3SetLongdesc($this->d3GetLongdescParamValue($oManufacturer)); + if (false === is_null($this->d3GetLongdescParamValue())) { + $oManufacturer->d3SetLongdesc($this->d3GetLongdescParamValue()); $oManufacturer->save(); } } @@ -103,7 +103,7 @@ class ManufacturerInfoLongdesc extends AdminDetailsController /** * @return string */ - public function d3GetLongdescParamValue(Manufacturer $oManufacturer): string + public function d3GetLongdescParamValue(): string { return (string) Registry::getRequest()->getRequestEscapedParameter("editval")['oxmanufacturers__d3description']; } @@ -114,13 +114,13 @@ class ManufacturerInfoLongdesc extends AdminDetailsController * * @param $sValue * - * @return mixed + * @return string */ - protected function processLongDesc($sValue): mixed + protected function processLongDesc($sValue): string { $aSearch = [' ', '&', '"', '&lang=', '

 

', '

 

']; $aReplace = [' ', '&', '"', '&lang=', '', '']; - return str_replace($aSearch, $aReplace, $sValue); + return (string) str_replace($aSearch, $aReplace, $sValue); } } diff --git a/Modules/Application/Model/D3ManufacturerLongDesc.php b/Modules/Application/Model/D3ManufacturerLongDesc.php index 143197f..78e9c95 100644 --- a/Modules/Application/Model/D3ManufacturerLongDesc.php +++ b/Modules/Application/Model/D3ManufacturerLongDesc.php @@ -18,6 +18,7 @@ declare(strict_types=1); namespace D3\ManufacturerInformation\Modules\Application\Model; use D3\ManufacturerInformation\Application\Model\Constants; +use Exception; use OxidEsales\Eshop\Core\Field; use OxidEsales\Eshop\Core\Registry; @@ -33,7 +34,7 @@ class D3ManufacturerLongDesc extends D3ManufacturerLongDesc_parent try { $this->assign([Constants::D3_OXMANUFACTURERS_LONGDESC_FIELDNAME => $sValue]); $this->save(); - } catch (\Exception $exception) { + } catch ( Exception $exception) { Registry::getLogger()->error($exception->getMessage()); } } @@ -42,9 +43,9 @@ class D3ManufacturerLongDesc extends D3ManufacturerLongDesc_parent } /** - * @return field + * @return Field */ - public function d3GetLongdesc(): field + public function d3GetLongdesc(): Field { $longName = $this->getFieldLongName(Constants::D3_OXMANUFACTURERS_LONGDESC_FIELDNAME); return $this->$longName ?: oxNew(Field::class); diff --git a/Modules/Application/Model/ManufacturerInfoList.php b/Modules/Application/Model/ManufacturerInfoList.php index ae81392..6c295b4 100644 --- a/Modules/Application/Model/ManufacturerInfoList.php +++ b/Modules/Application/Model/ManufacturerInfoList.php @@ -20,18 +20,22 @@ namespace D3\ManufacturerInformation\Modules\Application\Model; use OxidEsales\Eshop\Application\Model\Manufacturer; use OxidEsales\Eshop\Core\Field; use OxidEsales\Eshop\Core\Registry; -use OxidEsales\Eshop\Core\UtilsView; use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory; use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingService; use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingServiceInterface; use OxidEsales\EshopCommunity\Internal\Framework\Templating\TemplateRendererBridgeInterface; use OxidEsales\EshopCommunity\Internal\Framework\Templating\TemplateRendererInterface; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; class ManufacturerInfoList extends ManufacturerInfoList_parent { /** * @param Manufacturer|D3ManufacturerLongDesc $oManufacturer + * * @return void + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ protected function addCategoryFields($oManufacturer): void { @@ -64,6 +68,11 @@ class ManufacturerInfoList extends ManufacturerInfoList_parent } } + /** + * @return TemplateRendererInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ private function getRenderer(): TemplateRendererInterface { return ContainerFactory::getInstance()->getContainer()->get(TemplateRendererBridgeInterface::class)->getTemplateRenderer(); diff --git a/migration/data/Version20241023154223.php b/migration/data/Version20241023154223.php index 67d04b9..1463777 100644 --- a/migration/data/Version20241023154223.php +++ b/migration/data/Version20241023154223.php @@ -18,6 +18,7 @@ declare(strict_types=1); namespace D3\ManufacturerInformation\Migrations; use Doctrine\DBAL\Schema\Schema; +use Doctrine\DBAL\Schema\SchemaException; use Doctrine\DBAL\Types\TextType; use Doctrine\Migrations\AbstractMigration; @@ -45,7 +46,7 @@ final class Version20241023154223 extends AbstractMigration /** * @param Schema $schema * @return void - * @throws \Doctrine\DBAL\Schema\SchemaException + * @throws SchemaException */ public function d3AddLongdescColumnToOxmanufacturers(Schema $schema) { diff --git a/migration/data/Version20241028172608.php b/migration/data/Version20241028172608.php index c756aee..7d2a003 100644 --- a/migration/data/Version20241028172608.php +++ b/migration/data/Version20241028172608.php @@ -17,7 +17,9 @@ declare(strict_types=1); namespace D3\ManufacturerInformation\Migrations; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Schema\Schema; +use Doctrine\DBAL\Schema\SchemaException; use Doctrine\DBAL\Types\TextType; use Doctrine\Migrations\AbstractMigration; @@ -44,8 +46,10 @@ final class Version20241028172608 extends AbstractMigration /** * @param Schema $schema + * * @return void - * @throws \Doctrine\DBAL\Schema\SchemaException + * @throws Exception + * @throws SchemaException */ public function d3AddLongdescMultilangColumnsToOxmanufacturers(Schema $schema) {