From e2d7c0edf25743e99d875c8fa4bd8ae9479802bc Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Wed, 16 Oct 2024 13:10:12 +0200 Subject: [PATCH] Fix phpstan issues --- .../Resolver/CategorySelectionPropertyResolver.php | 1 + .../ContactAccountSelectionPropertyResolver.php | 6 +++++- .../Content/ResourceLoader/AccountResourceLoader.php | 10 ++++++++-- .../Content/ResourceLoader/ContactResourceLoader.php | 10 ++++++++-- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/Sulu/Bundle/CategoryBundle/Infrastructure/Sulu/Content/PropertyResolver/Resolver/CategorySelectionPropertyResolver.php b/src/Sulu/Bundle/CategoryBundle/Infrastructure/Sulu/Content/PropertyResolver/Resolver/CategorySelectionPropertyResolver.php index 210b3e47470..6f29cb0762e 100644 --- a/src/Sulu/Bundle/CategoryBundle/Infrastructure/Sulu/Content/PropertyResolver/Resolver/CategorySelectionPropertyResolver.php +++ b/src/Sulu/Bundle/CategoryBundle/Infrastructure/Sulu/Content/PropertyResolver/Resolver/CategorySelectionPropertyResolver.php @@ -13,6 +13,7 @@ namespace Sulu\Bundle\CategoryBundle\Infrastructure\Content\PropertyResolver\Resolver; +use Sulu\Bundle\CategoryBundle\Infrastructure\Content\ResourceLoader\CategoryResourceLoader; use Sulu\Bundle\ContentBundle\Content\Application\ContentResolver\Value\ContentView; use Sulu\Bundle\ContentBundle\Content\Application\PropertyResolver\PropertyResolverInterface; diff --git a/src/Sulu/Bundle/ContactBundle/Infrastructure/Sulu/Content/PropertyResolver/ContactAccountSelectionPropertyResolver.php b/src/Sulu/Bundle/ContactBundle/Infrastructure/Sulu/Content/PropertyResolver/ContactAccountSelectionPropertyResolver.php index c80391c6767..637a0dc7f53 100644 --- a/src/Sulu/Bundle/ContactBundle/Infrastructure/Sulu/Content/PropertyResolver/ContactAccountSelectionPropertyResolver.php +++ b/src/Sulu/Bundle/ContactBundle/Infrastructure/Sulu/Content/PropertyResolver/ContactAccountSelectionPropertyResolver.php @@ -42,7 +42,11 @@ public function resolve(mixed $data, string $locale, array $params = []): Conten foreach ($data as $id) { $key = \substr($id, 0, 1); $id = \substr($id, 1); - $id = \is_numeric($id) ? \intval($id) : null; // ignore invalid ids, invalid value can happen when template or block type was changed + $id = \is_numeric($id) ? \intval($id) : null; + + if (null === $id) { // ignore invalid ids, invalid value can happen when template or block type was changed + continue; + } // this is a very edge case normally the `ResolvableResource` class should not be used by property resolvers // but in this case we need to use it to load resources depending on the key correctly diff --git a/src/Sulu/Bundle/ContactBundle/Infrastructure/Sulu/Content/ResourceLoader/AccountResourceLoader.php b/src/Sulu/Bundle/ContactBundle/Infrastructure/Sulu/Content/ResourceLoader/AccountResourceLoader.php index d267a1e4703..a8e1c39e883 100644 --- a/src/Sulu/Bundle/ContactBundle/Infrastructure/Sulu/Content/ResourceLoader/AccountResourceLoader.php +++ b/src/Sulu/Bundle/ContactBundle/Infrastructure/Sulu/Content/ResourceLoader/AccountResourceLoader.php @@ -13,13 +13,19 @@ namespace Sulu\Bundle\ContactBundle\Infrastructure\Sulu\Content\ResourceLoader; +use Sulu\Bundle\ContactBundle\Api\Account as AccountApi; use Sulu\Bundle\ContactBundle\Contact\ContactManagerInterface; +use Sulu\Bundle\ContactBundle\Entity\AccountAddress as AccountAddressEntity; +use Sulu\Bundle\ContactBundle\Entity\AccountInterface; use Sulu\Bundle\ContentBundle\Content\Application\ResourceLoader\ResourceLoaderInterface; class AccountResourceLoader implements ResourceLoaderInterface { public const RESOURCE_LOADER_KEY = 'account'; + /** + * @param ContactManagerInterface $accountManager + */ public function __construct( private ContactManagerInterface $accountManager, ) { @@ -30,8 +36,8 @@ public function load(array $ids, ?string $locale, array $params = []): array $result = $this->accountManager->getByIds($ids, (string) $locale); $mappedResult = []; - foreach ($result as $media) { - $mappedResult[$media->getId()] = $media; + foreach ($result as $object) { + $mappedResult[$object->getId()] = $object; } return $mappedResult; diff --git a/src/Sulu/Bundle/ContactBundle/Infrastructure/Sulu/Content/ResourceLoader/ContactResourceLoader.php b/src/Sulu/Bundle/ContactBundle/Infrastructure/Sulu/Content/ResourceLoader/ContactResourceLoader.php index 43d2f7973d5..b92024c6949 100644 --- a/src/Sulu/Bundle/ContactBundle/Infrastructure/Sulu/Content/ResourceLoader/ContactResourceLoader.php +++ b/src/Sulu/Bundle/ContactBundle/Infrastructure/Sulu/Content/ResourceLoader/ContactResourceLoader.php @@ -13,13 +13,19 @@ namespace Sulu\Bundle\ContactBundle\Infrastructure\Sulu\Content\ResourceLoader; +use Sulu\Bundle\ContactBundle\Api\Contact as ContactApi; use Sulu\Bundle\ContactBundle\Contact\ContactManagerInterface; +use Sulu\Bundle\ContactBundle\Entity\ContactAddress; +use Sulu\Bundle\ContactBundle\Entity\ContactInterface; use Sulu\Bundle\ContentBundle\Content\Application\ResourceLoader\ResourceLoaderInterface; class ContactResourceLoader implements ResourceLoaderInterface { public const RESOURCE_LOADER_KEY = 'contact'; + /** + * @param ContactManagerInterface $contactManager + */ public function __construct( private ContactManagerInterface $contactManager, ) { @@ -30,8 +36,8 @@ public function load(array $ids, ?string $locale, array $params = []): array $result = $this->contactManager->getByIds($ids, (string) $locale); $mappedResult = []; - foreach ($result as $media) { - $mappedResult[$media->getId()] = $media; + foreach ($result as $object) { + $mappedResult[$object->getId()] = $object; } return $mappedResult;