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

@@ -15,7 +15,6 @@ use Chill\CustomFieldsBundle\Entity\CustomField;
use Chill\CustomFieldsBundle\Entity\CustomFieldsGroup;
use Chill\CustomFieldsBundle\Service\CustomFieldProvider;
use Doctrine\ORM\EntityManager;
use RuntimeException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
@@ -26,8 +25,6 @@ use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Component\Yaml\Exception\ParseException;
use Symfony\Component\Yaml\Parser;
use function count;
/**
* Class for the command 'chill:custom_fields:populate_group' that
* Create custom fields from a yml file.
@@ -40,9 +37,6 @@ class CreateFieldsOnGroupCommand extends Command
/**
* CreateFieldsOnGroupCommand constructor.
*
* @param $availableLanguages
* @param $customizablesEntities
*/
public function __construct(
private readonly CustomFieldProvider $customFieldProvider,
@@ -95,9 +89,9 @@ class CreateFieldsOnGroupCommand extends Command
->getRepository(\Chill\CustomFieldsBundle\Entity\CustomFieldsGroup::class)
->findAll();
if (count($customFieldsGroups) === 0) {
if (0 === \count($customFieldsGroups)) {
$output->writeln('<error>There aren\'t any CustomFieldsGroup recorded'
. ' Please create at least one.</error>');
.' Please create at least one.</error>');
}
$table = new Table($output);
@@ -120,7 +114,7 @@ class CreateFieldsOnGroupCommand extends Command
}
}
throw new RuntimeException('The id does not match an existing CustomFieldsGroup');
throw new \RuntimeException('The id does not match an existing CustomFieldsGroup');
}
);
$customFieldsGroup = $helper->ask($input, $output, $question);
@@ -135,6 +129,7 @@ class CreateFieldsOnGroupCommand extends Command
);
$fields = $this->_addFields($customFieldsGroup, $fieldsInput, $output);
return 0;
}
@@ -145,12 +140,11 @@ class CreateFieldsOnGroupCommand extends Command
$languages = $this->availableLanguages;
foreach ($values['fields'] as $slug => $field) {
//check the cf type exists
// check the cf type exists
$cfType = $this->customFieldProvider->getCustomFieldByType($field['type']);
if (null === $cfType) {
throw new RuntimeException('the type ' . $field['type'] . ' '
. 'does not exists');
throw new \RuntimeException('the type '.$field['type'].' does not exists');
}
$cf = new CustomField();
@@ -161,21 +155,21 @@ class CreateFieldsOnGroupCommand extends Command
->setType($field['type'])
->setCustomFieldsGroup($group);
//add to table
// add to table
$names = [];
foreach ($languages as $lang) {
//todo replace with service to find lang when available
// todo replace with service to find lang when available
$names[] = $cf->getName()[$lang] ?? 'Not available in this language';
}
if ($this->validator->validate($cf)) {
$em->persist($cf);
$output->writeln('<info>Adding Custom Field of type '
. $cf->getType() . "\t with slug " . $cf->getSlug() .
"\t and names : " . implode(', ', $names) . '</info>');
.$cf->getType()."\t with slug ".$cf->getSlug().
"\t and names : ".implode(', ', $names).'</info>');
} else {
throw new RuntimeException('Error in field ' . $slug);
throw new \RuntimeException('Error in field '.$slug);
}
}
@@ -187,13 +181,13 @@ class CreateFieldsOnGroupCommand extends Command
$parser = new Parser();
if (!file_exists($path)) {
throw new RuntimeException('file does not exist');
throw new \RuntimeException('file does not exist');
}
try {
$values = $parser->parse(file_get_contents($path));
} catch (ParseException $ex) {
throw new RuntimeException('The yaml file is not valid', 0, $ex);
throw new \RuntimeException('The yaml file is not valid', 0, $ex);
}
return $values;
@@ -203,7 +197,7 @@ class CreateFieldsOnGroupCommand extends Command
{
$rows = [];
$languages = $this->availableLanguages;
//gather entitites and create an array to access them easily
// gather entitites and create an array to access them easily
$customizableEntities = [];
foreach ($this->customizablesEntities as $entry) {
@@ -213,14 +207,14 @@ class CreateFieldsOnGroupCommand extends Command
array_walk(
$customFieldsGroups,
static function (CustomFieldsGroup $customFieldGroup, $key) use ($languages, &$rows, $customizableEntities) {
//set id and entity
// set id and entity
$row = [
$customFieldGroup->getId(),
$customizableEntities[$customFieldGroup->getEntity()],
];
foreach ($languages as $lang) {
//todo replace with service to find lang when available
// todo replace with service to find lang when available
$row[] = $customFieldGroup->getName()[$lang] ?? 'Not available in this language';
}
$rows[] = $row;