Skip to content

Commit

Permalink
Merge pull request #4703 from neos/task/improvePhpStanByFixingFlow
Browse files Browse the repository at this point in the history
TASK: Improve PhpStan By Fixing Flow
  • Loading branch information
kitsunet authored Nov 8, 2023
2 parents b1e4dd8 + 134c875 commit f622bde
Show file tree
Hide file tree
Showing 14 changed files with 368 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ private function determineResourcesPath(): string

private static function defaultResourcesPath(): string
{
// @phpstan-ignore-next-line
return FLOW_PATH_DATA . 'Persistent/Resources';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ protected function evaluateOperator($value, $operator, $operand)
{
if ($operator === 'instanceof' && $value instanceof Node) {
if ($this->operandIsSimpleType($operand)) {
/** @phpstan-ignore-next-line Flow does not properly declare its types here */
return $this->handleSimpleTypeOperand($operand, $value);
} elseif ($operand === Node::class) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,10 @@ public function listCommand(?string $filter = null, bool $includeAbstract = true
}

/**
* @param array<string, mixed> $array
* @param int $truncateLevel 0 for no truncation and 1 to only show the first keys of the array
* @param int $currentLevel 1 for the start and will be incremented recursively
* @return array<string, mixed>
*/
private static function truncateArrayAtLevel(array $array, int $truncateLevel, int $currentLevel = 1): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class NodeTypesLoader implements LoaderInterface
*/
private $configurationBasePath;

/** @phpstan-ignore-next-line FLOW_PATH_CONFIGURATION not found */
public function __construct(YamlSource $yamlSource, string $configurationBasePath = FLOW_PATH_CONFIGURATION, protected readonly ?Bootstrap $bootstrap = null)
{
$this->yamlSource = $yamlSource;
Expand Down
2 changes: 0 additions & 2 deletions Neos.ContentRepositoryRegistry/Classes/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public function boot(Bootstrap $bootstrap)
$dispatcher = $bootstrap->getSignalSlotDispatcher();

$dispatcher->connect(ConfigurationManager::class, 'configurationManagerReady', function (ConfigurationManager $configurationManager) use ($bootstrap) {
/** @phpstan-ignore-next-line FLOW_* */
$configurationManager->registerConfigurationType('NodeTypes', new NodeTypesLoader(new YamlSource(), FLOW_PATH_CONFIGURATION, $bootstrap));
});

Expand All @@ -64,7 +63,6 @@ public function boot(Bootstrap $bootstrap)
}
}

/** @phpstan-ignore-next-line FLOW_* */
$nodeTypeConfigurationFileMonitor->monitorDirectory(FLOW_PATH_CONFIGURATION, 'NodeTypes(\..+)\.yaml');

$nodeTypeConfigurationFileMonitor->detectChanges();
Expand Down
15 changes: 5 additions & 10 deletions Neos.Neos/Classes/Controller/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,15 @@ public function tokenLoginAction(string $token): void
if ($newSessionId === false) {
$this->logger->warning(sprintf('Token-based login failed, non-existing or expired token %s', $token));
$this->redirect('index');
return;
}

$this->logger->debug(sprintf('Token-based login succeeded, token %s', $token));

$newSession = $this->sessionManager->getSession($newSessionId);
if ($newSession->canBeResumed()) {
if ($newSession?->canBeResumed()) {
$newSession->resume();
}
if (!$newSession->isStarted()) {
if (!$newSession?->isStarted()) {
$this->logger->error(sprintf(
'Failed resuming or starting session %s which was referred to in the login token %s.',
$newSessionId,
Expand Down Expand Up @@ -211,13 +210,11 @@ protected function onAuthenticationFailure(AuthenticationRequiredException $exce
*
* @param ActionRequest|null $originalRequest The request that was intercepted by the security framework,
* NULL if there was none
* @phpstan-ignore-next-line Flow does not properly declare its return type here
* @return void
* @throws SessionNotStartedException
* @throws StopActionException
* @throws \Neos\Flow\Mvc\Exception\NoSuchArgumentException
*/
protected function onAuthenticationSuccess(ActionRequest $originalRequest = null): void
protected function onAuthenticationSuccess(ActionRequest $originalRequest = null): null
{
if ($this->view instanceof JsonView) {
$this->view->assign(
Expand All @@ -227,6 +224,7 @@ protected function onAuthenticationSuccess(ActionRequest $originalRequest = null
'csrfToken' => $this->securityContext->getCsrfProtectionToken()
]
);
return null;
} else {
if ($originalRequest !== null) {
// Redirect to the location that redirected to the login form because the user was nog logged in
Expand Down Expand Up @@ -268,11 +266,8 @@ public function logoutAction(): void
/**
* Disable the default error flash message
*
*
* @phpstan-ignore-next-line Flow does not properly declare its types here
* @return false
*/
protected function getErrorFlashMessage(): bool
protected function getErrorFlashMessage(): false
{
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ public function indexAction()

/**
* Display no flash message at all on errors.
*
* @phpstan-ignore-next-line Flow does not properly declare its types here
* @return false
*/
protected function getErrorFlashMessage()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public function indexAction()
$packageGroups = [];
foreach ($this->packageManager->getAvailablePackages() as $package) {
/** @var Package $package */
/** @phpstan-ignore-next-line FLOW_PATH_PACKAGES is known at this point */
$packagePath = substr($package->getPackagepath(), strlen(FLOW_PATH_PACKAGES));
$packageGroup = substr($packagePath, 0, strpos($packagePath, '/') ?: null);
$packageGroups[$packageGroup][$package->getPackageKey()] = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,6 @@ public function createSiteNodeAction($packageKey, $siteName, $nodeType)
1412372375
);
$this->redirect('createSiteNode');
return;
} catch (SiteNodeTypeIsInvalid $exception) {
$this->addFlashMessage(
$this->getModuleLabel(
Expand All @@ -406,7 +405,6 @@ public function createSiteNodeAction($packageKey, $siteName, $nodeType)
1412372375
);
$this->redirect('createSiteNode');
return;
} catch (SiteNodeNameIsAlreadyInUseByAnotherSite | NodeNameIsAlreadyOccupied $exception) {
$this->addFlashMessage(
$this->getModuleLabel('sites.SiteCreationError.siteWithSiteNodeNameAlreadyExists.body', [$siteName]),
Expand All @@ -416,7 +414,6 @@ public function createSiteNodeAction($packageKey, $siteName, $nodeType)
1412372375
);
$this->redirect('createSiteNode');
return;
}

$this->addFlashMessage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ public function showAction(WorkspaceName $workspace): void
if (is_null($workspaceObj)) {
/** @todo add flash message */
$this->redirect('index');
return;
}
$this->view->assignMultiple([
'selectedWorkspace' => $workspaceObj,
Expand Down Expand Up @@ -259,7 +258,6 @@ public function editAction(WorkspaceName $workspaceName): void
if (is_null($workspace)) {
// @todo add flash message
$this->redirect('index');
return;
}
$this->view->assign('workspace', $workspace);
$this->view->assign('baseWorkspaceOptions', $this->prepareBaseWorkspaceOptions($contentRepository, $workspace));
Expand Down Expand Up @@ -304,7 +302,6 @@ public function updateAction(
Message::SEVERITY_ERROR
);
$this->redirect('index');
return;
}

if (!$workspace->workspaceTitle->equals($title) || !$workspace->workspaceDescription->equals($description)) {
Expand Down Expand Up @@ -360,12 +357,10 @@ public function deleteAction(WorkspaceName $workspaceName): void
Message::SEVERITY_ERROR
);
$this->redirect('index');
return;
}

if ($workspace->isPersonalWorkspace()) {
$this->redirect('index');
return;
}

$dependentWorkspaces = $contentRepository->getWorkspaceFinder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ public function processRequest(ActionRequest $request, ActionResponse $response)
{
try {
parent::processRequest($request, $response);
/** @phpstan-ignore-next-line Although Flow does not declare it, StopActionExceptions might be thrown */
} catch (StopActionException $exception) {
throw $exception;
} catch (\Exception $exception) {
Expand Down
9 changes: 9 additions & 0 deletions bootstrap-phpstan.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

/**
* This bootstrap helps phpstan to detect all available constants
*/

$_SERVER['FLOW_ROOTPATH'] = dirname(__DIR__, 2);

new \Neos\Flow\Core\Bootstrap('Testing');
Loading

0 comments on commit f622bde

Please sign in to comment.