Skip to content

Commit

Permalink
Merge pull request #3644 from neos/task/addPhpStan
Browse files Browse the repository at this point in the history
TASK: Add phpstan
  • Loading branch information
mhsdesign authored Oct 20, 2023
2 parents edf303e + 3055ab8 commit 1fab944
Show file tree
Hide file tree
Showing 34 changed files with 117 additions and 357 deletions.
17 changes: 17 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,20 @@ jobs:
cd /home/circleci/app/
bin/phpunit -c Build/BuildEssentials/PhpUnit/UnitTests.xml Packages/Application/Neos.Neos.Ui/Tests/Unit
php-linting:
docker:
- image: cimg/php:8.2-node
working_directory: *workspace_root
steps:
- attach_workspace: *attach_workspace
- restore_cache: *restore_app_cache

- run: rm -rf /home/circleci/app/Packages/Application/Neos.Neos.Ui
- run: cd /home/circleci/app/Packages/Application && mv ~/neos-ui-workspace Neos.Neos.Ui
- run: |
cd /home/circleci/app/Packages/Application/Neos.Neos.Ui/Tests/Unit
../../../bin/phpstan analyse
workflows:
version: 2
build_and_test:
Expand All @@ -161,3 +175,6 @@ workflows:
- php-unittests:
requires:
- build_flow_app
- php-linting:
requires:
- build_flow_app
5 changes: 2 additions & 3 deletions Classes/ContentRepository/Service/WorkspaceService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Neos\ContentRepository\Core\Feature\WorkspacePublication\Command\DiscardIndividualNodesFromWorkspace;
use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindClosestNodeFilter;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepository\Core\Projection\Workspace\Workspace;
use Neos\Neos\Domain\Service\NodeTypeNameFactory;
use Neos\Neos\FrontendRouting\NodeAddress;
use Neos\Neos\FrontendRouting\NodeAddressFactory;
Expand Down Expand Up @@ -128,7 +127,6 @@ public function getAllowedTargetWorkspaces(ContentRepository $contentRepository)
$user = $this->domainUserService->getCurrentUser();

$workspacesArray = [];
/** @var Workspace $workspace */
foreach ($contentRepository->getWorkspaceFinder()->findAll() as $workspace) {
// FIXME: This check should be implemented through a specialized Workspace Privilege or something similar
// Skip workspace not owned by current user
Expand Down Expand Up @@ -157,6 +155,7 @@ public function getAllowedTargetWorkspaces(ContentRepository $contentRepository)
return $workspacesArray;
}

