From d0e539e488dd75626805bcf66e8f48070ffc06bc Mon Sep 17 00:00:00 2001 From: Ingolf Steinhardt Date: Mon, 19 Aug 2024 15:36:32 +0200 Subject: [PATCH] Fix PHPCQ --- .../CompilerPass/PrepareTranslatorPass.php | 7 ++++--- .../Breadcrumb/BreadcrumbStoreFactory.php | 10 +++++----- .../DcGeneral/Breadcrumb/ConnectionTrait.php | 7 +++---- .../Table/DcaSettingCondition/ValueListener.php | 16 +++++++++------- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/CoreBundle/DependencyInjection/CompilerPass/PrepareTranslatorPass.php b/src/CoreBundle/DependencyInjection/CompilerPass/PrepareTranslatorPass.php index 6a04a3dd5..09abf4a6d 100644 --- a/src/CoreBundle/DependencyInjection/CompilerPass/PrepareTranslatorPass.php +++ b/src/CoreBundle/DependencyInjection/CompilerPass/PrepareTranslatorPass.php @@ -64,9 +64,10 @@ public function process(ContainerBuilder $container): void // We need to keep us "first" to allow others to override the values from our loader. if ($container->hasDefinition('translator.default')) { $translator = $container->getDefinition('translator.default'); - $loaders = $translator->getArgument(3); - $keys = array_keys($loaders); - $last = array_pop($keys); + /** @var array> $loaders */ + $loaders = $translator->getArgument(3); + $keys = array_keys($loaders); + $last = array_pop($keys); if ($last === MetaModelTranslationLoader::class) { $value = array_pop($loaders); $loaders = [MetaModelTranslationLoader::class => $value] + $loaders; diff --git a/src/CoreBundle/EventListener/DcGeneral/Breadcrumb/BreadcrumbStoreFactory.php b/src/CoreBundle/EventListener/DcGeneral/Breadcrumb/BreadcrumbStoreFactory.php index 86cc1de55..4a6f76b61 100644 --- a/src/CoreBundle/EventListener/DcGeneral/Breadcrumb/BreadcrumbStoreFactory.php +++ b/src/CoreBundle/EventListener/DcGeneral/Breadcrumb/BreadcrumbStoreFactory.php @@ -3,7 +3,7 @@ /** * This file is part of MetaModels/core. * - * (c) 2012-2022 The MetaModels team. + * (c) 2012-2024 The MetaModels team. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,7 +14,7 @@ * @author Christian Schiffler * @author Sven Baumann * @author Ingolf Steinhardt - * @copyright 2012-2022 The MetaModels team. + * @copyright 2012-2024 The MetaModels team. * @license https://github.com/MetaModels/core/blob/master/LICENSE LGPL-3.0-or-later * @filesource */ @@ -35,21 +35,21 @@ class BreadcrumbStoreFactory * * @var IconBuilder */ - private $iconBuilder; + private IconBuilder $iconBuilder; /** * The translator. * * @var TranslatorInterface */ - private $translator; + private TranslatorInterface $translator; /** * The request stack. * * @var RequestStack */ - private $requestStack; + private RequestStack $requestStack; /** * Create a new instance. diff --git a/src/CoreBundle/EventListener/DcGeneral/Breadcrumb/ConnectionTrait.php b/src/CoreBundle/EventListener/DcGeneral/Breadcrumb/ConnectionTrait.php index 88db17130..aca32f456 100644 --- a/src/CoreBundle/EventListener/DcGeneral/Breadcrumb/ConnectionTrait.php +++ b/src/CoreBundle/EventListener/DcGeneral/Breadcrumb/ConnectionTrait.php @@ -3,7 +3,7 @@ /** * This file is part of MetaModels/core. * - * (c) 2012-2022 The MetaModels team. + * (c) 2012-2024 The MetaModels team. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,7 +14,7 @@ * @author Christian Schiffler * @author Sven Baumann * @author Ingolf Steinhardt - * @copyright 2012-2022 The MetaModels team. + * @copyright 2012-2024 The MetaModels team. * @license https://github.com/MetaModels/core/blob/master/LICENSE LGPL-3.0-or-later * @filesource */ @@ -33,7 +33,7 @@ trait ConnectionTrait * * @var Connection */ - private $connection; + private Connection $connection; /** * Set the database connection. @@ -51,7 +51,6 @@ public function setConnection(Connection $connection) * Retrieve the row. * * @param string $rowId The id. - * * @param string $table The table to fetch from. * * @return object diff --git a/src/CoreBundle/EventListener/DcGeneral/Table/DcaSettingCondition/ValueListener.php b/src/CoreBundle/EventListener/DcGeneral/Table/DcaSettingCondition/ValueListener.php index 1776bca73..6121c3b51 100644 --- a/src/CoreBundle/EventListener/DcGeneral/Table/DcaSettingCondition/ValueListener.php +++ b/src/CoreBundle/EventListener/DcGeneral/Table/DcaSettingCondition/ValueListener.php @@ -241,8 +241,10 @@ private function getOptionsViaDcGeneral($metaModel, $environment, $attribute, $m assert($dataProvider instanceof DataProviderInterface); if ($dataProvider instanceof MultiLanguageDataProviderInterface) { // FIXME: check if language supported. - $locale = System::getContainer()->get('request_stack')->getCurrentRequest()?->getLocale(); - $languages = $dataProvider->getLanguages($model->getId()); + $locale = System::getContainer()->get('request_stack')?->getCurrentRequest()?->getLocale(); + if (null === ($languages = $dataProvider->getLanguages($model->getId()))) { + return []; + } $found = false; foreach ($languages as $language) { if ($language->getLocale() === $locale) { @@ -251,11 +253,11 @@ private function getOptionsViaDcGeneral($metaModel, $environment, $attribute, $m break; } } - if (!$found) { - $dataProvider->setCurrentLanguage($dataProvider->getFallbackLanguage($model->getId())); + if (!$found && null !== ($language = $dataProvider->getFallbackLanguage($model->getId()))) { + $dataProvider->setCurrentLanguage($language->getLocale()); } } - $optEv = new GetPropertyOptionsEvent($subEnv, $dataProvider->getEmptyModel()); + $optEv = new GetPropertyOptionsEvent($subEnv, $dataProvider->getEmptyModel()); $optEv->setPropertyName($attribute->getColName()); $dispatcher = $subEnv->getEventDispatcher(); assert($dispatcher instanceof EventDispatcherInterface); @@ -272,9 +274,9 @@ private function getOptionsViaDcGeneral($metaModel, $environment, $attribute, $m * @param IAttribute $attribute The attribute. * @param string $language The language to used for the convertion. * - * @return string|null The value to be saved. + * @return string The value to be saved. */ - private function aliasToId(string $alias, IAttribute $attribute, string $language): ?string + private function aliasToId(string $alias, IAttribute $attribute, string $language): string { if ($attribute instanceof IAliasConverter) { $idForAlias = $attribute->getIdForAlias(substr($alias, 6), $language);