Skip to content

Commit

Permalink
IBX-8138: [Rector] Applied rules from Symfony 5 Rector set lists (#385)
Browse files Browse the repository at this point in the history
For more details see https://issues.ibexa.co/browse/IBX-8138 and #385

Key changes:

* [Rector] Applied Symfony 5.1 CommandConstantReturnCodeRector

* [Rector] Applied Symfony 5.2 RenameMethodRector

* [Rector] Applied Symfony 5.3 Rector sets

* [Rector] Applied Symfony code quality Rector sets

  Applied rules:
    * LiteralGetToRequestClassConstantRector
    * ResponseStatusCodeRector
    * MakeCommandLazyRector

* [Rector] Applied Return type rectors

  Applied rules:
    * ReturnTypeFromStrictNativeCallRector
    * ReturnTypeFromStrictScalarReturnExprRector

* [Rector] Applied Symfony 6.0 AddReturnTypeDeclarationRector

* [Rector] Added Symfony Bundle::getContainerExtension return type

* Added strict types for InstallPlatformCommand consts

* Made XML serialization exception more verbose in Author and DateTime converters

* Implemented `\Ibexa\Core\MVC\Symfony\Security\User::getUserIdentifier`

---------

Co-Authored-By: Paweł Niedzielski <[email protected]>
Co-Authored-By: Konrad Oboza <[email protected]>
  • Loading branch information
3 people authored Aug 28, 2024
1 parent 7c398f2 commit 7e4312d
Show file tree
Hide file tree
Showing 458 changed files with 1,047 additions and 1,301 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"ext-fileinfo": "*",
"ext-intl": "*",
"ext-json": "*",
"ext-libxml": "*",
"ext-mbstring": "*",
"ext-xsl": "*",
"composer/package-versions-deprecated": "^1.11",
Expand Down
330 changes: 0 additions & 330 deletions phpstan-baseline.neon

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/bundle/Core/Cache/Warmer/ProxyCacheWarmer.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ public function isOptional(): bool
return false;
}

public function warmUp($cacheDir): void
public function warmUp($cacheDir): array
{
$this->proxyGenerator->warmUp(self::PROXY_CLASSES);

return [];
}
}
2 changes: 1 addition & 1 deletion src/bundle/Core/Command/CheckURLsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
$progress->finish();

return 0;
return self::SUCCESS;
}

private function getTotalCount(): int
Expand Down
14 changes: 9 additions & 5 deletions src/bundle/Core/Command/CleanupVersionsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,21 @@ class CleanupVersionsCommand extends Command
- Run this command in production environment using <info>--env=prod</info>
EOT;
public const VERSION_DRAFT = 'draft';

public const VERSION_ARCHIVED = 'archived';
public const VERSION_PUBLISHED = 'published';
public const VERSION_ALL = 'all';

public const VERSION_STATUS = [
self::VERSION_DRAFT => VersionInfo::STATUS_DRAFT,
self::VERSION_ARCHIVED => VersionInfo::STATUS_ARCHIVED,
self::VERSION_PUBLISHED => VersionInfo::STATUS_PUBLISHED,
];

protected static $defaultName = 'ibexa:content:cleanup-versions';

protected static $defaultDescription = 'Removes unwanted content versions. Keeps the published version untouched. By default, also keeps the last archived/draft version.';

private readonly Repository $repository;

