Applied rector rules up to symfony 6.2

This commit is contained in:
Jan Böhmer 2023-05-28 01:21:05 +02:00
parent 88ea920dfb
commit a43af180a7
145 changed files with 563 additions and 889 deletions

View file

@ -40,9 +40,10 @@ use function count;
use const DIRECTORY_SEPARATOR;
#[\Symfony\Component\Console\Attribute\AsCommand('partdb:attachments:clean-unused|app:clean-attachments', 'Lists (and deletes if wanted) attachments files that are not used anymore (abandoned files).')]
class CleanAttachmentsCommand extends Command
{
protected static $defaultName = 'partdb:attachments:clean-unused|app:clean-attachments';
protected static $defaultDescription = 'Lists (and deletes if wanted) attachments files that are not used anymore (abandoned files).';
protected AttachmentManager $attachment_helper;
protected AttachmentReverseSearch $reverseSearch;
@ -60,10 +61,8 @@ class CleanAttachmentsCommand extends Command
protected function configure(): void
{
$this
->setDescription('Lists (and deletes if wanted) attachments files that are not used anymore (abandoned files).')
->setHelp('This command allows to find all files in the media folder which are not associated with an attachment anymore.'.
' These files are not needed and can eventually deleted.');
$this->setHelp('This command allows to find all files in the media folder which are not associated with an attachment anymore.'.
' These files are not needed and can eventually deleted.');
}
protected function execute(InputInterface $input, OutputInterface $output): int
@ -108,7 +107,7 @@ class CleanAttachmentsCommand extends Command
if (!$continue) {
//We are finished here, when no files should be deleted
return 0;
return \Symfony\Component\Console\Command\Command::SUCCESS;
}
//Delete the files
@ -121,7 +120,7 @@ class CleanAttachmentsCommand extends Command
$io->success('No abandoned files found.');
}
return 0;
return \Symfony\Component\Console\Command\Command::SUCCESS;
}
/**

View file

@ -16,11 +16,9 @@ use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
#[\Symfony\Component\Console\Attribute\AsCommand('partdb:backup', 'Backup the files and the database of Part-DB')]
class BackupCommand extends Command
{
protected static $defaultName = 'partdb:backup';
protected static $defaultDescription = 'Backup the files and the database of Part-DB';
private string $project_dir;
private EntityManagerInterface $entityManager;

View file

@ -27,9 +27,10 @@ use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface;
#[\Symfony\Component\Console\Attribute\AsCommand('partdb:check-requirements', 'Checks if the requirements Part-DB needs or recommends are fulfilled.')]
class CheckRequirementsCommand extends Command
{
protected static $defaultName = 'partdb:check-requirements';
protected static $defaultDescription = 'Checks if the requirements Part-DB needs or recommends are fulfilled.';
protected ContainerBagInterface $params;
@ -41,9 +42,7 @@ class CheckRequirementsCommand extends Command
protected function configure(): void
{
$this
->setDescription('Checks if the requirements Part-DB needs or recommends are fulfilled.')
->addOption('only_issues', 'i', InputOption::VALUE_NONE, 'Only show issues, not success messages.')
$this->addOption('only_issues', 'i', InputOption::VALUE_NONE, 'Only show issues, not success messages.')
;
}

View file

@ -35,9 +35,10 @@ use Symfony\Component\Console\Style\SymfonyStyle;
use function count;
use function strlen;
#[\Symfony\Component\Console\Attribute\AsCommand('partdb:currencies:update-exchange-rates|partdb:update-exchange-rates|app:update-exchange-rates', 'Updates the currency exchange rates.')]
class UpdateExchangeRatesCommand extends Command
{
protected static $defaultName = 'partdb:currencies:update-exchange-rates|partdb:update-exchange-rates|app:update-exchange-rates';
protected static $defaultDescription = 'Updates the currency exchange rates.';
protected string $base_current;
protected EntityManagerInterface $em;
@ -56,9 +57,7 @@ class UpdateExchangeRatesCommand extends Command
protected function configure(): void
{
$this
->setDescription('Updates the currency exchange rates.')
->addArgument('iso_code', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, 'The ISO Codes of the currencies that should be updated.');
$this->addArgument('iso_code', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, 'The ISO Codes of the currencies that should be updated.');
}
protected function execute(InputInterface $input, OutputInterface $output): int
@ -69,7 +68,7 @@ class UpdateExchangeRatesCommand extends Command
if (3 !== strlen($this->base_current)) {
$io->error('Chosen Base current is not valid. Check your settings!');
return 1;
return \Symfony\Component\Console\Command\Command::FAILURE;
}
$io->note('Update currency exchange rates with base currency: '.$this->base_current);
@ -106,6 +105,6 @@ class UpdateExchangeRatesCommand extends Command
$io->success(sprintf('%d (of %d) currency exchange rates were updated.', $success_counter, count($candidates)));
return 0;
return \Symfony\Component\Console\Command\Command::SUCCESS;
}
}

View file

@ -36,9 +36,10 @@ use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Contracts\Translation\TranslatorInterface;
#[\Symfony\Component\Console\Attribute\AsCommand('partdb:logs:show|app:show-logs', 'List the last event log entries.')]
class ShowEventLogCommand extends Command
{
protected static $defaultName = 'partdb:logs:show|app:show-logs';
protected static $defaultDescription = 'List the last event log entries.';
protected EntityManagerInterface $entityManager;
protected TranslatorInterface $translator;
protected ElementTypeNameGenerator $elementTypeNameGenerator;
@ -74,7 +75,7 @@ class ShowEventLogCommand extends Command
if ($page > $max_page && $max_page > 0) {
$io->error("There is no page ${page}! The maximum page is ${max_page}.");
return 1;
return \Symfony\Component\Console\Command\Command::FAILURE;
}
$io->note("There are a total of ${total_count} log entries in the DB.");
@ -84,21 +85,19 @@ class ShowEventLogCommand extends Command
$this->showPage($output, $desc, $limit, $page, $max_page, $showExtra);
if ($onePage) {
return 0;
return \Symfony\Component\Console\Command\Command::SUCCESS;
}
$continue = $io->confirm('Do you want to show the next page?');
++$page;
}
return 0;
return \Symfony\Component\Console\Command\Command::SUCCESS;
}
protected function configure(): void
{
$this
->setDescription('List the last event log entries.')
->addOption('count', 'c', InputOption::VALUE_REQUIRED, 'How many log entries should be shown per page.', 50)
$this->addOption('count', 'c', InputOption::VALUE_REQUIRED, 'How many log entries should be shown per page.', 50)
->addOption('oldest_first', null, InputOption::VALUE_NONE, 'Show older entries first.')
->addOption('page', 'p', InputOption::VALUE_REQUIRED, 'Which page should be shown?', 1)
->addOption('onePage', null, InputOption::VALUE_NONE, 'Show only one page (dont ask to go to next).')

View file

@ -47,6 +47,7 @@ use function count;
/**
* This command converts the BBCode used by old Part-DB versions (<1.0), to the current used Markdown format.
*/
#[\Symfony\Component\Console\Attribute\AsCommand('partdb:migrations:convert-bbcode|app:convert-bbcode', 'Converts BBCode used in old Part-DB versions to newly used Markdown')]
class ConvertBBCodeCommand extends Command
{
/**
@ -58,7 +59,7 @@ class ConvertBBCodeCommand extends Command
*/
protected const BBCODE_REGEX = '/\\[.+\\].*\\[\\/.+\\]/';
protected static $defaultName = 'partdb:migrations:convert-bbcode|app:convert-bbcode';
protected static $defaultDescription = 'Converts BBCode used in old Part-DB versions to newly used Markdown';
protected EntityManagerInterface $em;
protected PropertyAccessorInterface $propertyAccessor;
@ -76,9 +77,7 @@ class ConvertBBCodeCommand extends Command
protected function configure(): void
{
$this
->setDescription('Converts BBCode used in old Part-DB versions to newly used Markdown')
->setHelp('Older versions of Part-DB (<1.0) used BBCode for rich text formatting.
$this->setHelp('Older versions of Part-DB (<1.0) used BBCode for rich text formatting.
Part-DB now uses Markdown which offers more features but is incompatible with BBCode.
When you upgrade from an pre 1.0 version you have to run this command to convert your comment fields');
@ -168,6 +167,6 @@ class ConvertBBCodeCommand extends Command
$io->success('Changes saved to DB successfully!');
}
return 0;
return \Symfony\Component\Console\Command\Command::SUCCESS;
}
}

View file

@ -33,10 +33,11 @@ use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
#[\Symfony\Component\Console\Attribute\AsCommand('partdb:migrations:import-partkeepr', 'Import a PartKeepr database XML dump into Part-DB')]
class ImportPartKeeprCommand extends Command
{
protected static $defaultName = 'partdb:migrations:import-partkeepr';
protected static $defaultDescription = 'Import a PartKeepr database XML dump into Part-DB';
protected EntityManagerInterface $em;
protected MySQLDumpXMLConverter $xml_converter;
@ -60,7 +61,6 @@ class ImportPartKeeprCommand extends Command
protected function configure()
{
$this->setDescription('Import a PartKeepr database XML dump into Part-DB');
$this->setHelp('This command allows you to import a PartKeepr database exported by mysqldump as XML file into Part-DB');
$this->addArgument('file', InputArgument::REQUIRED, 'The file to which should be imported.');
@ -100,7 +100,7 @@ class ImportPartKeeprCommand extends Command
if (!$this->importHelper->checkVersion($data)) {
$db_version = $this->importHelper->getDatabaseSchemaVersion($data);
$io->error('The version of the imported database is not supported! (Version: '.$db_version.')');
return 1;
return \Symfony\Component\Console\Command\Command::FAILURE;
}
//Import the mandatory data
@ -118,7 +118,7 @@ class ImportPartKeeprCommand extends Command
$io->success('Imported '.$count.' users.');
}
return 0;
return \Symfony\Component\Console\Command\Command::SUCCESS;
}
private function doImport(SymfonyStyle $io, array $data): void

View file

@ -30,9 +30,10 @@ use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
#[\Symfony\Component\Console\Attribute\AsCommand('partdb:user:convert-to-saml-user|partdb:users:convert-to-saml-user', 'Converts a local user to a SAML user (and vice versa)')]
class ConvertToSAMLUserCommand extends Command
{
protected static $defaultName = 'partdb:user:convert-to-saml-user|partdb:users:convert-to-saml-user';
protected static $defaultDescription = 'Converts a local user to a SAML user (and vice versa)';
protected EntityManagerInterface $entityManager;
protected bool $saml_enabled;
@ -46,9 +47,7 @@ class ConvertToSAMLUserCommand extends Command
protected function configure(): void
{
$this
->setDescription('Converts a local user to a SAML user (and vice versa)')
->setHelp('This converts a local user, which can login via the login form, to a SAML user, which can only login via SAML. This is useful if you want to migrate from a local user system to a SAML user system.')
$this->setHelp('This converts a local user, which can login via the login form, to a SAML user, which can only login via SAML. This is useful if you want to migrate from a local user system to a SAML user system.')
->addArgument('user', InputArgument::REQUIRED, 'The username (or email) of the user')
->addOption('to-local', null, InputOption::VALUE_NONE, 'Converts a SAML user to a local user')
;
@ -70,7 +69,7 @@ class ConvertToSAMLUserCommand extends Command
if (!$user) {
$io->error('User not found!');
return 1;
return \Symfony\Component\Console\Command\Command::FAILURE;
}
$io->info('User found: '.$user->getFullName(true) . ': '.$user->getEmail().' [ID: ' . $user->getID() . ']');

View file

@ -34,9 +34,10 @@ use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
#[\Symfony\Component\Console\Attribute\AsCommand('partdb:users:set-password|app:set-password|users:set-password|partdb:user:set-password', 'Sets the password of a user')]
class SetPasswordCommand extends Command
{
protected static $defaultName = 'partdb:users:set-password|app:set-password|users:set-password|partdb:user:set-password';
protected static $defaultDescription = 'Sets the password of a user';
protected EntityManagerInterface $entityManager;
protected UserPasswordHasherInterface $encoder;
@ -53,9 +54,7 @@ class SetPasswordCommand extends Command
protected function configure(): void
{
$this
->setDescription('Sets the password of a user')
->setHelp('This password allows you to set the password of a user, without knowing the old password.')
$this->setHelp('This password allows you to set the password of a user, without knowing the old password.')
->addArgument('user', InputArgument::REQUIRED, 'The username or email of the user')
;
}
@ -70,14 +69,14 @@ class SetPasswordCommand extends Command
if (!$user) {
$io->error(sprintf('No user with the given username %s found in the database!', $user_name));
return 1;
return \Symfony\Component\Console\Command\Command::FAILURE;
}
$io->note('User found!');
if ($user->isSamlUser()) {
$io->error('This user is a SAML user, so you can not change the password!');
return 1;
return \Symfony\Component\Console\Command\Command::FAILURE;
}
$proceed = $io->confirm(
@ -85,7 +84,7 @@ class SetPasswordCommand extends Command
$user->getFullName(true), $user->getID()));
if (!$proceed) {
return 1;
return \Symfony\Component\Console\Command\Command::FAILURE;
}
$success = false;
@ -116,6 +115,6 @@ class SetPasswordCommand extends Command
$security_event = new SecurityEvent($user);
$this->eventDispatcher->dispatch($security_event, SecurityEvents::PASSWORD_CHANGED);
return 0;
return \Symfony\Component\Console\Command\Command::SUCCESS;
}
}

View file

@ -31,11 +31,9 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
#[\Symfony\Component\Console\Attribute\AsCommand('partdb:users:upgrade-permissions-schema', '(Manually) upgrades the permissions schema of all users to the latest version.')]
final class UpgradePermissionsSchemaCommand extends Command
{
protected static $defaultName = 'partdb:users:upgrade-permissions-schema';
protected static $defaultDescription = '(Manually) upgrades the permissions schema of all users to the latest version.';
private PermissionSchemaUpdater $permissionSchemaUpdater;
private EntityManagerInterface $em;
private EventCommentHelper $eventCommentHelper;
@ -84,7 +82,7 @@ final class UpgradePermissionsSchemaCommand extends Command
if (empty($groups_to_upgrade) && empty($users_to_upgrade)) {
$io->success('All users and group permissions schemas are up-to-date. No update needed.');
return 0;
return \Symfony\Component\Console\Command\Command::SUCCESS;
}
//List all users and groups that need an update
@ -100,7 +98,7 @@ final class UpgradePermissionsSchemaCommand extends Command
if(!$io->confirm('Continue with the update?', false)) {
$io->warning('Update aborted.');
return 0;
return \Symfony\Component\Console\Command\Command::SUCCESS;
}
//Update all users and groups

View file

@ -29,9 +29,10 @@ use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
#[\Symfony\Component\Console\Attribute\AsCommand('partdb:users:enable|partdb:user:enable', 'Enables/Disable the login of one or more users')]
class UserEnableCommand extends Command
{
protected static $defaultName = 'partdb:users:enable|partdb:user:enable';
protected static $defaultDescription = 'Enables/Disable the login of one or more users';
protected EntityManagerInterface $entityManager;
@ -44,9 +45,7 @@ class UserEnableCommand extends Command
protected function configure(): void
{
$this
->setDescription('Enables/Disable the login of one or more users')
->setHelp('This allows you to allow or prevent the login of certain user. Use the --disable option to disable the login for the given users')
$this->setHelp('This allows you to allow or prevent the login of certain user. Use the --disable option to disable the login for the given users')
->addArgument('users', InputArgument::IS_ARRAY, 'The usernames of the users to use')
->addOption('all', 'a', InputOption::VALUE_NONE, 'Enable/Disable all users')
->addOption('disable', 'd', InputOption::VALUE_NONE, 'Disable the login of the given users')

View file

@ -28,9 +28,10 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
#[\Symfony\Component\Console\Attribute\AsCommand('partdb:users:list|users:list', 'Lists all users')]
class UserListCommand extends Command
{
protected static $defaultName = 'partdb:users:list|users:list';
protected static $defaultDescription = 'Lists all users';
protected EntityManagerInterface $entityManager;
@ -43,9 +44,7 @@ class UserListCommand extends Command
protected function configure(): void
{
$this
->setDescription('Lists all users')
->setHelp('This command lists all users in the database.')
$this->setHelp('This command lists all users in the database.')
->addOption('local', 'l', null, 'Only list local users')
->addOption('saml', 's', null, 'Only list SAML users')
;

View file

@ -34,11 +34,9 @@ use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Contracts\Translation\TranslatorInterface;
#[\Symfony\Component\Console\Attribute\AsCommand('partdb:users:permissions|partdb:user:permissions', 'View and edit the permissions of a given user')]
class UsersPermissionsCommand extends Command
{
protected static $defaultName = 'partdb:users:permissions|partdb:user:permissions';
protected static $defaultDescription = 'View and edit the permissions of a given user';
protected EntityManagerInterface $entityManager;
protected UserRepository $userRepository;
protected PermissionManager $permissionResolver;

View file

@ -27,9 +27,10 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
#[\Symfony\Component\Console\Attribute\AsCommand('partdb:version|app:version', 'Shows the currently installed version of Part-DB.')]
class VersionCommand extends Command
{
protected static $defaultName = 'partdb:version|app:version';
protected static $defaultDescription = 'Shows the currently installed version of Part-DB.';
protected VersionManagerInterface $versionManager;
protected GitVersionInfo $gitVersionInfo;
@ -43,9 +44,6 @@ class VersionCommand extends Command
protected function configure(): void
{
$this
->setDescription('Shows the currently installed version of Part-DB.')
;
}
protected function execute(InputInterface $input, OutputInterface $output): int
@ -66,6 +64,6 @@ class VersionCommand extends Command
$io->info('OS: '. php_uname());
$io->info('PHP extension: '. implode(', ', get_loaded_extensions()));
return 0;
return \Symfony\Component\Console\Command\Command::SUCCESS;
}
}