Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-8019: Replaced LocationService::loadLocationChildren usages with SearchService::findLocations #114

Merged
merged 9 commits into from
Jun 7, 2024
47 changes: 11 additions & 36 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,6 @@ parameters:
count: 1
path: src/bundle/DependencyInjection/ConfigurationMapper.php

-
message: "#^Parameter \\#1 \\$configuration of method Symfony\\\\Component\\\\DependencyInjection\\\\Extension\\\\Extension\\:\\:processConfiguration\\(\\) expects Symfony\\\\Component\\\\Config\\\\Definition\\\\ConfigurationInterface, Symfony\\\\Component\\\\Config\\\\Definition\\\\ConfigurationInterface\\|null given\\.$#"
count: 1
path: src/bundle/DependencyInjection/EzRecommendationClientExtension.php

-
message: "#^Method EzSystems\\\\EzRecommendationClientBundle\\\\EzRecommendationClientBundle\\:\\:build\\(\\) has no return type specified\\.$#"
count: 1
Expand Down Expand Up @@ -1235,6 +1230,11 @@ parameters:
count: 1
path: tests/lib/Event/Subscriber/AbstractCoreEventSubscriberTest.php

-
message: "#^PHPDoc tag @var for property EzSystems\\\\EzRecommendationClient\\\\Tests\\\\Event\\\\Subscriber\\\\AbstractCoreEventSubscriberTest\\:\\:\\$notificationServiceMock contains unresolvable type\\.$#"
count: 1
path: tests/lib/Event/Subscriber/AbstractCoreEventSubscriberTest.php

-
message: "#^Return type of call to method PHPUnit\\\\Framework\\\\TestCase\\:\\:createMock\\(\\) contains unresolvable type\\.$#"
count: 1
Expand Down Expand Up @@ -1320,19 +1320,19 @@ parameters:
count: 1
path: tests/lib/Event/Subscriber/ContentEventSubscriberTest.php

-
message: "#^Parameter \\#1 \\$notificationService of class EzSystems\\\\EzRecommendationClient\\\\Event\\\\Subscriber\\\\ContentEventSubscriber constructor expects EzSystems\\\\EzRecommendationClient\\\\Service\\\\NotificationService, EzSystems\\\\EzRecommendationClient\\\\Service\\\\EventNotificationService\\|PHPUnit\\\\Framework\\\\MockObject\\\\MockObject given\\.$#"
count: 1
path: tests/lib/Event/Subscriber/ContentEventSubscriberTest.php

-
message: "#^Return type of call to method PHPUnit\\\\Framework\\\\TestCase\\:\\:createMock\\(\\) contains unresolvable type\\.$#"
count: 6
path: tests/lib/Event/Subscriber/ContentEventSubscriberTest.php

-
message: "#^Call to an undefined method EzSystems\\\\EzRecommendationClient\\\\Helper\\\\ContentHelper\\|PHPUnit\\\\Framework\\\\MockObject\\\\MockObject\\:\\:expects\\(\\)\\.$#"
count: 4
count: 3
path: tests/lib/Event/Subscriber/LocationEventSubscriberTest.php

-
message: "#^Call to an undefined method EzSystems\\\\EzRecommendationClient\\\\Helper\\\\ContentHelper\\|PHPUnit\\\\Framework\\\\MockObject\\\\MockObject\\:\\:method\\(\\)\\.$#"
count: 3
path: tests/lib/Event/Subscriber/LocationEventSubscriberTest.php

-
Expand Down Expand Up @@ -1385,16 +1385,6 @@ parameters:
count: 1
path: tests/lib/Event/Subscriber/LocationEventSubscriberTest.php

-
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Tests\\\\Event\\\\Subscriber\\\\LocationEventSubscriberTest\\:\\:updateLocationWithChildrenDataProvider\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/lib/Event/Subscriber/LocationEventSubscriberTest.php

-
message: "#^Parameter \\#1 \\$notificationService of class EzSystems\\\\EzRecommendationClient\\\\Event\\\\Subscriber\\\\LocationEventSubscriber constructor expects EzSystems\\\\EzRecommendationClient\\\\Service\\\\NotificationService, EzSystems\\\\EzRecommendationClient\\\\Service\\\\EventNotificationService\\|PHPUnit\\\\Framework\\\\MockObject\\\\MockObject given\\.$#"
count: 1
path: tests/lib/Event/Subscriber/LocationEventSubscriberTest.php