private readonly RepositoryConfigurationProviderInterface $repositoryConfigurationProvider;
Expand All @@ -62,8 +68,6 @@ protected function configure()
{
$beforeRunningHints = self::BEFORE_RUNNING_HINTS;
$this
->setName('ibexa:content:cleanup-versions')
->setDescription('Removes unwanted content versions. Keeps the published version untouched. By default, also keeps the last archived/draft version.')
->addOption(
'status',
't',
Expand Down Expand Up @@ -144,7 +148,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
if ($contentIdsCount === 0) {
$output->writeln('<info>There is no content matching the given Criteria.</info>');

return 0;
return self::SUCCESS;
}

$output->writeln(sprintf(
Expand Down Expand Up @@ -182,7 +186,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
), OutputInterface::VERBOSITY_VERBOSE);

if ($removeAll) {
$versions = array_filter($versions, static function (VersionInfo $version) {
$versions = array_filter($versions, static function (VersionInfo $version): bool {
return $version->status !== VersionInfo::STATUS_PUBLISHED;
});
}
Expand Down Expand Up @@ -225,7 +229,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$contentIdsCount
));

return 0;
return self::SUCCESS;
}

/**
Expand Down
12 changes: 7 additions & 5 deletions src/bundle/Core/Command/CopySubtreeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
*/
class CopySubtreeCommand extends Command
{
protected static $defaultName = 'ibexa:copy-subtree';

protected static $defaultDescription = 'Copies a subtree from one Location to another';

/** @var \Ibexa\Contracts\Core\Repository\LocationService */
private $locationService;

Expand Down Expand Up @@ -68,7 +72,6 @@ public function __construct(
protected function configure()
{
$this
->setName('ibexa:copy-subtree')
->addArgument(
'source-location-id',
InputArgument::REQUIRED,
Expand All @@ -85,8 +88,7 @@ protected function configure()
InputOption::VALUE_OPTIONAL,
'Ibexa username (with Role containing at least content policies: create, read)',
'admin'
)
->setDescription('Copies a subtree from one Location to another');
);
}

/**
Expand Down Expand Up @@ -150,7 +152,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
);

if (!$input->getOption('no-interaction') && !$questionHelper->ask($input, $output, $question)) {
return 0;
return self::SUCCESS;
}

$this->locationService->copySubtree(
Expand All @@ -162,7 +164,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
'<info>Finished</info>'
);

return 0;
return self::SUCCESS;
}

/**
Expand Down
7 changes: 4 additions & 3 deletions src/bundle/Core/Command/DebugConfigResolverCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

class DebugConfigResolverCommand extends Command
{
protected static $defaultName = 'ibexa:debug:config-resolver';

/** @var \Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface */
private $configResolver;

Expand All @@ -40,7 +42,6 @@ public function __construct(
*/
public function configure()
{
$this->setName('ibexa:debug:config-resolver');
$this->setAliases(['ibexa:debug:config']);
$this->setDescription('Debugs / Retrieves a parameter from the Config Resolver');
$this->addArgument(
Expand Down Expand Up @@ -96,7 +97,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
if ($input->getOption('json')) {
$output->write(json_encode($parameterData));

return 0;
return self::SUCCESS;
}

$output->writeln('<comment>SiteAccess name:</comment> ' . $this->siteAccess->name);
Expand All @@ -111,6 +112,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
)
);

return 0;
return self::SUCCESS;
}
}
14 changes: 8 additions & 6 deletions src/bundle/Core/Command/DeleteContentTranslationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
*/
class DeleteContentTranslationCommand extends Command
{
protected static $defaultName = 'ibexa:delete-content-translation';

protected static $defaultDescription = 'Deletes a translation from all versions of a Content item';

/** @var \Ibexa\Contracts\Core\Repository\Repository */
private $repository;

Expand Down Expand Up @@ -51,7 +55,6 @@ public function __construct(Repository $repository)
protected function configure()
{
$this
->setName('ibexa:delete-content-translation')
->addArgument('content-id', InputArgument::REQUIRED, 'Content Object Id')
->addArgument(
'language-code',
Expand All @@ -64,8 +67,7 @@ protected function configure()
InputOption::VALUE_OPTIONAL,
'Ibexa username (with Role containing at least content Policies: read, versionread, edit, remove, versionremove)',
'admin'
)
->setDescription('Deletes a translation from all versions of a Content item');
);
}

protected function initialize(InputInterface $input, OutputInterface $output)
Expand Down Expand Up @@ -125,7 +127,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->repository->rollback();
$this->output->writeln('Reverting and aborting.');

return 0;
return self::SUCCESS;
}

// Delete Translation
Expand All @@ -142,7 +144,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
throw $e;
}

return 0;
return self::SUCCESS;
}

/**
Expand All @@ -167,7 +169,7 @@ private function promptUserForMainLanguageChange(
// get main Translation candidates w/o Translation being removed
$mainTranslationCandidates = array_filter(
$lastVersionLanguageCodes,
static function ($versionLanguageCode) use ($languageCode) {
static function ($versionLanguageCode) use ($languageCode): bool {
return $versionLanguageCode !== $languageCode;
}
);
Expand Down
7 changes: 4 additions & 3 deletions src/bundle/Core/Command/ExpireUserPasswordsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ final class ExpireUserPasswordsCommand extends Command
{
protected static $defaultName = 'ibexa:user:expire-password';

protected static $defaultDescription = 'Expire passwords for selected users.';

public const REQUIRE_NEW_PASSWORD_VALUE = true;

public const DEFAULT_BATCH_SIZE = 50;
Expand Down Expand Up @@ -71,7 +73,6 @@ protected function configure(): void
{
$beforeRunningHints = self::BEFORE_RUNNING_HINTS;
$this
->setDescription('Expire passwords for selected users.')
->addOption(
'user-id',
'u',
Expand Down Expand Up @@ -147,7 +148,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
if ($totalCount === 0) {
$output->writeln('<info>There are no users matching given criteria</info>');

return Command::SUCCESS;
return self::SUCCESS;
}

$output->writeln(sprintf(
Expand Down Expand Up @@ -212,7 +213,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
);
}

return Command::SUCCESS;
return self::SUCCESS;
}

/**
Expand Down
11 changes: 6 additions & 5 deletions src/bundle/Core/Command/NormalizeImagesPathsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ final class NormalizeImagesPathsCommand extends Command

protected static $defaultName = 'ibexa:images:normalize-paths';

protected static $defaultDescription = 'Normalizes stored paths for images.';

/** @var \Ibexa\Core\FieldType\Image\ImageStorage\Gateway */
private $imageGateway;