/** @return list<RemoveNode> */
public function predictRemoveNodeFeedbackFromDiscardIndividualNodesFromWorkspaceCommand(
DiscardIndividualNodesFromWorkspace $command,
ContentRepository $contentRepository
Expand Down Expand Up @@ -192,7 +191,7 @@ public function predictRemoveNodeFeedbackFromDiscardIndividualNodesFromWorkspace

$childNode = $subgraph->findNodeById($nodeToDiscard->nodeAggregateId);
$parentNode = $subgraph->findParentNode($nodeToDiscard->nodeAggregateId);
if ($parentNode) {
if ($childNode && $parentNode) {
$result[] = new RemoveNode($childNode, $parentNode);
$handledNodes[] = $nodeToDiscard;
}
Expand Down
53 changes: 26 additions & 27 deletions Classes/Controller/BackendServiceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Eel\FlowQuery\FlowQuery;
use Neos\Eel\FlowQuery\Operations\GetOperation;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Mvc\ActionRequest;
use Neos\Flow\Mvc\ActionResponse;
Expand All @@ -39,7 +40,6 @@
use Neos\Neos\Service\UserService;
use Neos\Neos\Ui\ContentRepository\Service\NeosUiNodeService;
use Neos\Neos\Ui\ContentRepository\Service\WorkspaceService;
use Neos\Neos\Ui\Domain\Model\ChangeCollection;
use Neos\Neos\Ui\Domain\Model\Feedback\Messages\Error;
use Neos\Neos\Ui\Domain\Model\Feedback\Messages\Info;
use Neos\Neos\Ui\Domain\Model\Feedback\Messages\Success;
Expand All @@ -50,7 +50,6 @@
use Neos\Neos\Ui\Fusion\Helper\NodeInfoHelper;
use Neos\Neos\Ui\Fusion\Helper\WorkspaceHelper;
use Neos\Neos\Ui\Service\NodeClipboard;
use Neos\Neos\Ui\Service\NodePolicyService;
use Neos\Neos\Ui\Service\PublishingService;
use Neos\Neos\Ui\TypeConverter\ChangeCollectionConverter;
use Neos\Neos\Utility\NodeUriPathSegmentGenerator;
Expand Down Expand Up @@ -103,12 +102,6 @@ class BackendServiceController extends ActionController
*/
protected $userService;

/**
* @Flow\Inject
* @var NodePolicyService
*/
protected $nodePolicyService;

/**
* @Flow\Inject
* @var ChangeCollectionConverter
Expand Down Expand Up @@ -157,15 +150,13 @@ protected function initializeController(ActionRequest $request, ActionResponse $

/**
* Apply a set of changes to the system
* @param array<int,array<string,mixed>> $changes
*/
/** @phpstan-ignore-next-line */
public function changeAction(array $changes): void
{
$contentRepositoryId = SiteDetectionResult::fromRequest($this->request->getHttpRequest())->contentRepositoryId;

/** @param array<int,array<string,mixed>> $changes */
$changes = $this->changeCollectionConverter->convert($changes, $contentRepositoryId);
/** @var ChangeCollection $changes */
try {
$count = $changes->count();
$changes->apply();
Expand Down Expand Up @@ -208,9 +199,8 @@ public function publishAllAction(): void
/**
* Publish nodes
*
* @param array $nodeContextPaths
* @param list<string> $nodeContextPaths
*/
/** @phpstan-ignore-next-line */
public function publishAction(array $nodeContextPaths, string $targetWorkspaceName): void
{
$contentRepositoryId = SiteDetectionResult::fromRequest($this->request->getHttpRequest())->contentRepositoryId;
Expand Down Expand Up @@ -267,9 +257,8 @@ public function publishAction(array $nodeContextPaths, string $targetWorkspaceNa
/**
* Discard nodes
*
* @param array $nodeContextPaths
* @param list<string> $nodeContextPaths
*/
/** @phpstan-ignore-next-line */
public function discardAction(array $nodeContextPaths): void
{
$contentRepositoryId = SiteDetectionResult::fromRequest($this->request->getHttpRequest())->contentRepositoryId;
Expand Down Expand Up @@ -417,12 +406,11 @@ public function changeBaseWorkspaceAction(string $targetWorkspaceName, string $d
/**
* Persists the clipboard node on copy
*
* @param array $nodes
* @param list<string> $nodes
* @return void
* @throws \Neos\Flow\Property\Exception
* @throws \Neos\Flow\Security\Exception
*/
/** @phpstan-ignore-next-line */
public function copyNodesAction(array $nodes): void
{
$contentRepositoryId = SiteDetectionResult::fromRequest($this->request->getHttpRequest())->contentRepositoryId;
Expand Down Expand Up @@ -450,11 +438,10 @@ public function clearClipboardAction()
/**
* Persists the clipboard node on cut
*
* @param array $nodes
* @param list<string> $nodes
* @throws \Neos\Flow\Property\Exception
* @throws \Neos\Flow\Security\Exception
*/
/** @phpstan-ignore-next-line */
public function cutNodesAction(array $nodes): void
{
$contentRepositoryId = SiteDetectionResult::fromRequest($this->request->getHttpRequest())->contentRepositoryId;
Expand Down Expand Up @@ -489,8 +476,8 @@ public function initializeGetAdditionalNodeMetadataAction(): void

/**
* Fetches all the node information that can be lazy-loaded
* @param list<string> $nodes
*/
/** @phpstan-ignore-next-line */
public function getAdditionalNodeMetadataAction(array $nodes): void
{
$contentRepositoryId = SiteDetectionResult::fromRequest($this->request->getHttpRequest())->contentRepositoryId;
Expand All @@ -513,7 +500,13 @@ public function getAdditionalNodeMetadataAction(array $nodes): void
}, $node->getOtherNodeVariants())));*/
if (!is_null($node)) {
$result[$nodeAddress->serializeForUri()] = [
'policy' => $this->nodePolicyService->getNodePolicyInformation($node),
// todo reimplement nodePolicyService
'policy' => [
'disallowedNodeTypes' => [],
'canRemove' => true,
'canEdit' => true,
'disallowedProperties' => []
]
//'dimensions' => $this->getCurrentDimensionPresetIdentifiersForNode($node),
//'otherNodeVariants' => $otherNodeVariants
];
Expand Down Expand Up @@ -549,7 +542,13 @@ public function getPolicyInformationAction(array $nodes): void
$node = $subgraph->findNodeById($nodeAddress->nodeAggregateId);
if (!is_null($node)) {
$result[$nodeAddress->serializeForUri()] = [
'policy' => $this->nodePolicyService->getNodePolicyInformation($node)
// todo reimplement nodePolicyService
'policy' => [
'disallowedNodeTypes' => [],
'canRemove' => true,
'canEdit' => true,
'disallowedProperties' => []
]
];
}
}
Expand All @@ -560,28 +559,28 @@ public function getPolicyInformationAction(array $nodes): void
/**
* Build and execute a flow query chain
*
* @param array $chain
* @param list<array{type: string, payload: array<string|int, mixed>}> $chain
*/
/** @phpstan-ignore-next-line */
public function flowQueryAction(array $chain): string
{
$contentRepositoryId = SiteDetectionResult::fromRequest($this->request->getHttpRequest())->contentRepositoryId;

$createContext = array_shift($chain);
$finisher = array_pop($chain);

/** @var array<int,mixed> $payload */
$payload = $createContext['payload'] ?? [];
$flowQuery = new FlowQuery(array_map(
fn ($envelope) => $this->nodeService->findNodeBySerializedNodeAddress($envelope['$node'], $contentRepositoryId),
$payload
));

foreach ($chain as $operation) {
// @phpstan-ignore-next-line
$flowQuery = call_user_func_array([$flowQuery, $operation['type']], $operation['payload']);
$flowQuery = $flowQuery->__call($operation['type'], $operation['payload']);
}

/** @see GetOperation */
assert(is_callable([$flowQuery, 'get']));

$nodeInfoHelper = new NodeInfoHelper();
$type = $finisher['type'] ?? null;
$result = match ($type) {
Expand Down
3 changes: 2 additions & 1 deletion Classes/Domain/Model/AbstractFeedback.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

abstract class AbstractFeedback implements FeedbackInterface
{
public function serialize(ControllerContext $controllerContext)
/** @return array<string, mixed> */
public function serialize(ControllerContext $controllerContext): array
{
return [
'type' => $this->getType(),
Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/Model/Changes/AbstractCreate.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function getName(): ?string
* @param Node $parentNode
* @param NodeAggregateId|null $succeedingSiblingNodeAggregateId
* @return Node
* @throws InvalidNodeCreationHandlerException|NodeNameIsAlreadyOccupied|NodeException
* @throws InvalidNodeCreationHandlerException|NodeNameIsAlreadyOccupied
*/
protected function createNode(
Node $parentNode,
Expand Down
4 changes: 2 additions & 2 deletions Classes/Domain/Model/Changes/AbstractStructuralChange.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function getSiblingDomAddress(): ?RenderedNodeDomAddress
*/
public function getSiblingNode(): ?Node
{
if ($this->siblingDomAddress === null) {
if ($this->siblingDomAddress === null || !$this->getSubject()) {
return null;
}

Expand Down Expand Up @@ -152,7 +152,7 @@ protected function finish(Node $node)
// 1) the parent of our new (or copied or moved) node is a ContentCollection;
// so we can directly update an element of this content collection

$contentRepository = $this->contentRepositoryRegistry->get($parentNode->subgraphIdentity->contentRepositoryId);
$contentRepository = $this->contentRepositoryRegistry->get($node->subgraphIdentity->contentRepositoryId);
if ($parentNode && $this->getNodeType($parentNode)->isOfType('Neos.Neos:ContentCollection') &&
// 2) the parent DOM address (i.e. the closest RENDERED node in DOM is actually the ContentCollection;
// and no other node in between
Expand Down
1 change: 0 additions & 1 deletion Classes/Domain/Model/Changes/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ public function canApply(): bool
/**
* Applies this change
*
* @throws \Neos\ContentRepository\Exception\NodeException
* @throws ContentStreamDoesNotExistYet
* @throws NodeAggregatesTypeIsAmbiguous
* @throws DimensionSpacePointNotFound
Expand Down
3 changes: 1 addition & 2 deletions Classes/Domain/Model/Changes/Remove.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public function canApply(): bool
* @throws NodeAggregatesTypeIsAmbiguous
* @throws ContentStreamDoesNotExistYet
* @throws DimensionSpacePointNotFound
* @throws \Neos\ContentRepository\Exception\NodeException
*/
public function apply(): void
{
Expand All @@ -79,7 +78,7 @@ public function apply(): void
NodeVariantSelectionStrategy::STRATEGY_ALL_SPECIALIZATIONS,
);
if ($closestDocumentParentNode !== null) {
$command = $command->withRemovalAttachmentPoint($closestDocumentParentNode?->nodeAggregateId);
$command = $command->withRemovalAttachmentPoint($closestDocumentParentNode->nodeAggregateId);
}

$contentRepository = $this->contentRepositoryRegistry->get($subject->subgraphIdentity->contentRepositoryId);
Expand Down
4 changes: 2 additions & 2 deletions Classes/Domain/Model/Feedback/Operations/Redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ public function isSimilarTo(FeedbackInterface $feedback)
* Serialize the payload for this feedback
*
* @param ControllerContext $controllerContext
* @return array
* @return array<string, string>
*/
public function serializePayload(ControllerContext $controllerContext)
public function serializePayload(ControllerContext $controllerContext): array
{
$node = $this->getNode();
$redirectUri = $this->linkingService->createNodeUri($controllerContext, $node, null, null, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ protected function renderContent(ControllerContext $controllerContext): string|R
/**
* @return array<string,mixed>
*/
public function serialize(ControllerContext $controllerContext)
public function serialize(ControllerContext $controllerContext): array
{
try {
return parent::serialize($controllerContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ public function isSimilarTo(FeedbackInterface $feedback)
* Serialize the payload for this feedback
*
* @param ControllerContext $controllerContext
* @return array
* @return array<string, string>
*/
public function serializePayload(ControllerContext $controllerContext)
public function serializePayload(ControllerContext $controllerContext): array
{
if ($this->node === null) {
$newPreviewUrl = '';
Expand Down
4 changes: 2 additions & 2 deletions Classes/Domain/Model/FeedbackCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function add(FeedbackInterface $feedback)
/**
* Serialize collection to `json_encode`able array
*
* @return array
* @return array<string, mixed>
*/
public function jsonSerialize(): array
{
Expand All @@ -76,7 +76,7 @@ public function jsonSerialize(): array
];
}

public function reset()
public function reset(): void
{
$this->feedbacks = [];
}
Expand Down
4 changes: 2 additions & 2 deletions Classes/Domain/Model/FeedbackInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ interface FeedbackInterface
* in AbstractFeedback, but can be overridden to implement fallback logic in case of errors.
*
* @param ControllerContext $controllerContext
* @return array
* @return array<string, mixed>
*/
public function serialize(ControllerContext $controllerContext);
public function serialize(ControllerContext $controllerContext): array;

/**
* Get the type identifier
Expand Down
5 changes: 2 additions & 3 deletions Classes/Domain/Model/RenderedNodeDomAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,9 @@ public function getFusionPathForContentRendering(): string
/**
* Serialize to json
*
* @return array
* @return array<string, string>
*/
#[\ReturnTypeWillChange]
public function jsonSerialize(): mixed
public function jsonSerialize(): array
{
return [
'contextPath' => $this->getContextPath(),
Expand Down
Loading

0 comments on commit 1fab944

Please sign in to comment.