-
message: "#^Parameter \\#1 \\$originalClassName of method PHPUnit\\\\Framework\\\\TestCase\\:\\:createMock\\(\\) expects class\\-string\\<mixed\\>, string given\\.$#"
count: 1
Expand Down Expand Up @@ -1435,21 +1425,11 @@ parameters:
count: 1
path: tests/lib/Event/Subscriber/ObjectStateEventSubscriberTest.php

-
message: "#^Parameter \\#1 \\$notificationService of class EzSystems\\\\EzRecommendationClient\\\\Event\\\\Subscriber\\\\ObjectStateEventSubscriber constructor expects EzSystems\\\\EzRecommendationClient\\\\Service\\\\NotificationService, EzSystems\\\\EzRecommendationClient\\\\Service\\\\EventNotificationService\\|PHPUnit\\\\Framework\\\\MockObject\\\\MockObject given\\.$#"
count: 1
path: tests/lib/Event/Subscriber/ObjectStateEventSubscriberTest.php

-
message: "#^Return type of call to method PHPUnit\\\\Framework\\\\TestCase\\:\\:createMock\\(\\) contains unresolvable type\\.$#"
count: 1
path: tests/lib/Event/Subscriber/ObjectStateEventSubscriberTest.php

-
message: "#^Anonymous function has an unused use \\$contentInfo\\.$#"
count: 2
path: tests/lib/Event/Subscriber/TrashEventSubscriberTest.php

-
message: "#^Method EzSystems\\\\EzRecommendationClient\\\\Tests\\\\Event\\\\Subscriber\\\\TrashEventSubscriberTest\\:\\:getRelationList\\(\\) has no return type specified\\.$#"
count: 1
Expand Down Expand Up @@ -1480,11 +1460,6 @@ parameters:
count: 1
path: tests/lib/Event/Subscriber/TrashEventSubscriberTest.php

-
message: "#^Parameter \\#1 \\$notificationService of class EzSystems\\\\EzRecommendationClient\\\\Event\\\\Subscriber\\\\TrashEventSubscriber constructor expects EzSystems\\\\EzRecommendationClient\\\\Service\\\\NotificationService, EzSystems\\\\EzRecommendationClient\\\\Service\\\\EventNotificationService\\|PHPUnit\\\\Framework\\\\MockObject\\\\MockObject given\\.$#"
count: 1
path: tests/lib/Event/Subscriber/TrashEventSubscriberTest.php

-
message: "#^Parameter \\#4 \\$locationHelper of class EzSystems\\\\EzRecommendationClient\\\\Event\\\\Subscriber\\\\TrashEventSubscriber constructor expects EzSystems\\\\EzRecommendationClient\\\\Helper\\\\LocationHelper, EzSystems\\\\EzRecommendationClient\\\\Helper\\\\LocationHelper\\|PHPUnit\\\\Framework\\\\MockObject\\\\MockObject given\\.$#"
count: 1
Expand Down
43 changes: 38 additions & 5 deletions src/lib/Event/Subscriber/AbstractRepositoryEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

use eZ\Publish\API\Repository\ContentService as ContentServiceInterface;
use eZ\Publish\API\Repository\LocationService as LocationServiceInterface;
use eZ\Publish\API\Repository\SearchService;
use eZ\Publish\API\Repository\Values\Content\Location;
use eZ\Publish\Core\Query\QueryFactoryInterface;
use EzSystems\EzRecommendationClient\Helper\ContentHelper;
use EzSystems\EzRecommendationClient\Helper\LocationHelper;
use EzSystems\EzRecommendationClient\Service\NotificationService;
Expand All @@ -29,33 +31,64 @@ abstract class AbstractRepositoryEventSubscriber extends AbstractCoreEventSubscr
/** @var \EzSystems\EzRecommendationClient\Helper\ContentHelper */
protected $contentHelper;

/** @var \eZ\Publish\Core\Query\QueryFactoryInterface */
private $queryFactory;

/** @var \eZ\Publish\API\Repository\SearchService */
private $searchService;

public function __construct(
NotificationService $notificationService,
ContentServiceInterface $contentService,
LocationServiceInterface $locationService,
LocationHelper $locationHelper,
ContentHelper $contentHelper
ContentHelper $contentHelper,
QueryFactoryInterface $queryFactory,
SearchService $searchService
) {
parent::__construct($notificationService);
$this->contentService = $contentService;
$this->locationService = $locationService;
$this->locationHelper = $locationHelper;
$this->contentHelper = $contentHelper;
$this->queryFactory = $queryFactory;
$this->searchService = $searchService;
}

