Applied rector with PHP8.1 migration rules

This commit is contained in:
Jan Böhmer 2023-06-11 14:15:46 +02:00
parent dc6a67c2f0
commit 7ee01d9a05
303 changed files with 1228 additions and 3465 deletions

View file

@ -43,16 +43,10 @@ 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 AttachmentManager $attachment_helper;
protected AttachmentReverseSearch $reverseSearch;
protected MimeTypes $mimeTypeGuesser;
protected AttachmentPathResolver $pathResolver;
public function __construct(AttachmentManager $attachmentHelper, AttachmentReverseSearch $reverseSearch, AttachmentPathResolver $pathResolver)
public function __construct(protected AttachmentManager $attachment_helper, protected AttachmentReverseSearch $reverseSearch, protected AttachmentPathResolver $pathResolver)
{
$this->attachment_helper = $attachmentHelper;
$this->pathResolver = $pathResolver;
$this->reverseSearch = $reverseSearch;
$this->mimeTypeGuesser = new MimeTypes();
parent::__construct();
}
@ -88,7 +82,7 @@ class CleanAttachmentsCommand extends Command
foreach ($finder as $file) {
//If not attachment object uses this file, print it
if (0 === count($this->reverseSearch->findAttachmentsByFile($file))) {
if ([] === $this->reverseSearch->findAttachmentsByFile($file)) {
$file_list[] = $file;
$table->addRow([
$fs->makePathRelative($file->getPathname(), $mediaPath),
@ -98,7 +92,7 @@ class CleanAttachmentsCommand extends Command
}
}
if (count($file_list) > 0) {
if ($file_list !== []) {
$table->render();
$continue = $io->confirm(sprintf('Found %d abandoned files. Do you want to delete them? This can not be undone!', count($file_list)), false);

View file

@ -19,14 +19,8 @@ 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
{
private string $project_dir;
private EntityManagerInterface $entityManager;
public function __construct(string $project_dir, EntityManagerInterface $entityManager)
public function __construct(private readonly string $project_dir, private readonly EntityManagerInterface $entityManager)
{
$this->project_dir = $project_dir;
$this->entityManager = $entityManager;
parent::__construct();
}
@ -69,13 +63,10 @@ class BackupCommand extends Command
$io->info('Backup Part-DB to '.$output_filepath);
//Check if the file already exists
if (file_exists($output_filepath)) {
//Then ask the user, if he wants to overwrite the file
if (!$io->confirm('The file '.realpath($output_filepath).' already exists. Do you want to overwrite it?', false)) {
$io->error('Backup aborted!');
return Command::FAILURE;
}
//Then ask the user, if he wants to overwrite the file
if (file_exists($output_filepath) && !$io->confirm('The file '.realpath($output_filepath).' already exists. Do you want to overwrite it?', false)) {
$io->error('Backup aborted!');
return Command::FAILURE;
}
$io->note('Starting backup...');
@ -113,8 +104,6 @@ class BackupCommand extends Command
/**
* Constructs the MySQL PDO DSN.
* Taken from https://github.com/doctrine/dbal/blob/3.5.x/src/Driver/PDO/MySQL/Driver.php
*
* @param array $params
*/
private function configureDumper(array $params, DbDumper $dumper): void
{

View file

@ -30,11 +30,8 @@ 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 ContainerBagInterface $params;
public function __construct(ContainerBagInterface $params)
public function __construct(protected ContainerBagInterface $params)
{
$this->params = $params;
parent::__construct();
}
@ -66,40 +63,48 @@ class CheckRequirementsCommand extends Command
protected function checkPHP(SymfonyStyle $io, $only_issues = false): void
{
//Check PHP versions
$io->isVerbose() && $io->comment('Checking PHP version...');
if ($io->isVerbose()) {
$io->comment('Checking PHP version...');
}
//We recommend PHP 8.2, but 8.1 is the minimum
if (PHP_VERSION_ID < 80200) {
$io->warning('You are using PHP '. PHP_VERSION .'. This will work, but a newer version is recommended.');
} else {
!$only_issues && $io->success('PHP version is sufficient.');
} elseif (!$only_issues) {
$io->success('PHP version is sufficient.');
}
//Check if opcache is enabled
$io->isVerbose() && $io->comment('Checking Opcache...');
if ($io->isVerbose()) {
$io->comment('Checking Opcache...');
}
$opcache_enabled = ini_get('opcache.enable') === '1';
if (!$opcache_enabled) {
$io->warning('Opcache is not enabled. This will work, but performance will be better with opcache enabled. Set opcache.enable=1 in your php.ini to enable it');
} else {
!$only_issues && $io->success('Opcache is enabled.');
} elseif (!$only_issues) {
$io->success('Opcache is enabled.');
}
//Check if opcache is configured correctly
$io->isVerbose() && $io->comment('Checking Opcache configuration...');
if ($io->isVerbose()) {
$io->comment('Checking Opcache configuration...');
}
if ($opcache_enabled && (ini_get('opcache.memory_consumption') < 256 || ini_get('opcache.max_accelerated_files') < 20000)) {
$io->warning('Opcache configuration can be improved. See https://symfony.com/doc/current/performance.html for more info.');
} else {
!$only_issues && $io->success('Opcache configuration is already performance optimized.');
} elseif (!$only_issues) {
$io->success('Opcache configuration is already performance optimized.');
}
}
protected function checkPartDBConfig(SymfonyStyle $io, $only_issues = false): void
{
//Check if APP_ENV is set to prod
$io->isVerbose() && $io->comment('Checking debug mode...');
if($this->params->get('kernel.debug')) {
if ($io->isVerbose()) {
$io->comment('Checking debug mode...');
}
if ($this->params->get('kernel.debug')) {
$io->warning('You have activated debug mode, this is will leak informations in a production environment.');
} else {
!$only_issues && $io->success('Debug mode disabled.');
} elseif (!$only_issues) {
$io->success('Debug mode disabled.');
}
}
@ -108,61 +113,71 @@ class CheckRequirementsCommand extends Command
{
//Get all installed PHP extensions
$extensions = get_loaded_extensions();
$io->isVerbose() && $io->comment('Your PHP installation has '. count($extensions) .' extensions installed: '. implode(', ', $extensions));
if ($io->isVerbose()) {
$io->comment('Your PHP installation has '. count($extensions) .' extensions installed: '. implode(', ', $extensions));
}
$db_drivers_count = 0;
if(!in_array('pdo_mysql', $extensions)) {
$io->error('pdo_mysql is not installed. You will not be able to use MySQL databases.');
} else {
!$only_issues && $io->success('PHP extension pdo_mysql is installed.');
if (!$only_issues) {
$io->success('PHP extension pdo_mysql is installed.');
}
$db_drivers_count++;
}
if(!in_array('pdo_sqlite', $extensions)) {
$io->error('pdo_sqlite is not installed. You will not be able to use SQLite. databases');
} else {
!$only_issues && $io->success('PHP extension pdo_sqlite is installed.');
if (!$only_issues) {
$io->success('PHP extension pdo_sqlite is installed.');
}
$db_drivers_count++;
}
$io->isVerbose() && $io->comment('You have '. $db_drivers_count .' database drivers installed.');
if ($io->isVerbose()) {
$io->comment('You have '. $db_drivers_count .' database drivers installed.');
}
if ($db_drivers_count === 0) {
$io->error('You have no database drivers installed. You have to install at least one database driver!');
}
if(!in_array('curl', $extensions)) {
if (!in_array('curl', $extensions)) {
$io->warning('curl extension is not installed. Install curl extension for better performance');
} else {
!$only_issues && $io->success('PHP extension curl is installed.');
} elseif (!$only_issues) {
$io->success('PHP extension curl is installed.');
}
$gd_installed = in_array('gd', $extensions);
if(!$gd_installed) {
if (!$gd_installed) {
$io->error('GD is not installed. GD is required for image processing.');
} else {
!$only_issues && $io->success('PHP extension GD is installed.');
} elseif (!$only_issues) {
$io->success('PHP extension GD is installed.');
}
//Check if GD has jpeg support
$io->isVerbose() && $io->comment('Checking if GD has jpeg support...');
if ($io->isVerbose()) {
$io->comment('Checking if GD has jpeg support...');
}
if ($gd_installed) {
$gd_info = gd_info();
if($gd_info['JPEG Support'] === false) {
if ($gd_info['JPEG Support'] === false) {
$io->warning('Your GD does not have jpeg support. You will not be able to generate thumbnails of jpeg images.');
} else {
!$only_issues && $io->success('GD has jpeg support.');
} elseif (!$only_issues) {
$io->success('GD has jpeg support.');
}
if($gd_info['PNG Support'] === false) {
if ($gd_info['PNG Support'] === false) {
$io->warning('Your GD does not have png support. You will not be able to generate thumbnails of png images.');
} else {
!$only_issues && $io->success('GD has png support.');
} elseif (!$only_issues) {
$io->success('GD has png support.');
}
if($gd_info['WebP Support'] === false) {
if ($gd_info['WebP Support'] === false) {
$io->warning('Your GD does not have WebP support. You will not be able to generate thumbnails of WebP images.');
} else {
!$only_issues && $io->success('GD has WebP support.');
} elseif (!$only_issues) {
$io->success('GD has WebP support.');
}
}

View file

@ -38,18 +38,8 @@ 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 string $base_current;
protected EntityManagerInterface $em;
protected ExchangeRateUpdater $exchangeRateUpdater;
public function __construct(string $base_current, EntityManagerInterface $entityManager, ExchangeRateUpdater $exchangeRateUpdater)
public function __construct(protected string $base_current, protected EntityManagerInterface $em, protected ExchangeRateUpdater $exchangeRateUpdater)
{
//$this->swap = $swap;
$this->base_current = $base_current;
$this->em = $entityManager;
$this->exchangeRateUpdater = $exchangeRateUpdater;
parent::__construct();
}
@ -75,11 +65,7 @@ class UpdateExchangeRatesCommand extends Command
$iso_code = $input->getArgument('iso_code');
$repo = $this->em->getRepository(Currency::class);
if (!empty($iso_code)) {
$candidates = $repo->findBy(['iso_code' => $iso_code]);
} else {
$candidates = $repo->findAll();
}
$candidates = empty($iso_code) ? $repo->findAll() : $repo->findBy(['iso_code' => $iso_code]);
$success_counter = 0;

View file

@ -39,20 +39,11 @@ 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 EntityManagerInterface $entityManager;
protected TranslatorInterface $translator;
protected ElementTypeNameGenerator $elementTypeNameGenerator;
protected LogEntryRepository $repo;
protected LogEntryExtraFormatter $formatter;
public function __construct(EntityManagerInterface $entityManager,
TranslatorInterface $translator, ElementTypeNameGenerator $elementTypeNameGenerator, LogEntryExtraFormatter $formatter)
public function __construct(protected EntityManagerInterface $entityManager,
protected TranslatorInterface $translator, protected ElementTypeNameGenerator $elementTypeNameGenerator, protected LogEntryExtraFormatter $formatter)
{
$this->entityManager = $entityManager;
$this->translator = $translator;
$this->elementTypeNameGenerator = $elementTypeNameGenerator;
$this->formatter = $formatter;
$this->repo = $this->entityManager->getRepository(AbstractLogEntry::class);
parent::__construct();
}
@ -145,14 +136,12 @@ class ShowEventLogCommand extends Command
$target_class = $this->elementTypeNameGenerator->getLocalizedTypeLabel($entry->getTargetClass());
}
if ($entry->getUser()) {
if ($entry->getUser() instanceof \App\Entity\UserSystem\User) {
$user = $entry->getUser()->getFullName(true);
} elseif ($entry->isCLIEntry()) {
$user = $entry->getCLIUsername() . ' [CLI]';
} else {
if ($entry->isCLIEntry()) {
$user = $entry->getCLIUsername() . ' [CLI]';
} else {
$user = $entry->getUsername() . ' [deleted]';
}
$user = $entry->getUsername() . ' [deleted]';
}
$row = [

View file

@ -58,16 +58,10 @@ class ConvertBBCodeCommand extends Command
* @var string The regex (performed in PHP) used to check if a property really contains BBCODE
*/
protected const BBCODE_REGEX = '/\\[.+\\].*\\[\\/.+\\]/';
protected EntityManagerInterface $em;
protected PropertyAccessorInterface $propertyAccessor;
protected BBCodeToMarkdownConverter $converter;
public function __construct(EntityManagerInterface $entityManager, PropertyAccessorInterface $propertyAccessor)
public function __construct(protected EntityManagerInterface $em, protected PropertyAccessorInterface $propertyAccessor)
{
$this->em = $entityManager;
$this->propertyAccessor = $propertyAccessor;
$this->converter = new BBCodeToMarkdownConverter();
parent::__construct();
@ -126,25 +120,25 @@ class ConvertBBCodeCommand extends Command
//Fetch resulting classes
$results = $qb->getQuery()->getResult();
$io->note(sprintf('Found %d entities, that need to be converted!', count($results)));
$io->note(sprintf('Found %d entities, that need to be converted!', is_countable($results) ? count($results) : 0));
//In verbose mode print the names of the entities
foreach ($results as $result) {
/** @var AbstractNamedDBElement $result */
$io->writeln(
'Convert entity: '.$result->getName().' ('.get_class($result).': '.$result->getID().')',
'Convert entity: '.$result->getName().' ('.$result::class.': '.$result->getID().')',
OutputInterface::VERBOSITY_VERBOSE
);
foreach ($properties as $property) {
//Retrieve bbcode from entity
$bbcode = $this->propertyAccessor->getValue($result, $property);
//Check if the current property really contains BBCode
if (!preg_match(static::BBCODE_REGEX, $bbcode)) {
if (!preg_match(static::BBCODE_REGEX, (string) $bbcode)) {
continue;
}
$io->writeln(
'BBCode (old): '
.str_replace('\n', ' ', substr($bbcode, 0, 255)),
.str_replace('\n', ' ', substr((string) $bbcode, 0, 255)),
OutputInterface::VERBOSITY_VERY_VERBOSE
);
$markdown = $this->converter->convert($bbcode);

View file

@ -37,24 +37,11 @@ use Symfony\Component\Console\Style\SymfonyStyle;
class ImportPartKeeprCommand extends Command
{
protected EntityManagerInterface $em;
protected MySQLDumpXMLConverter $xml_converter;
protected PKDatastructureImporter $datastructureImporter;
protected PKImportHelper $importHelper;
protected PKPartImporter $partImporter;
protected PKOptionalImporter $optionalImporter;
public function __construct(EntityManagerInterface $em, MySQLDumpXMLConverter $xml_converter,
PKDatastructureImporter $datastructureImporter, PKPartImporter $partImporter, PKImportHelper $importHelper,
PKOptionalImporter $optionalImporter)
public function __construct(protected EntityManagerInterface $em, protected MySQLDumpXMLConverter $xml_converter,
protected PKDatastructureImporter $datastructureImporter, protected PKPartImporter $partImporter, protected PKImportHelper $importHelper,
protected PKOptionalImporter $optionalImporter)
{
parent::__construct(self::$defaultName);
$this->em = $em;
$this->datastructureImporter = $datastructureImporter;
$this->importHelper = $importHelper;
$this->partImporter = $partImporter;
$this->xml_converter = $xml_converter;
$this->optionalImporter = $optionalImporter;
}
protected function configure()

View file

@ -33,14 +33,9 @@ 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 EntityManagerInterface $entityManager;
protected bool $saml_enabled;
public function __construct(EntityManagerInterface $entityManager, bool $saml_enabled)
public function __construct(protected EntityManagerInterface $entityManager, protected bool $saml_enabled)
{
parent::__construct();
$this->entityManager = $entityManager;
$this->saml_enabled = $saml_enabled;
}
protected function configure(): void

View file

@ -37,16 +37,8 @@ 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 EntityManagerInterface $entityManager;
protected UserPasswordHasherInterface $encoder;
protected EventDispatcherInterface $eventDispatcher;
public function __construct(EntityManagerInterface $entityManager, UserPasswordHasherInterface $passwordEncoder, EventDispatcherInterface $eventDispatcher)
public function __construct(protected EntityManagerInterface $entityManager, protected UserPasswordHasherInterface $encoder, protected EventDispatcherInterface $eventDispatcher)
{
$this->entityManager = $entityManager;
$this->encoder = $passwordEncoder;
$this->eventDispatcher = $eventDispatcher;
parent::__construct();
}
@ -64,7 +56,7 @@ class SetPasswordCommand extends Command
$user = $this->entityManager->getRepository(User::class)->findByEmailOrName($user_name);
if (!$user) {
if (!$user instanceof \App\Entity\UserSystem\User) {
$io->error(sprintf('No user with the given username %s found in the database!', $user_name));
return \Symfony\Component\Console\Command\Command::FAILURE;

View file

@ -34,17 +34,9 @@ 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
{
private PermissionSchemaUpdater $permissionSchemaUpdater;
private EntityManagerInterface $em;
private EventCommentHelper $eventCommentHelper;
public function __construct(PermissionSchemaUpdater $permissionSchemaUpdater, EntityManagerInterface $entityManager, EventCommentHelper $eventCommentHelper)
public function __construct(private readonly PermissionSchemaUpdater $permissionSchemaUpdater, private readonly EntityManagerInterface $em, private readonly EventCommentHelper $eventCommentHelper)
{
parent::__construct(self::$defaultName);
$this->permissionSchemaUpdater = $permissionSchemaUpdater;
$this->eventCommentHelper = $eventCommentHelper;
$this->em = $entityManager;
}
protected function configure(): void
@ -79,7 +71,7 @@ final class UpgradePermissionsSchemaCommand extends Command
}
$io->info('Found '. count($groups_to_upgrade) .' groups and '. count($users_to_upgrade) .' users that need an update.');
if (empty($groups_to_upgrade) && empty($users_to_upgrade)) {
if ($groups_to_upgrade === [] && $users_to_upgrade === []) {
$io->success('All users and group permissions schemas are up-to-date. No update needed.');
return \Symfony\Component\Console\Command\Command::SUCCESS;
@ -87,14 +79,10 @@ final class UpgradePermissionsSchemaCommand extends Command
//List all users and groups that need an update
$io->section('Groups that need an update:');
$io->listing(array_map(static function (Group $group) {
return $group->getName() . ' (ID: '. $group->getID() .', Current version: ' . $group->getPermissions()->getSchemaVersion() . ')';
}, $groups_to_upgrade));
$io->listing(array_map(static fn(Group $group): string => $group->getName() . ' (ID: '. $group->getID() .', Current version: ' . $group->getPermissions()->getSchemaVersion() . ')', $groups_to_upgrade));
$io->section('Users that need an update:');
$io->listing(array_map(static function (User $user) {
return $user->getUsername() . ' (ID: '. $user->getID() .', Current version: ' . $user->getPermissions()->getSchemaVersion() . ')';
}, $users_to_upgrade));
$io->listing(array_map(static fn(User $user): string => $user->getUsername() . ' (ID: '. $user->getID() .', Current version: ' . $user->getPermissions()->getSchemaVersion() . ')', $users_to_upgrade));
if(!$io->confirm('Continue with the update?', false)) {
$io->warning('Update aborted.');

View file

@ -32,12 +32,8 @@ 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 EntityManagerInterface $entityManager;
public function __construct(EntityManagerInterface $entityManager, string $name = null)
public function __construct(protected EntityManagerInterface $entityManager, string $name = null)
{
$this->entityManager = $entityManager;
parent::__construct($name);
}
@ -70,7 +66,7 @@ class UserEnableCommand extends Command
} else { //Otherwise, fetch the users from DB
foreach ($usernames as $username) {
$user = $repo->findByEmailOrName($username);
if ($user === null) {
if (!$user instanceof \App\Entity\UserSystem\User) {
$io->error('No user found with username: '.$username);
return self::FAILURE;
}
@ -84,9 +80,7 @@ class UserEnableCommand extends Command
$io->note('The following users will be enabled:');
}
$io->table(['Username', 'Enabled/Disabled'],
array_map(static function(User $user) {
return [$user->getFullName(true), $user->isDisabled() ? 'Disabled' : 'Enabled'];
}, $users));
array_map(static fn(User $user) => [$user->getFullName(true), $user->isDisabled() ? 'Disabled' : 'Enabled'], $users));
if(!$io->confirm('Do you want to continue?')) {
$io->warning('Aborting!');

View file

@ -31,12 +31,8 @@ use Symfony\Component\Console\Style\SymfonyStyle;
#[\Symfony\Component\Console\Attribute\AsCommand('partdb:users:list|users:list', 'Lists all users')]
class UserListCommand extends Command
{
protected EntityManagerInterface $entityManager;
public function __construct(EntityManagerInterface $entityManager)
public function __construct(protected EntityManagerInterface $entityManager)
{
$this->entityManager = $entityManager;
parent::__construct();
}
@ -83,7 +79,7 @@ class UserListCommand extends Command
$user->getUsername(),
$user->getFullName(),
$user->getEmail(),
$user->getGroup() !== null ? $user->getGroup()->getName() . ' (ID: ' . $user->getGroup()->getID() . ')' : 'No group',
$user->getGroup() instanceof \App\Entity\UserSystem\Group ? $user->getGroup()->getName() . ' (ID: ' . $user->getGroup()->getID() . ')' : 'No group',
$user->isDisabled() ? 'Yes' : 'No',
$user->isSAMLUser() ? 'SAML' : 'Local',
]);

View file

@ -37,17 +37,11 @@ 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 EntityManagerInterface $entityManager;
protected UserRepository $userRepository;
protected PermissionManager $permissionResolver;
protected TranslatorInterface $translator;
public function __construct(EntityManagerInterface $entityManager, PermissionManager $permissionResolver, TranslatorInterface $translator)
public function __construct(protected EntityManagerInterface $entityManager, protected PermissionManager $permissionResolver, protected TranslatorInterface $translator)
{
$this->entityManager = $entityManager;
$this->userRepository = $entityManager->getRepository(User::class);
$this->permissionResolver = $permissionResolver;
$this->translator = $translator;
parent::__construct(self::$defaultName);
}
@ -71,7 +65,7 @@ class UsersPermissionsCommand extends Command
//Find user
$io->note('Finding user with username: ' . $username);
$user = $this->userRepository->findByEmailOrName($username);
if ($user === null) {
if (!$user instanceof \App\Entity\UserSystem\User) {
$io->error('No user found with username: ' . $username);
return Command::FAILURE;
}
@ -100,7 +94,7 @@ class UsersPermissionsCommand extends Command
$new_value_str = $io->ask('Enter the new value for the permission (A = allow, D = disallow, I = inherit)');
switch (strtolower($new_value_str)) {
switch (strtolower((string) $new_value_str)) {
case 'a':
case 'allow':
$new_value = true;
@ -207,11 +201,11 @@ class UsersPermissionsCommand extends Command
if ($permission_value === true) {
return '<fg=green>Allow</>';
} else if ($permission_value === false) {
} elseif ($permission_value === false) {
return '<fg=red>Disallow</>';
} else if ($permission_value === null && !$inherit) {
} elseif ($permission_value === null && !$inherit) {
return '<fg=blue>Inherit</>';
} else if ($permission_value === null && $inherit) {
} elseif ($permission_value === null && $inherit) {
return '<fg=red>Disallow (Inherited)</>';
}

View file

@ -30,13 +30,8 @@ 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 VersionManagerInterface $versionManager;
protected GitVersionInfo $gitVersionInfo;
public function __construct(VersionManagerInterface $versionManager, GitVersionInfo $gitVersionInfo)
public function __construct(protected VersionManagerInterface $versionManager, protected GitVersionInfo $gitVersionInfo)
{
$this->versionManager = $versionManager;
$this->gitVersionInfo = $gitVersionInfo;
parent::__construct();
}