Expand Down Expand Up @@ -73,7 +75,6 @@ protected function configure()
$beforeRunningHints = self::BEFORE_RUNNING_HINTS;

$this
->setDescription('Normalizes stored paths for images.')
->addOption(
self::SKIP_HASHING_COMMAND_PARAMETER,
null,
Expand Down Expand Up @@ -112,11 +113,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
if ($imagePathsToNormalizeCount === 0) {
$io->success('No paths to normalize.');

return 0;
return self::SUCCESS;
}

if (!$io->confirm('Do you want to continue?')) {
return 0;
return self::SUCCESS;
}

$io->writeln('Normalizing image paths. Please wait...');
Expand All @@ -135,7 +136,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$io->progressFinish();
$io->success('Done!');

return 0;
return self::SUCCESS;
}

/**
Expand Down Expand Up @@ -232,7 +233,7 @@ private function getFinalNormalizedPath(
$processedPaths = array_values(
array_filter(
$imagePathsToNormalize,
static function (array $data) use ($filePath) {
static function (array $data) use ($filePath): bool {
return $data['oldPath'] === $filePath;
}
)
Expand Down
17 changes: 9 additions & 8 deletions src/bundle/Core/Command/RegenerateUrlAliasesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use Symfony\Component\Console\Question\ConfirmationQuestion;

/**
* The ezplatform:urls:regenerate-aliases Symfony command implementation.
* The ibexa:urls:regenerate-aliases Symfony command implementation.
* Recreates system URL aliases for all existing Locations and cleanups corrupted URL alias nodes.
*/
class RegenerateUrlAliasesCommand extends Command
Expand All @@ -36,6 +36,8 @@ class RegenerateUrlAliasesCommand extends Command
- Manually clear HTTP cache after running this command.
EOT;

protected static $defaultName = 'ibexa:urls:regenerate-aliases';

/** @var \Ibexa\Contracts\Core\Repository\Repository */
private $repository;

Expand All @@ -61,7 +63,6 @@ protected function configure()
{
$beforeRunningHints = self::BEFORE_RUNNING_HINTS;
$this
->setName('ibexa:urls:regenerate-aliases')
->setDescription(
'Regenerates Location URL aliases (autogenerated) and cleans up custom Location ' .
'and global URL aliases stored in the Legacy Storage Engine'
Expand Down Expand Up @@ -116,7 +117,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$locationsCount = count($locationIds);
} else {
$locationsCount = $this->repository->sudo(
static function (Repository $repository) {
static function (Repository $repository): int {
return $repository->getLocationService()->getAllLocationsCount();
}
);
Expand All @@ -125,7 +126,7 @@ static function (Repository $repository) {
if ($locationsCount === 0) {
$output->writeln('<info>No location was found. Exiting.</info>');

return 0;
return self::SUCCESS;
}

if (!$input->getOption('no-interaction')) {
Expand All @@ -139,24 +140,24 @@ static function (Repository $repository) {
false
);
if (!$helper->ask($input, $output, $question)) {
return 0;
return self::SUCCESS;
}
} elseif (!$input->getOption('force')) {
return 1;
return self::FAILURE;
}

$this->regenerateSystemUrlAliases($output, $locationsCount, $locationIds, $iterationCount);

$output->writeln('<info>Cleaning up corrupted URL aliases...</info>');
$corruptedAliasesCount = $this->repository->sudo(
static function (Repository $repository) {
static function (Repository $repository): int {
return $repository->getURLAliasService()->deleteCorruptedUrlAliases();
}
);
$output->writeln("<info>Done. Deleted {$corruptedAliasesCount} entries.</info>");
$output->writeln('<comment>Make sure to clear HTTP cache.</comment>');

return 0;
return self::SUCCESS;
}

/**
Expand Down
Loading

0 comments on commit 7e4312d

Please sign in to comment.