/**
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
*/
protected function updateLocationSubtree(Location $location, string $method, string $action): void
{
$subtree = $this->locationService->loadLocationChildren($location);
$locationChildren = $this->loadLocationChildren($location);

/** @var \eZ\Publish\API\Repository\Values\Content\Location $content */
foreach ($subtree as $content) {
foreach ($locationChildren as $locationChild) {
$this->notificationService->sendNotification(
$method, $action, $content->getContentInfo()
$method, $action, $locationChild->getContentInfo()
);
}
}

/**
* @return array<\eZ\Publish\API\Repository\Values\Content\Location>
*
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
*/
protected function loadLocationChildren(Location $location): array
{
/** @var \eZ\Publish\API\Repository\Values\Content\LocationQuery $locationChildrenQuery */
$locationChildrenQuery = $this->queryFactory->create('Children', ['location' => $location]);
$searchResult = $this->searchService->findLocations($locationChildrenQuery);

$locations = [];
foreach ($searchResult->searchHits as $searchHit) {
/** @var \eZ\Publish\API\Repository\Values\Content\Location $locationChild */
$locationChild = $searchHit->valueObject;
$locations[] = $locationChild;
}

return $locations;
}
}
12 changes: 4 additions & 8 deletions src/lib/Event/Subscriber/LocationEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,13 @@ public function onUpdateLocation(UpdateLocationEvent $event): void

