Skip to content

Commit

Permalink
Merge pull request neos#3786 from neos/task/phpstanLevel8
Browse files Browse the repository at this point in the history
FEATURE: Level up to PHPStan 8
  • Loading branch information
mhsdesign authored Jun 25, 2024
2 parents 6b83212 + 7169667 commit ee00f76
Show file tree
Hide file tree
Showing 26 changed files with 107 additions and 138 deletions.
12 changes: 6 additions & 6 deletions Classes/Application/SyncWorkspace/ConflictsBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ private function createConflictFromCommandThatFailedDuringRebase(
$nodeAggregateId
);
$affectedSite = $nodeAggregateId
? $subgraph->findClosestNode(
? $subgraph?->findClosestNode(
$nodeAggregateId,
FindClosestNodeFilter::create(nodeTypes: NodeTypeNameFactory::NAME_SITE)
)
: null;
$affectedDocument = $nodeAggregateId
? $subgraph->findClosestNode(
? $subgraph?->findClosestNode(
$nodeAggregateId,
FindClosestNodeFilter::create(nodeTypes: NodeTypeNameFactory::NAME_DOCUMENT)
)
Expand Down Expand Up @@ -216,13 +216,13 @@ private function acquireSubgraphFromCommand(
$dimensionSpacePoint = $this->extractValidDimensionSpacePointFromNodeAggregate(
$nodeAggregate
);

if ($dimensionSpacePoint === null) {
return null;
}
}
}

if ($dimensionSpacePoint === null) {
return null;
}

return $contentGraph->getSubgraph(
$dimensionSpacePoint,
VisibilityConstraints::withoutRestrictions()
Expand Down
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
1 change: 1 addition & 0 deletions Classes/Controller/BackendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ public function indexAction(string $node = null)
}

$currentAccount = $this->securityContext->getAccount();
assert($currentAccount !== null);
$workspaceName = WorkspaceNameBuilder::fromAccountIdentifier($currentAccount->getAccountIdentifier());

try {
Expand Down
8 changes: 7 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 @@ -418,6 +419,7 @@ public function changeBaseWorkspaceAction(string $targetWorkspaceName, string $d
$nodeAddressFactory = NodeAddressFactory::create($contentRepository);

$currentAccount = $this->securityContext->getAccount();
assert($currentAccount !== null);
$userWorkspaceName = WorkspaceNameBuilder::fromAccountIdentifier(
$currentAccount->getAccountIdentifier()
);
Expand Down Expand Up @@ -476,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
8 changes: 4 additions & 4 deletions 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 Expand Up @@ -173,14 +173,14 @@ protected function finish(Node $node)
}
}

protected function findChildNodes(Node $node): Nodes
final protected function findChildNodes(Node $node): Nodes
{
// TODO REMOVE
return $this->contentRepositoryRegistry->subgraphForNode($node)
->findChildNodes($node->aggregateId, FindChildNodesFilter::create());
}

protected function isNodeTypeAllowedAsChildNode(Node $parentNode, NodeTypeName $nodeTypeNameToCheck): bool
final protected function isNodeTypeAllowedAsChildNode(Node $parentNode, NodeTypeName $nodeTypeNameToCheck): bool
{
$nodeTypeManager = $this->contentRepositoryRegistry->get($parentNode->contentRepositoryId)->getNodeTypeManager();

Expand All @@ -196,7 +196,7 @@ protected function isNodeTypeAllowedAsChildNode(Node $parentNode, NodeTypeName $
}
return $parentNodeType->allowsChildNodeType($nodeTypeToCheck);
}

assert($parentNode->name !== null); // were tethered
$subgraph = $this->contentRepositoryRegistry->subgraphForNode($parentNode);
$grandParentNode = $subgraph->findParentNode($parentNode->aggregateId);

Expand Down
14 changes: 7 additions & 7 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 All @@ -81,10 +78,13 @@ public function apply(): void

$contentRepository->handle($command);

$newlyCreatedNodeId = $command->nodeAggregateIdMapping->getNewNodeAggregateId($subject->aggregateId);
assert($newlyCreatedNodeId !== null); // cannot happen
$newlyCreatedNode = $this->contentRepositoryRegistry->subgraphForNode($parentNodeOfPreviousSibling)
->findNodeById(
$command->nodeAggregateIdMapping->getNewNodeAggregateId($subject->aggregateId)
);
->findNodeById($newlyCreatedNodeId);
if (!$newlyCreatedNode) {
throw new \RuntimeException(sprintf('Node %s was not found after copy.', $newlyCreatedNodeId->value), 1716023308);
}
$this->finish($newlyCreatedNode);
// NOTE: we need to run "finish" before "addNodeCreatedFeedback"
// to ensure the new node already exists when the last feedback is processed
Expand Down
14 changes: 7 additions & 7 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 All @@ -76,10 +73,13 @@ public function apply(): void

$contentRepository->handle($command);

$newlyCreatedNodeId = $command->nodeAggregateIdMapping->getNewNodeAggregateId($subject->aggregateId);
assert($newlyCreatedNodeId !== null); // cannot happen
$newlyCreatedNode = $this->contentRepositoryRegistry->subgraphForNode($parentNodeOfSucceedingSibling)
->findNodeById(
$command->nodeAggregateIdMapping->getNewNodeAggregateId($subject->aggregateId)
);
->findNodeById($newlyCreatedNodeId);
if (!$newlyCreatedNode) {
throw new \RuntimeException(sprintf('Node %s was not found after copy.', $newlyCreatedNodeId->value), 1716023308);
}
$this->finish($newlyCreatedNode);
// NOTE: we need to run "finish" before "addNodeCreatedFeedback"
// to ensure the new node already exists when the last feedback is processed
Expand Down
11 changes: 7 additions & 4 deletions Classes/Domain/Model/Changes/CopyInto.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 All @@ -82,10 +82,13 @@ public function apply(): void
);
$contentRepository->handle($command);

$newlyCreatedNodeId = $command->nodeAggregateIdMapping->getNewNodeAggregateId($subject->aggregateId);
assert($newlyCreatedNodeId !== null); // cannot happen
$newlyCreatedNode = $this->contentRepositoryRegistry->subgraphForNode($parentNode)
->findNodeById(
$command->nodeAggregateIdMapping->getNewNodeAggregateId($subject->aggregateId),
);
->findNodeById($newlyCreatedNodeId);
if (!$newlyCreatedNode) {
throw new \RuntimeException(sprintf('Node %s was not found after copy.', $newlyCreatedNodeId->value), 1716023308);
}
$this->finish($newlyCreatedNode);
// NOTE: we need to run "finish" before "addNodeCreatedFeedback"
// to ensure the new node already exists when the last feedback is processed
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 $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
9 changes: 3 additions & 6 deletions Classes/Domain/Model/Changes/CreateAfter.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,20 @@ public function getMode(): string
*/
public function canApply(): bool
{
if (is_null($this->subject)) {
return false;
}
$parent = $this->findParentNode($this->subject);
$nodeTypeName = $this->getNodeTypeName();

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

/**
* Create a new node after the subject
*/
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
9 changes: 3 additions & 6 deletions Classes/Domain/Model/Changes/CreateBefore.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,20 @@ public function getMode(): string
*/
public function canApply(): bool
{
if (is_null($this->subject)) {
return false;
}
$parent = $this->findParentNode($this->subject);
$nodeTypeName = $this->getNodeTypeName();

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

/**
* Create a new node after the subject
*/
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
Loading

0 comments on commit ee00f76

Please sign in to comment.