Skip to content

Commit

Permalink
TASK: Declare ChangeInterface::getSubject as non nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Jun 24, 2024
1 parent 2b08575 commit 7169667
Show file tree
Hide file tree
Showing 20 changed files with 74 additions and 124 deletions.
2 changes: 1 addition & 1 deletion Classes/Application/SyncWorkspace/SyncWorkspaceCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
public function __construct(
public ContentRepositoryId $contentRepositoryId,
public WorkspaceName $workspaceName,
public DimensionSpacePoint $preferredDimensionSpacePoint,
public ?DimensionSpacePoint $preferredDimensionSpacePoint,
public RebaseErrorHandlingStrategy $rebaseErrorHandlingStrategy
) {
}
Expand Down
7 changes: 6 additions & 1 deletion Classes/Controller/BackendServiceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePoint;
use Neos\ContentRepository\Core\Feature\WorkspaceModification\Exception\WorkspaceIsNotEmptyException;
use Neos\ContentRepository\Core\Feature\WorkspaceRebase\Dto\RebaseErrorHandlingStrategy;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepository\Core\Projection\ContentGraph\VisibilityConstraints;
use Neos\ContentRepository\Core\SharedModel\Exception\NodeAggregateCurrentlyDoesNotExist;
use Neos\ContentRepository\Core\SharedModel\Exception\NodeAggregateDoesCurrentlyNotCoverDimensionSpacePoint;
Expand Down Expand Up @@ -477,24 +478,28 @@ public function changeBaseWorkspaceAction(string $targetWorkspaceName, string $d
// todo ensure that https://github.com/neos/neos-ui/pull/3734 doesnt need to be refixed in Neos 9.0
$redirectNode = $documentNode;
while (true) {
// @phpstan-ignore-next-line
$redirectNodeInBaseWorkspace = $subgraph->findNodeById($redirectNode->aggregateId);
if ($redirectNodeInBaseWorkspace) {
break;
} else {
// @phpstan-ignore-next-line
$redirectNode = $subgraph->findParentNode($redirectNode->aggregateId);
// get parent always returns Node
if (!$redirectNode) {
throw new \Exception(
sprintf(
'Wasn\'t able to locate any valid node in rootline of node %s in the workspace %s.',
$documentNode->aggregateId->value,
$documentNode?->aggregateId->value,
$targetWorkspaceName
),
1458814469
);
}
}
}
/** @var Node $documentNode */
/** @var Node $redirectNode */

// If current document node exists in the base workspace, then reload, else redirect
if ($redirectNode->equals($documentNode)) {
Expand Down
26 changes: 11 additions & 15 deletions Classes/Domain/Model/AbstractChange.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/
abstract class AbstractChange implements ChangeInterface
{
protected ?Node $subject = null;
protected Node $subject;

#[Flow\Inject]
protected ContentRepositoryRegistry $contentRepositoryRegistry;
Expand Down Expand Up @@ -56,7 +56,7 @@ final public function setSubject(Node $subject): void
$this->subject = $subject;
}

final public function getSubject(): ?Node
final public function getSubject(): Node
{
return $this->subject;
}
Expand All @@ -66,13 +66,11 @@ final public function getSubject(): ?Node
*/
final protected function updateWorkspaceInfo(): void
{
if (!is_null($this->subject)) {
$subgraph = $this->contentRepositoryRegistry->subgraphForNode($this->subject);
$documentNode = $subgraph->findClosestNode($this->subject->aggregateId, FindClosestNodeFilter::create(nodeTypes: NodeTypeNameFactory::NAME_DOCUMENT));
if (!is_null($documentNode)) {
$updateWorkspaceInfo = new UpdateWorkspaceInfo($documentNode->contentRepositoryId, $documentNode->workspaceName);
$this->feedbackCollection->add($updateWorkspaceInfo);
}
$subgraph = $this->contentRepositoryRegistry->subgraphForNode($this->subject);
$documentNode = $subgraph->findClosestNode($this->subject->aggregateId, FindClosestNodeFilter::create(nodeTypes: NodeTypeNameFactory::NAME_DOCUMENT));
if (!is_null($documentNode)) {
$updateWorkspaceInfo = new UpdateWorkspaceInfo($documentNode->contentRepositoryId, $documentNode->workspaceName);
$this->feedbackCollection->add($updateWorkspaceInfo);
}
}

Expand Down Expand Up @@ -108,11 +106,9 @@ protected function reloadDocument(Node $node = null): void
*/
final protected function addNodeCreatedFeedback(Node $subject = null): void
{
$node = $subject ?: $this->getSubject();
if ($node) {
$nodeCreated = new NodeCreated();
$nodeCreated->setNode($node);
$this->feedbackCollection->add($nodeCreated);
}
$node = $subject ?? $this->getSubject();
$nodeCreated = new NodeCreated();
$nodeCreated->setNode($node);
$this->feedbackCollection->add($nodeCreated);
}
}
2 changes: 1 addition & 1 deletion Classes/Domain/Model/ChangeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function setSubject(Node $subject): void;
/**
* Get the subject
*/
public function getSubject(): ?Node;
public function getSubject(): Node;

/**
* Checks whether this change can be applied to the subject
Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/Model/Changes/AbstractStructuralChange.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function getSiblingDomAddress(): ?RenderedNodeDomAddress
*/
public function getSiblingNode(): ?Node
{
if ($this->siblingDomAddress === null || !$this->getSubject()) {
if ($this->siblingDomAddress === null) {
return null;
}

Expand Down
5 changes: 1 addition & 4 deletions Classes/Domain/Model/Changes/CopyAfter.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ class CopyAfter extends AbstractStructuralChange
*/
public function canApply(): bool
{
if (is_null($this->subject)) {
return false;
}
$siblingNode = $this->getSiblingNode();
if (is_null($siblingNode)) {
return false;
Expand All @@ -57,7 +54,7 @@ public function apply(): void
: null;
$subject = $this->subject;

if ($this->canApply() && $subject && !is_null($previousSibling) && !is_null($parentNodeOfPreviousSibling)) {
if ($this->canApply() && !is_null($previousSibling) && !is_null($parentNodeOfPreviousSibling)) {
$succeedingSibling = null;
try {
$succeedingSibling = $this->findChildNodes($parentNodeOfPreviousSibling)->next($previousSibling);
Expand Down
5 changes: 1 addition & 4 deletions Classes/Domain/Model/Changes/CopyBefore.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ class CopyBefore extends AbstractStructuralChange
*/
public function canApply(): bool
{
if (is_null($this->subject)) {
return false;
}
$siblingNode = $this->getSiblingNode();
if (is_null($siblingNode)) {
return false;
Expand All @@ -57,7 +54,7 @@ public function apply(): void
? $this->findParentNode($succeedingSibling)
: null;
$subject = $this->subject;
if ($this->canApply() && !is_null($subject) && !is_null($succeedingSibling)
if ($this->canApply() && !is_null($succeedingSibling)
&& !is_null($parentNodeOfSucceedingSibling)
) {
$contentRepository = $this->contentRepositoryRegistry->get($subject->contentRepositoryId);
Expand Down
4 changes: 2 additions & 2 deletions Classes/Domain/Model/Changes/CopyInto.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function canApply(): bool
{
$parentNode = $this->getParentNode();

return $this->subject && $parentNode && $this->isNodeTypeAllowedAsChildNode($parentNode, $this->subject->nodeTypeName);
return $parentNode && $this->isNodeTypeAllowedAsChildNode($parentNode, $this->subject->nodeTypeName);
}

public function getMode(): string
Expand All @@ -66,7 +66,7 @@ public function apply(): void
{
$subject = $this->getSubject();
$parentNode = $this->getParentNode();
if ($parentNode && $subject && $this->canApply()) {
if ($parentNode && $this->canApply()) {
$contentRepository = $this->contentRepositoryRegistry->get($subject->contentRepositoryId);
$command = CopyNodesRecursively::createFromSubgraphAndStartNode(
$contentRepository->getContentGraph($subject->workspaceName)->getSubgraph(
Expand Down
4 changes: 2 additions & 2 deletions Classes/Domain/Model/Changes/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function canApply(): bool
$subject = $this->getSubject();
$nodeTypeName = $this->getNodeTypeName();

return $subject && $nodeTypeName && $this->isNodeTypeAllowedAsChildNode($subject, $nodeTypeName);
return $nodeTypeName && $this->isNodeTypeAllowedAsChildNode($subject, $nodeTypeName);
}

/**
Expand All @@ -49,7 +49,7 @@ public function canApply(): bool
public function apply(): void
{
$parentNode = $this->getSubject();
if ($parentNode && $this->canApply()) {
if ($this->canApply()) {
$this->createNode($parentNode, null);
$this->updateWorkspaceInfo();
}
Expand Down
7 changes: 2 additions & 5 deletions Classes/Domain/Model/Changes/CreateAfter.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ public function getMode(): string
*/
public function canApply(): bool
{
if (is_null($this->subject)) {
return false;
}
$parent = $this->findParentNode($this->subject);
$nodeTypeName = $this->getNodeTypeName();

Expand All @@ -46,9 +43,9 @@ public function canApply(): bool
*/
public function apply(): void
{
$parentNode = $this->subject ? $this->findParentNode($this->subject) : null;
$parentNode = $this->findParentNode($this->subject);
$subject = $this->subject;
if ($this->canApply() && !is_null($subject) && !is_null($parentNode)) {
if ($this->canApply() && !is_null($parentNode)) {
$succeedingSibling = null;
try {
$succeedingSibling = $this->findChildNodes($parentNode)->next($subject);
Expand Down
7 changes: 2 additions & 5 deletions Classes/Domain/Model/Changes/CreateBefore.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ public function getMode(): string
*/
public function canApply(): bool
{
if (is_null($this->subject)) {
return false;
}
$parent = $this->findParentNode($this->subject);
$nodeTypeName = $this->getNodeTypeName();

Expand All @@ -46,9 +43,9 @@ public function canApply(): bool
*/
public function apply(): void
{
$parent = $this->subject ? $this->findParentNode($this->subject) : null;
$parent = $this->findParentNode($this->subject);
$subject = $this->subject;
if ($this->canApply() && !is_null($subject) && !is_null($parent)) {
if ($this->canApply() && !is_null($parent)) {
$this->createNode($parent, $subject->aggregateId);
$this->updateWorkspaceInfo();
}
Expand Down
6 changes: 1 addition & 5 deletions Classes/Domain/Model/Changes/MoveAfter.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ class MoveAfter extends AbstractStructuralChange
*/
public function canApply(): bool
{
if (is_null($this->subject)) {
return false;
}
$sibling = $this->getSiblingNode();
if (is_null($sibling)) {
return false;
Expand All @@ -58,9 +55,8 @@ public function apply(): void
$parentNodeOfPreviousSibling = $precedingSibling ? $this->findParentNode($precedingSibling) : null;
// "subject" is the to-be-moved node
$subject = $this->subject;
$parentNode = $this->subject ? $this->findParentNode($this->subject) : null;
$parentNode = $this->findParentNode($this->subject);
if ($this->canApply()
&& !is_null($subject)
&& !is_null($precedingSibling)
&& !is_null($parentNodeOfPreviousSibling)
&& !is_null($parentNode)
Expand Down
7 changes: 2 additions & 5 deletions Classes/Domain/Model/Changes/MoveBefore.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ class MoveBefore extends AbstractStructuralChange
*/
public function canApply(): bool
{
if (is_null($this->subject)) {
return false;
}
$siblingNode = $this->getSiblingNode();
if (is_null($siblingNode)) {
return false;
Expand All @@ -54,9 +51,9 @@ public function apply(): void
$succeedingSibling = $this->getSiblingNode();
// "subject" is the to-be-moved node
$subject = $this->subject;
$parentNode = $subject ? $this->findParentNode($subject) : null;
$parentNode = $this->findParentNode($subject);
$succeedingSiblingParent = $succeedingSibling ? $this->findParentNode($succeedingSibling) : null;
if ($this->canApply() && !is_null($subject) && !is_null($succeedingSibling)
if ($this->canApply() && !is_null($succeedingSibling)
&& !is_null($parentNode) && !is_null($succeedingSiblingParent)
) {
$precedingSibling = null;
Expand Down
7 changes: 2 additions & 5 deletions Classes/Domain/Model/Changes/MoveInto.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function setParentContextPath(string $parentContextPath): void

public function getParentNode(): ?Node
{
if ($this->parentContextPath === null || !$this->getSubject()) {
if ($this->parentContextPath === null) {
return null;
}

Expand All @@ -57,9 +57,6 @@ public function getMode(): string
*/
public function canApply(): bool
{
if (is_null($this->subject)) {
return false;
}
$parent = $this->getParentNode();

return $parent && $this->isNodeTypeAllowedAsChildNode($parent, $this->subject->nodeTypeName);
Expand All @@ -74,7 +71,7 @@ public function apply(): void
$parentNode = $this->getParentNode();
// "subject" is the to-be-moved node
$subject = $this->subject;
if ($this->canApply() && $parentNode && $subject) {
if ($this->canApply() && $parentNode) {
$otherParent = $this->contentRepositoryRegistry->subgraphForNode($subject)
->findParentNode($subject->aggregateId);

Expand Down
6 changes: 3 additions & 3 deletions Classes/Domain/Model/Changes/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function getIsInline(): bool
public function canApply(): bool
{
$propertyName = $this->getPropertyName();
if (!$this->subject || !$propertyName) {
if (!$propertyName) {
return false;
}
$nodeType = $this->getNodeType($this->subject);
Expand All @@ -147,9 +147,9 @@ public function canApply(): bool
public function apply(): void
{
$subject = $this->subject;
$nodeType = $subject ? $this->getNodeType($subject) : null;
$nodeType = $this->getNodeType($subject);
$propertyName = $this->getPropertyName();
if (is_null($subject) || is_null($nodeType) || is_null($propertyName) || $this->canApply() === false) {
if (is_null($nodeType) || is_null($propertyName) || $this->canApply() === false) {
return;
}

Expand Down
10 changes: 2 additions & 8 deletions Classes/Domain/Model/Changes/Remove.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,14 @@
*/
class Remove extends AbstractChange
{
/**
* @Flow\Inject
* @var ContentCacheFlusher
*/
protected $contentCacheFlusher;

/**
* Checks whether this change can be applied to the subject
*
* @return boolean
*/
public function canApply(): bool
{
return !is_null($this->subject);
return true;
}

/**
Expand All @@ -60,7 +54,7 @@ public function canApply(): bool
public function apply(): void
{
$subject = $this->subject;
if ($this->canApply() && !is_null($subject)) {
if ($this->canApply()) {
$parentNode = $this->findParentNode($subject);
if (is_null($parentNode)) {
throw new \InvalidArgumentException(
Expand Down
Loading

0 comments on commit 7169667

Please sign in to comment.