/**
* @throws \eZ\Publish\API\Repository\Exceptions\BadStateException
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
*/
private function hideLocation(Location $location, bool $isChild = false): void
{
$children = $this->locationService->loadLocationChildren($location)->locations;

/** @var \eZ\Publish\API\Repository\Values\Content\Location $child */
foreach ($children as $child) {
foreach ($this->loadLocationChildren($location) as $child) {
$this->hideLocation($child, true);
}

Expand All @@ -158,15 +156,13 @@ private function hideLocation(Location $location, bool $isChild = false): void
}

/**
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
*/
private function updateLocationWithChildren(Location $location, string $method, string $action): void
{
$children = $this->locationService->loadLocationChildren($location)->locations;

/** @var \eZ\Publish\API\Repository\Values\Content\Location $child */
foreach ($children as $child) {
foreach ($this->loadLocationChildren($location) as $child) {
$this->updateLocationWithChildren($child, $method, $action);
}

Expand Down
14 changes: 13 additions & 1 deletion src/lib/Event/Subscriber/TrashEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
use eZ\Publish\API\Repository\Events\Trash\TrashEvent;
use eZ\Publish\API\Repository\LocationService as LocationServiceInterface;
use eZ\Publish\API\Repository\Repository;
use eZ\Publish\API\Repository\SearchService;
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
use eZ\Publish\Core\Query\QueryFactoryInterface;
use EzSystems\EzRecommendationClient\Helper\ContentHelper;
use EzSystems\EzRecommendationClient\Helper\LocationHelper;
use EzSystems\EzRecommendationClient\Service\NotificationService;
Expand All @@ -31,9 +33,19 @@ public function __construct(
LocationServiceInterface $locationService,
LocationHelper $locationHelper,
ContentHelper $contentHelper,
QueryFactoryInterface $queryFactory,
SearchService $searchService,
Repository $repository
) {
parent::__construct($notificationService, $contentService, $locationService, $locationHelper, $contentHelper);
parent::__construct(
$notificationService,
$contentService,
$locationService,
$locationHelper,
$contentHelper,
$queryFactory,
$searchService
);

$this->repository = $repository;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@

abstract class AbstractCoreEventSubscriberTest extends TestCase
{
/** @var \PHPUnit\Framework\MockObject\MockObject|\EzSystems\EzRecommendationClient\Service\EventNotificationService */
protected $notificationServiceMock;

/** @var \eZ\Publish\API\Repository\Values\Content\ContentInfo */
protected $contentInfo;

Expand All @@ -30,9 +27,11 @@ abstract class AbstractCoreEventSubscriberTest extends TestCase
/** @var \eZ\Publish\Core\Repository\Values\Content\Content */
protected $content;

/** @var \PHPUnit\Framework\MockObject\MockObject&\EzSystems\EzRecommendationClient\Service\EventNotificationService */
protected $notificationServiceMock;

public function setUp(): void
{
$this->notificationServiceMock = $this->createMock(EventNotificationService::class);
$this->contentInfo = new ContentInfo([
'id' => 1,
'contentTypeId' => 2,
Expand All @@ -47,6 +46,7 @@ public function setUp(): void
'contentInfo' => $this->contentInfo,
]),
]);
$this->notificationServiceMock = $this->createMock(EventNotificationService::class);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

use eZ\Publish\API\Repository\ContentService;
use eZ\Publish\API\Repository\LocationService;
use eZ\Publish\API\Repository\SearchService;
use eZ\Publish\Core\Query\QueryFactoryInterface;
use EzSystems\EzRecommendationClient\Helper\ContentHelper;
use EzSystems\EzRecommendationClient\Helper\LocationHelper;

Expand All @@ -21,12 +23,18 @@
/** @var \PHPUnit\Framework\MockObject\MockObject|\eZ\Publish\API\Repository\LocationService */
protected $locationServiceMock;

/** @var \PHPUnit\Framework\MockObject\MockObject|\EzSystems\EzRecommendationClient\Helper\LocationHelper */
/** @var \PHPUnit\Framework\MockObject\MockObject&\EzSystems\EzRecommendationClient\Helper\LocationHelper */
protected $locationHelperMock;

Check failure on line 27 in tests/lib/Event/Subscriber/AbstractRepositoryEventSubscriberTest.php

View workflow job for this annotation

GitHub Actions / Tests (7.4)

PHPDoc tag @var for property EzSystems\EzRecommendationClient\Tests\Event\Subscriber\AbstractRepositoryEventSubscriberTest::$locationHelperMock contains unresolvable type.

Check failure on line 27 in tests/lib/Event/Subscriber/AbstractRepositoryEventSubscriberTest.php

View workflow job for this annotation

GitHub Actions / Tests (7.3)

PHPDoc tag @var for property EzSystems\EzRecommendationClient\Tests\Event\Subscriber\AbstractRepositoryEventSubscriberTest::$locationHelperMock contains unresolvable type.

Check failure on line 27 in tests/lib/Event/Subscriber/AbstractRepositoryEventSubscriberTest.php

View workflow job for this annotation

GitHub Actions / Tests (8.1)

PHPDoc tag @var for property EzSystems\EzRecommendationClient\Tests\Event\Subscriber\AbstractRepositoryEventSubscriberTest::$locationHelperMock contains unresolvable type.

/** @var \PHPUnit\Framework\MockObject\MockObject|\EzSystems\EzRecommendationClient\Helper\ContentHelper */
/** @var \PHPUnit\Framework\MockObject\MockObject&\EzSystems\EzRecommendationClient\Helper\ContentHelper */
protected $contentHelperMock;

Check failure on line 30 in tests/lib/Event/Subscriber/AbstractRepositoryEventSubscriberTest.php

View workflow job for this annotation

GitHub Actions / Tests (7.4)

PHPDoc tag @var for property EzSystems\EzRecommendationClient\Tests\Event\Subscriber\AbstractRepositoryEventSubscriberTest::$contentHelperMock contains unresolvable type.

Check failure on line 30 in tests/lib/Event/Subscriber/AbstractRepositoryEventSubscriberTest.php

View workflow job for this annotation

GitHub Actions / Tests (7.3)

PHPDoc tag @var for property EzSystems\EzRecommendationClient\Tests\Event\Subscriber\AbstractRepositoryEventSubscriberTest::$contentHelperMock contains unresolvable type.

Check failure on line 30 in tests/lib/Event/Subscriber/AbstractRepositoryEventSubscriberTest.php

View workflow job for this annotation

GitHub Actions / Tests (8.1)

PHPDoc tag @var for property EzSystems\EzRecommendationClient\Tests\Event\Subscriber\AbstractRepositoryEventSubscriberTest::$contentHelperMock contains unresolvable type.

/** @var \PHPUnit\Framework\MockObject\MockObject&\eZ\Publish\Core\Query\QueryFactoryInterface */
protected $queryFactoryMock;

/** @var \PHPUnit\Framework\MockObject\MockObject&\eZ\Publish\API\Repository\SearchService */
protected $searchServiceMock;

public function setUp(): void
{
parent::setUp();
Expand All @@ -35,5 +43,7 @@
$this->locationServiceMock = $this->createMock(LocationService::class);
$this->locationHelperMock = $this->createMock(LocationHelper::class);
$this->contentHelperMock = $this->createMock(ContentHelper::class);
$this->queryFactoryMock = $this->createMock(QueryFactoryInterface::class);
$this->searchServiceMock = $this->createMock(SearchService::class);
}
}
Loading
Loading