-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
53 changed files
with
783 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Neos\Rector\ContentRepository90\Legacy; | ||
|
||
/** | ||
* @deprecated | ||
*/ | ||
class NodeLegacyStub | ||
{ | ||
|
||
public function getContext() : LegacyContextStub { | ||
return new LegacyContextStub([]); | ||
} | ||
|
||
public function isLive() :bool { | ||
return false; | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
src/ContentRepository90/Rules/ContextGetCurrentRenderingModeRector.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
declare (strict_types=1); | ||
|
||
namespace Neos\Rector\ContentRepository90\Rules; | ||
|
||
use Neos\Rector\Utility\CodeSampleLoader; | ||
use PhpParser\Node; | ||
use PHPStan\Type\ObjectType; | ||
use Rector\Core\Rector\AbstractRector; | ||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; | ||
use Rector\PostRector\Collector\NodesToAddCollector; | ||
use PhpParser\Node\Expr\Assign; | ||
|
||
final class ContextGetCurrentRenderingModeRector extends AbstractRector | ||
{ | ||
use AllTraits; | ||
use ContextRectorTrait; | ||
|
||
public function __construct( | ||
private readonly NodesToAddCollector $nodesToAddCollector | ||
) { | ||
} | ||
|
||
|
||
public function getRuleDefinition(): RuleDefinition | ||
{ | ||
return CodeSampleLoader::fromFile('"ContentContext::getCurrentRenderingMode()" will be replaced with RenderingModeService::findByCurrentUser().', __CLASS__); | ||
} | ||
|
||
/** | ||
* @return array<class-string<Node>> | ||
*/ | ||
public function getNodeTypes(): array | ||
{ | ||
return [Node\Expr\MethodCall::class]; | ||
} | ||
|
||
/** | ||
* @param \PhpParser\Node\Stmt\Expression $node | ||
*/ | ||
public function refactor(Node $node): ?Node | ||
{ | ||
assert($node instanceof Node\Expr\MethodCall); | ||
|
||
$oldContextMethod = 'getCurrentRenderingMode'; | ||
if ( | ||
$this->isContextWithMethod($node, $oldContextMethod) | ||
) { | ||
|
||
return $this->nodeFactory->createMethodCall( | ||
$this->nodeFactory->createPropertyFetch( | ||
'this', | ||
'renderingModeService' | ||
), | ||
'findByCurrentUser' | ||
); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
} |
67 changes: 67 additions & 0 deletions
67
src/ContentRepository90/Rules/ContextIsInBackendRector.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
declare (strict_types=1); | ||
|
||
namespace Neos\Rector\ContentRepository90\Rules; | ||
|
||
use Neos\Rector\Utility\CodeSampleLoader; | ||
use PhpParser\Node; | ||
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; | ||
|
||
final class ContextIsInBackendRector extends AbstractRector | ||
{ | ||
use AllTraits; | ||
use ContextRectorTrait; | ||
|
||
public function __construct( | ||
private readonly NodesToAddCollector $nodesToAddCollector | ||
) { | ||
} | ||
|
||
|
||
public function getRuleDefinition(): RuleDefinition | ||
{ | ||
return CodeSampleLoader::fromFile('"ContentContext::isLive()" will be replaced with RenderingModeService::findByCurrentUser().', __CLASS__); | ||
} | ||
|
||
/** | ||
* @return array<class-string<Node>> | ||
*/ | ||
public function getNodeTypes(): array | ||
{ | ||
return [Node\Expr\MethodCall::class]; | ||
} | ||
|
||
/** | ||
* @param \PhpParser\Node\Stmt\Expression $node | ||
*/ | ||
public function refactor(Node $node): ?Node | ||
{ | ||
assert($node instanceof Node\Expr\MethodCall); | ||
|
||
$oldContextMethod = 'isInBackend'; | ||
if ($this->isContextWithMethod($node, $oldContextMethod)) { | ||
|
||
$renderingModeService = $this->nodeFactory->createMethodCall( | ||
$this->nodeFactory->createPropertyFetch( | ||
'this', | ||
'renderingModeService' | ||
), | ||
'findByCurrentUser' | ||
); | ||
|
||
return $this->nodeFactory->createPropertyFetch( | ||
$renderingModeService, 'isEdit' | ||
); | ||
|
||
} | ||
|
||
return null; | ||
} | ||
|
||
} |
Oops, something went wrong.