apply more cs rules for php-cs

This commit is contained in:
2023-10-17 13:27:03 +02:00
parent 0b0cbed9db
commit bc2041cbdd
1485 changed files with 8169 additions and 9620 deletions

View File

@@ -17,11 +17,9 @@ use Chill\MainBundle\Entity\PermissionsGroup;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Repository\UserRepository;
use Doctrine\ORM\EntityManagerInterface;
use Exception;
use League\Csv\Reader;
use League\Csv\Writer;
use Psr\Log\LoggerInterface;
use RuntimeException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
@@ -33,15 +31,6 @@ use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Component\Validator\ConstraintViolationListInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use function array_key_exists;
use function array_keys;
use function array_merge;
use function bin2hex;
use function count;
use function implode;
use function random_bytes;
use function trim;
class ChillImportUsersCommand extends Command
{
/**
@@ -91,7 +80,7 @@ class ChillImportUsersCommand extends Command
$str[] = $e->getMessage();
}
return implode(';', $str);
return \implode(';', $str);
}
protected function configure()
@@ -107,8 +96,8 @@ class ChillImportUsersCommand extends Command
protected function createOrGetGroupCenter(Center $center, PermissionsGroup $pg): GroupCenter
{
if (array_key_exists($center->getId(), $this->groupCenters)) {
if (array_key_exists($pg->getId(), $this->groupCenters[$center->getId()])) {
if (\array_key_exists($center->getId(), $this->groupCenters)) {
if (\array_key_exists($pg->getId(), $this->groupCenters[$center->getId()])) {
return $this->groupCenters[$center->getId()][$pg->getId()];
}
}
@@ -138,12 +127,12 @@ class ChillImportUsersCommand extends Command
{
$user = new User();
$user
->setEmail(trim((string) $data['email']))
->setUsername(trim((string) $data['username']))
->setEmail(\trim((string) $data['email']))
->setUsername(\trim((string) $data['username']))
->setEnabled(true)
->setPassword($this->passwordEncoder->encodePassword(
$user,
bin2hex(random_bytes(32))
\bin2hex(\random_bytes(32))
));
$errors = $this->validator->validate($user);
@@ -154,8 +143,7 @@ class ChillImportUsersCommand extends Command
$this->tempOutput->writeln(sprintf('%d errors found with user with username "%s" at line %d', $errors->count(), $data['username'], $offset));
$this->tempOutput->writeln($errorMessages);
throw new RuntimeException('Found errors while creating an user. '
. 'Watch messages in command output');
throw new \RuntimeException('Found errors while creating an user. Watch messages in command output');
}
$pgs = $this->getPermissionGroup($data['permission group']);
@@ -215,9 +203,10 @@ class ChillImportUsersCommand extends Command
try {
$this->loadUsers();
} catch (Exception $e) {
} catch (\Exception $e) {
throw $e;
}
return 0;
}
@@ -239,9 +228,9 @@ class ChillImportUsersCommand extends Command
protected function getCenters($name)
{
// sanitize
$name = trim($name);
$name = \trim($name);
if (array_key_exists($name, $this->centers)) {
if (\array_key_exists($name, $this->centers)) {
return $this->centers[$name];
}
@@ -274,8 +263,7 @@ class ChillImportUsersCommand extends Command
$this->tempOutput->writeln(sprintf('%d errors found with center with name "%s"', $errors->count(), $name));
$this->tempOutput->writeln($errorMessages);
throw new RuntimeException('Found errors while creating one center. '
. 'Watch messages in command output');
throw new \RuntimeException('Found errors while creating one center. Watch messages in command output');
}
$this->em->persist($center);
@@ -288,7 +276,7 @@ class ChillImportUsersCommand extends Command
protected function getPermissionGroup($alias)
{
if (array_key_exists($alias, $this->permissionGroups)) {
if (\array_key_exists($alias, $this->permissionGroups)) {
return $this->permissionGroups[$alias];
}
@@ -301,30 +289,29 @@ class ChillImportUsersCommand extends Command
$permissionGroupsByName[$permissionGroup->getName()] = $permissionGroup;
}
if (count($permissionGroupsByName) === 0) {
throw new RuntimeException('no permission groups found. Create them '
. 'before importing users');
if (0 === \count($permissionGroupsByName)) {
throw new \RuntimeException('no permission groups found. Create them before importing users');
}
$question = new ChoiceQuestion(
"To which permission groups associate with \"{$alias}\" ?",
array_keys($permissionGroupsByName)
\array_keys($permissionGroupsByName)
);
$question
->setMultiselect(true)
->setAutocompleterValues(array_keys($permissionGroupsByName))
->setAutocompleterValues(\array_keys($permissionGroupsByName))
->setNormalizer(static function ($value) {
if (null === $value) {
return '';
}
return trim((string) $value);
return \trim((string) $value);
});
$helper = $this->getHelper('question');
$keys = $helper->ask($this->tempInput, $this->tempOutput, $question);
$this->tempOutput->writeln('You have chosen ' . implode(', ', $keys));
$this->tempOutput->writeln('You have chosen '.\implode(', ', $keys));
if (
$helper->ask(
@@ -343,7 +330,7 @@ class ChillImportUsersCommand extends Command
$this->logger->error('Error while responding to a a question');
$this->tempOutput->writeln('Ok, I accept, but I do not know what to do. Please try again.');
throw new RuntimeException('Error while responding to a question');
throw new \RuntimeException('Error while responding to a question');
}
protected function loadUsers()
@@ -358,7 +345,7 @@ class ChillImportUsersCommand extends Command
if ($this->doesUserExists($r)) {
$this->tempOutput->writeln(sprintf("User with username '%s' already "
. 'exists, skipping', $r['username']));
.'exists, skipping', $r['username']));
$this->logger->info('One user already exists, skipping creation', [
'username_in_file' => $r['username'],
@@ -381,7 +368,7 @@ class ChillImportUsersCommand extends Command
foreach ($reader->getRecords() as $r) {
$this->centers[$r['alias']] =
array_merge(
\array_merge(
$this->centers[$r['alias']] ?? [],
$this->getCenters(
$r['center']