Skip to content

Commit

Permalink
Merge pull request #119 from neos/feature/node-search-serviceInterface
Browse files Browse the repository at this point in the history
FEATURE: Rewrite code also for NodeSearchServiceInterface
  • Loading branch information
dlubitz authored Dec 23, 2024
2 parents 1ffb3eb + 41132c5 commit ec55fa4
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/ContentRepository90/Rules/NodeSearchServiceRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ public function refactor(Node $node): ?Node
{
assert($node instanceof Node\Expr\MethodCall);

if (!$this->isObjectType($node->var, new ObjectType(\Neos\Neos\Domain\Service\NodeSearchService::class))) {
if (
!$this->isObjectType($node->var, new ObjectType(\Neos\Neos\Domain\Service\NodeSearchService::class))
&& !$this->isObjectType($node->var, new ObjectType(\Neos\Neos\Domain\Service\NodeSearchServiceInterface::class))
) {
return null;
}
if (!$this->isName($node->name, 'findByProperties')) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace Neos\Rector\Test;

use Neos\ContentRepository\Domain\Model\Node;
use Neos\ContentRepository\Domain\Service\Context;

class SomeClass extends AnotherClass
{
/**
* @var \Neos\Neos\Domain\Service\NodeSearchServiceInterface
*/
private $nodeSearchServiceInterface;

public function startingPointNodeIsGiven(Node $node, Context $context)
{
$term = "term";
$searchNodeTypes = [];
$nodes = $this->nodeSearchServiceInterface->findByProperties($term, $searchNodeTypes, $context, $node);
}

public function startingPointNodeIsNotGiven(Context $context)
{
$term = "term";
$searchNodeTypes = [];
$nodes = $this->nodeSearchServiceInterface->findByProperties($term, $searchNodeTypes, $context);
}
}

-----
<?php

namespace Neos\Rector\Test;

use Neos\ContentRepository\Domain\Model\Node;
use Neos\ContentRepository\Domain\Service\Context;

class SomeClass extends AnotherClass
{
/**
* @var \Neos\Neos\Domain\Service\NodeSearchServiceInterface
*/
private $nodeSearchServiceInterface;

public function startingPointNodeIsGiven(Node $node, Context $context)
{
$term = "term";
$searchNodeTypes = [];
// TODO 9.0 migration: This could be a suitable replacement. Please check if all your requirements are still fulfilled.
$subgraph = $this->contentRepositoryRegistry->subgraphForNode($node);
$nodes = $subgraph->findDescendantNodes($node->aggregateId, \Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindDescendantNodesFilter::create(nodeTypes: \Neos\ContentRepository\Core\Projection\ContentGraph\Filter\NodeType\NodeTypeCriteria::create(\Neos\ContentRepository\Core\NodeType\NodeTypeNames::fromStringArray($searchNodeTypes), \Neos\ContentRepository\Core\NodeType\NodeTypeNames::createEmpty()), searchTerm: $term));
}

public function startingPointNodeIsNotGiven(Context $context)
{
$term = "term";
$searchNodeTypes = [];
// TODO 9.0 migration: The replacement needs a node as starting point for the search. Please provide a node, to make this replacement working.
$node = 'we-need-a-node-here';
$subgraph = $this->contentRepositoryRegistry->subgraphForNode($node);
$nodes = $subgraph->findDescendantNodes($node->aggregateId, \Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindDescendantNodesFilter::create(nodeTypes: \Neos\ContentRepository\Core\Projection\ContentGraph\Filter\NodeType\NodeTypeCriteria::create(\Neos\ContentRepository\Core\NodeType\NodeTypeNames::fromStringArray($searchNodeTypes), \Neos\ContentRepository\Core\NodeType\NodeTypeNames::createEmpty()), searchTerm: $term));
}
}

30 changes: 25 additions & 5 deletions tests/Sets/ContentRepository90/Fixture/node-search-service.php.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@

namespace Neos\Rector\Test;

use Neos\Flow\Annotations as Flow;
use Neos\ContentRepository\Domain\Model\Node;
use Neos\ContentRepository\Domain\Service\Context;

class SomeClass extends AnotherClass
{
/**
* @Flow\Inject
* @var \Neos\Neos\Domain\Service\NodeSearchService
*/
private $nodeSearchService;

/**
* @Flow\Inject
* @var \Neos\Neos\Domain\Service\NodeSearchServiceInterface
*/
private $nodeSearchServiceInterface;

public function startingPointNodeIsGiven(Node $node, Context $context)
{
$term = "term";
Expand All @@ -25,25 +33,28 @@ class SomeClass extends AnotherClass
$searchNodeTypes = [];
$nodes = $this->nodeSearchService->findByProperties($term, $searchNodeTypes, $context);
}

public function startingPointNodeIsGivenUsingInterface(Node $node, Context $context)
{
$term = "term";
$searchNodeTypes = [];
$nodes = $this->nodeSearchServiceInterface->findByProperties($term, $searchNodeTypes, $context, $node);
}
}

-----
<?php

namespace Neos\Rector\Test;

use Neos\Flow\Annotations as Flow;
use Neos\ContentRepository\Domain\Model\Node;
use Neos\ContentRepository\Domain\Service\Context;

class SomeClass extends AnotherClass
{
/**
* @var \Neos\Neos\Domain\Service\NodeSearchService
*/
private $nodeSearchService;
#[\Neos\Flow\Annotations\Inject]
protected \Neos\ContentRepositoryRegistry\ContentRepositoryRegistry $contentRepositoryRegistry;

public function startingPointNodeIsGiven(\Neos\ContentRepository\Core\Projection\ContentGraph\Node $node, \Neos\Rector\ContentRepository90\Legacy\LegacyContextStub $context)
{
$term = "term";
Expand All @@ -62,5 +73,14 @@ class SomeClass extends AnotherClass
$subgraph = $this->contentRepositoryRegistry->subgraphForNode($node);
$nodes = $subgraph->findDescendantNodes($node->aggregateId, \Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindDescendantNodesFilter::create(nodeTypes: \Neos\ContentRepository\Core\Projection\ContentGraph\Filter\NodeType\NodeTypeCriteria::create(\Neos\ContentRepository\Core\NodeType\NodeTypeNames::fromStringArray($searchNodeTypes), \Neos\ContentRepository\Core\NodeType\NodeTypeNames::createEmpty()), searchTerm: $term));
}

public function startingPointNodeIsGivenUsingInterface(\Neos\ContentRepository\Core\Projection\ContentGraph\Node $node, \Neos\Rector\ContentRepository90\Legacy\LegacyContextStub $context)
{
$term = "term";
$searchNodeTypes = [];
// TODO 9.0 migration: This could be a suitable replacement. Please check if all your requirements are still fulfilled.
$subgraph = $this->contentRepositoryRegistry->subgraphForNode($node);
$nodes = $subgraph->findDescendantNodes($node->aggregateId, \Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindDescendantNodesFilter::create(nodeTypes: \Neos\ContentRepository\Core\Projection\ContentGraph\Filter\NodeType\NodeTypeCriteria::create(\Neos\ContentRepository\Core\NodeType\NodeTypeNames::fromStringArray($searchNodeTypes), \Neos\ContentRepository\Core\NodeType\NodeTypeNames::createEmpty()), searchTerm: $term));
}
}

0 comments on commit ec55fa4

Please sign in to comment.