Skip to content

Commit

Permalink
Fix phpstan issues
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz committed Oct 16, 2024
1 parent 69627af commit e2d7c0e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<AccountInterface, AccountApi, AccountAddressEntity> $accountManager
*/
public function __construct(
private ContactManagerInterface $accountManager,
) {
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ContactInterface, ContactApi, ContactAddress> $contactManager
*/
public function __construct(
private ContactManagerInterface $contactManager,
) {
Expand All @@ -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;
Expand Down

0 comments on commit e2d7c0e

Please sign in to comment.