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

FEATURE: Rewrite code also for NodeSearchServiceInterface #119

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
}
}

Loading