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

WIP Upgrade package to rector/rector 1.0 #59

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
"tests": "phpunit tests"
},
"require": {
"rector/rector": "0.15.24",
"phpstan/phpstan": "1.10.13",
"rector/rector": "^1.0",
"symfony/yaml": "*",
"neos/utility-arrays": "*",
"webmozart/assert": "^1.11"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
use PhpParser\Node;
use PhpParser\Node\Expr;
use PHPStan\Type\ObjectType;
use Rector\Core\Rector\AbstractRector;
use Rector\PostRector\Collector\NodesToAddCollector;
use Rector\Rector\AbstractRector;

use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

final class ContentDimensionCombinatorGetAllAllowedCombinationsRector extends AbstractRector
{
use AllTraits;

public function __construct(
private readonly NodesToAddCollector $nodesToAddCollector

)
{
}
Expand Down Expand Up @@ -49,14 +49,14 @@ public function refactor(Node $node) : ?Node
return null;
}

$this->nodesToAddCollector->addNodesBeforeNode(
[
self::assign('contentRepository', $this->this_contentRepositoryRegistry_get($this->contentRepositoryId_fromString('default'))),
self::assign('dimensionSpacePoints', $this->contentRepository_getVariationGraph_getDimensionSpacePoints()),
self::todoComment('try to directly work with $dimensionSpacePoints, instead of converting them to the legacy dimension format')
],
$node
);
// $this->nodesToAddCollector->addNodesBeforeNode(
// [
// self::assign('contentRepository', $this->this_contentRepositoryRegistry_get($this->contentRepositoryId_fromString('default'))),
// self::assign('dimensionSpacePoints', $this->contentRepository_getVariationGraph_getDimensionSpacePoints()),
// self::todoComment('try to directly work with $dimensionSpacePoints, instead of converting them to the legacy dimension format')
// ],
// $node
// );

return $this->dimensionSpacePoints_toLegacyDimensionArray();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@
use Neos\Rector\Utility\CodeSampleLoader;
use PhpParser\Node;
use PHPStan\Type\ObjectType;
use Rector\Core\Rector\AbstractRector;
use Rector\PostRector\Collector\NodesToAddCollector;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

final class ContextFactoryToLegacyContextStubRector extends AbstractRector
{
use AllTraits;

public function __construct(
private readonly NodesToAddCollector $nodesToAddCollector
)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
use Neos\Rector\Utility\CodeSampleLoader;
use PhpParser\Node;
use PHPStan\Type\ObjectType;
use Rector\Core\Rector\AbstractRector;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use Rector\PostRector\Collector\NodesToAddCollector;
use PhpParser\Node\Expr\Assign;

final class ContextGetCurrentRenderingModeRector extends AbstractRector
Expand All @@ -18,7 +17,6 @@ final class ContextGetCurrentRenderingModeRector extends AbstractRector
use ContextRectorTrait;

public function __construct(
private readonly NodesToAddCollector $nodesToAddCollector
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,19 @@

namespace Neos\Rector\ContentRepository90\Rules;

use Neos\Rector\ContentRepository90\Legacy\LegacyContextStub;
use Neos\Rector\Utility\CodeSampleLoader;
use PhpParser\Node;
use PhpParser\NodeFinder;
use PhpParser\NodeTraverser;
use PHPStan\Type\ObjectType;
use Rector\Core\Rector\AbstractRector;
use Rector\PostRector\Collector\NodesToAddCollector;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

final class ContextGetFirstLevelNodeCacheRector extends AbstractRector
{
use AllTraits;

public function __construct(
private readonly NodesToAddCollector $nodesToAddCollector
) {
}

Expand All @@ -38,14 +35,14 @@ public function getNodeTypes(): array
}

/**
* @param \PhpParser\Node\Expr\MethodCall $node
* @param \PhpParser\Node\Stmt\Expression $node
*/
public function refactor(Node $node): ?Node
public function refactor(Node $node)
{
assert($node instanceof Node\Stmt\Expression);

if ($this->containsContextGetFirstLevelNodeCache($node->expr)) {
$this->removeNode($node);
return NodeTraverser::REMOVE_NODE;
}
return $node;
}
Expand Down
32 changes: 16 additions & 16 deletions src/ContentRepository90/Rules/ContextGetRootNodeRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
use PhpParser\Node;
use PhpParser\Node\Expr;
use PHPStan\Type\ObjectType;
use Rector\Core\Rector\AbstractRector;
use Rector\PostRector\Collector\NodesToAddCollector;
use Rector\Rector\AbstractRector;

use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

final class ContextGetRootNodeRector extends AbstractRector
{
use AllTraits;

public function __construct(
private readonly NodesToAddCollector $nodesToAddCollector

)
{
}
Expand Down Expand Up @@ -49,19 +49,19 @@ public function refactor(Node $node) : ?Node
return null;
}

$this->nodesToAddCollector->addNodesBeforeNode(
[
self::withTodoComment(
'!! MEGA DIRTY CODE! Ensure to rewrite this; by getting rid of LegacyContextStub.',
self::assign('contentRepository', $this->this_contentRepositoryRegistry_get($this->contentRepositoryId_fromString('default')))
),
self::assign('workspace', $this->contentRepository_getWorkspaceFinder_findOneByName($this->workspaceName_fromString($this->context_workspaceName_fallbackToLive($node->var)))),
self::assign('rootNodeAggregate', $this->contentRepository_getContentGraph_findRootNodeAggregateByType($this->workspace_currentContentStreamId(), $this->nodeTypeName_fromString('Neos.Neos:Sites'))),
self::assign('subgraph', $this->contentRepository_getContentGraph_getSubgraph($this->workspace_currentContentStreamId(), $this->dimensionSpacePoint_fromLegacyDimensionArray($this->context_dimensions_fallbackToEmpty($node->var)), $this->visibilityConstraints($node->var))),

],
$node
);
// $this->nodesToAddCollector->addNodesBeforeNode(
// [
// self::withTodoComment(
// '!! MEGA DIRTY CODE! Ensure to rewrite this; by getting rid of LegacyContextStub.',
// self::assign('contentRepository', $this->this_contentRepositoryRegistry_get($this->contentRepositoryId_fromString('default')))
// ),
// self::assign('workspace', $this->contentRepository_getWorkspaceFinder_findOneByName($this->workspaceName_fromString($this->context_workspaceName_fallbackToLive($node->var)))),
// self::assign('rootNodeAggregate', $this->contentRepository_getContentGraph_findRootNodeAggregateByType($this->workspace_currentContentStreamId(), $this->nodeTypeName_fromString('Neos.Neos:Sites'))),
// self::assign('subgraph', $this->contentRepository_getContentGraph_getSubgraph($this->workspace_currentContentStreamId(), $this->dimensionSpacePoint_fromLegacyDimensionArray($this->context_dimensions_fallbackToEmpty($node->var)), $this->visibilityConstraints($node->var))),
//
// ],
// $node
// );

return $this->subgraph_findNodeById(
$this->nodeFactory->createPropertyFetch('rootNodeAggregate', 'nodeAggregateId')
Expand Down
6 changes: 2 additions & 4 deletions src/ContentRepository90/Rules/ContextIsInBackendRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
use Neos\Rector\Utility\CodeSampleLoader;
use PhpParser\Node;
use PHPStan\Type\ObjectType;
use Rector\Core\Rector\AbstractRector;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use Rector\PostRector\Collector\NodesToAddCollector;
use PhpParser\Node\Expr\Assign;
use PhpParser\NodeDumper;

Expand All @@ -19,7 +18,6 @@ final class ContextIsInBackendRector extends AbstractRector
use ContextRectorTrait;

public function __construct(
private readonly NodesToAddCollector $nodesToAddCollector
) {
}

Expand All @@ -38,7 +36,7 @@ public function getNodeTypes(): array
}

/**
* @param \PhpParser\Node\Stmt\Expression $node
* @param \PhpParser\Node\Expr\MethodCall $node
*/
public function refactor(Node $node): ?Node
{
Expand Down
6 changes: 2 additions & 4 deletions src/ContentRepository90/Rules/ContextIsLiveRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
use Neos\Rector\Utility\CodeSampleLoader;
use PhpParser\Node;
use PHPStan\Type\ObjectType;
use Rector\Core\Rector\AbstractRector;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use Rector\PostRector\Collector\NodesToAddCollector;
use PhpParser\Node\Expr\Assign;
use PhpParser\NodeDumper;

Expand All @@ -19,7 +18,6 @@ final class ContextIsLiveRector extends AbstractRector
use ContextRectorTrait;

public function __construct(
private readonly NodesToAddCollector $nodesToAddCollector
) {
}

Expand All @@ -38,7 +36,7 @@ public function getNodeTypes(): array
}

/**
* @param \PhpParser\Node\Stmt\Expression $node
* @param \PhpParser\Node\Expr\MethodCall $node
*/
public function refactor(Node $node): ?Node
{
Expand Down
7 changes: 0 additions & 7 deletions src/ContentRepository90/Rules/ContextRectorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,8 @@

namespace Neos\Rector\ContentRepository90\Rules;

use Neos\Rector\Utility\CodeSampleLoader;
use PhpParser\Node;
use PhpParser\NodeFinder;
use PHPStan\Type\ObjectType;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use Rector\PostRector\Collector\NodesToAddCollector;
use PhpParser\Node\Expr\Assign;
use PhpParser\NodeDumper;

trait ContextRectorTrait
{
Expand Down
6 changes: 4 additions & 2 deletions src/ContentRepository90/Rules/NodeFactoryResetRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

use Neos\Rector\Utility\CodeSampleLoader;
use PhpParser\Node;
use PhpParser\NodeTraverser;
use PHPStan\Type\ObjectType;
use Rector\Core\Rector\AbstractRector;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

final class NodeFactoryResetRector extends AbstractRector
Expand All @@ -33,7 +34,7 @@ public function getNodeTypes() : array
/**
* @param \PhpParser\Node\Expr\MethodCall $node
*/
public function refactor(Node $node) : ?Node
public function refactor(Node $node)
{
assert($node instanceof Node\Expr\MethodCall);

Expand All @@ -44,6 +45,7 @@ public function refactor(Node $node) : ?Node
return null;
}

// return NodeTraverser::REMOVE_NODE;
$this->removeNode($node);

return $node;
Expand Down
18 changes: 9 additions & 9 deletions src/ContentRepository90/Rules/NodeFindParentNodeRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
use Neos\Rector\Utility\CodeSampleLoader;
use PhpParser\Node;
use PHPStan\Type\ObjectType;
use Rector\Core\Rector\AbstractRector;
use Rector\PostRector\Collector\NodesToAddCollector;
use Rector\Rector\AbstractRector;

use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

final class NodeFindParentNodeRector extends AbstractRector
{
use AllTraits;

public function __construct(
private readonly NodesToAddCollector $nodesToAddCollector

)
{
}
Expand Down Expand Up @@ -48,12 +48,12 @@ public function refactor(Node $node): ?Node
return null;
}

$this->nodesToAddCollector->addNodesBeforeNode(
[
self::assign('subgraph', $this->this_contentRepositoryRegistry_subgraphForNode($node->var)),
],
$node
);
// $this->nodesToAddCollector->addNodesBeforeNode(
// [
// self::assign('subgraph', $this->this_contentRepositoryRegistry_subgraphForNode($node->var)),
// ],
// $node
// );

return $this->subgraph_findParentNode($node->var);
}
Expand Down
20 changes: 10 additions & 10 deletions src/ContentRepository90/Rules/NodeGetChildNodesRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
use Neos\Rector\Utility\CodeSampleLoader;
use PhpParser\Node;
use PHPStan\Type\ObjectType;
use Rector\Core\Rector\AbstractRector;
use Rector\PostRector\Collector\NodesToAddCollector;
use Rector\Rector\AbstractRector;

use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

final class NodeGetChildNodesRector extends AbstractRector
{
use AllTraits;

public function __construct(
private readonly NodesToAddCollector $nodesToAddCollector

)
{
}
Expand Down Expand Up @@ -70,13 +70,13 @@ public function refactor(Node $node) : ?Node
}
}

$this->nodesToAddCollector->addNodesBeforeNode(
[
self::assign('subgraph', $this->this_contentRepositoryRegistry_subgraphForNode($node->var)),
self::todoComment('Try to remove the iterator_to_array($nodes) call.')
],
$node
);
// $this->nodesToAddCollector->addNodesBeforeNode(
// [
// self::assign('subgraph', $this->this_contentRepositoryRegistry_subgraphForNode($node->var)),
// self::todoComment('Try to remove the iterator_to_array($nodes) call.')
// ],
// $node
// );

return $this->iteratorToArray(
$this->subgraph_findChildNodes($node->var, $nodeTypeFilterExpr, $limitExpr, $offsetExpr)
Expand Down
Loading
Loading