mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-29 19:13:49 +00:00
apply more cs rules for php-cs
This commit is contained in:
@@ -25,28 +25,14 @@ use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Chill\PersonBundle\Export\Declarations;
|
||||
use Chill\ReportBundle\Entity\Report;
|
||||
use Chill\ReportBundle\Security\Authorization\ReportVoter;
|
||||
use Closure;
|
||||
use DateTime;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\Query;
|
||||
use Exception;
|
||||
use LogicException;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Validator\Constraints\Callback;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
use function array_key_exists;
|
||||
use function array_keys;
|
||||
use function array_merge;
|
||||
use function count;
|
||||
use function in_array;
|
||||
use function strlen;
|
||||
use function strtolower;
|
||||
use function ucfirst;
|
||||
use function uniqid;
|
||||
|
||||
class ReportList implements ExportElementValidatedInterface, ListInterface
|
||||
{
|
||||
protected array $fields = [
|
||||
@@ -86,16 +72,16 @@ class ReportList implements ExportElementValidatedInterface, ListInterface
|
||||
return [];
|
||||
},
|
||||
'choice_label' => fn (string $key, string $label): string => match (substr($key, 0, 7)) {
|
||||
'person_' => $this->translator->trans(substr($key, 7, strlen($key) - 7)) .
|
||||
' (' . $this->translator->trans('Person') . ')',
|
||||
'report_' => $this->translator->trans(ucfirst(substr($key, 7, strlen($key) - 7))) .
|
||||
' (' . $this->translator->trans('Report') . ')',
|
||||
default => $label .
|
||||
' (' . $this->translator->trans("Report's question") . ')',
|
||||
'person_' => $this->translator->trans(substr($key, 7, \strlen($key) - 7)).
|
||||
' ('.$this->translator->trans('Person').')',
|
||||
'report_' => $this->translator->trans(\ucfirst(substr($key, 7, \strlen($key) - 7))).
|
||||
' ('.$this->translator->trans('Report').')',
|
||||
default => $label.
|
||||
' ('.$this->translator->trans("Report's question").')',
|
||||
},
|
||||
'constraints' => [new Callback([
|
||||
'callback' => static function ($selected, ExecutionContextInterface $context) {
|
||||
if (count($selected) === 0) {
|
||||
if (0 === \count($selected)) {
|
||||
$context->buildViolation('You must select at least one element')
|
||||
->atPath('fields')
|
||||
->addViolation();
|
||||
@@ -110,9 +96,10 @@ class ReportList implements ExportElementValidatedInterface, ListInterface
|
||||
'block_name' => 'list_export_form_address_date',
|
||||
]);
|
||||
}
|
||||
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return ['address_date' => new DateTime()];
|
||||
return ['address_date' => new \DateTime()];
|
||||
}
|
||||
|
||||
public function getAllowedFormattersTypes()
|
||||
@@ -147,14 +134,13 @@ class ReportList implements ExportElementValidatedInterface, ListInterface
|
||||
}
|
||||
|
||||
if ('person_birthdate' === $key) {
|
||||
$date = DateTime::createFromFormat('Y-m-d', $value);
|
||||
$date = \DateTime::createFromFormat('Y-m-d', $value);
|
||||
} else {
|
||||
$date = DateTime::createFromFormat('Y-m-d H:i:s', $value);
|
||||
$date = \DateTime::createFromFormat('Y-m-d H:i:s', $value);
|
||||
}
|
||||
// check that the creation could occurs.
|
||||
if (false === $date) {
|
||||
throw new Exception(sprintf('The value %s could '
|
||||
. 'not be converted to %s', $value, DateTime::class));
|
||||
throw new \Exception(sprintf('The value %s could not be converted to %s', $value, \DateTime::class));
|
||||
}
|
||||
|
||||
return $date->format('d-m-Y');
|
||||
@@ -224,7 +210,7 @@ class ReportList implements ExportElementValidatedInterface, ListInterface
|
||||
|
||||
return function ($value) use ($key, $countryRepository) {
|
||||
if ('_header' === $value) {
|
||||
return strtolower($key);
|
||||
return \strtolower($key);
|
||||
}
|
||||
|
||||
if (null === $value) {
|
||||
@@ -241,7 +227,7 @@ class ReportList implements ExportElementValidatedInterface, ListInterface
|
||||
case 'person_address_country_name':
|
||||
return function ($value) use ($key) {
|
||||
if ('_header' === $value) {
|
||||
return strtolower($key);
|
||||
return \strtolower($key);
|
||||
}
|
||||
|
||||
if (null === $value) {
|
||||
@@ -253,10 +239,10 @@ class ReportList implements ExportElementValidatedInterface, ListInterface
|
||||
|
||||
default:
|
||||
// for fields which are associated with person
|
||||
if (in_array($key, $this->fields, true)) {
|
||||
if (\in_array($key, $this->fields, true)) {
|
||||
return static function ($value) use ($key) {
|
||||
if ('_header' === $value) {
|
||||
return strtolower($key);
|
||||
return \strtolower($key);
|
||||
}
|
||||
|
||||
return $value;
|
||||
@@ -272,13 +258,13 @@ class ReportList implements ExportElementValidatedInterface, ListInterface
|
||||
$fields = [];
|
||||
|
||||
foreach ($data['fields'] as $key) {
|
||||
if (in_array($key, $this->fields, true)) {
|
||||
if (\in_array($key, $this->fields, true)) {
|
||||
$fields[] = $key;
|
||||
}
|
||||
}
|
||||
|
||||
// add the key from slugs and return
|
||||
return [...$fields, ...array_keys($this->slugs)];
|
||||
return [...$fields, ...\array_keys($this->slugs)];
|
||||
}
|
||||
|
||||
public function getResult($query, $data)
|
||||
@@ -306,9 +292,8 @@ class ReportList implements ExportElementValidatedInterface, ListInterface
|
||||
$centers = array_map(static fn ($el) => $el['center'], $acl);
|
||||
|
||||
// throw an error if any fields are present
|
||||
if (!array_key_exists('fields', $data)) {
|
||||
throw new \Doctrine\DBAL\Exception\InvalidArgumentException('any fields '
|
||||
. 'have been checked');
|
||||
if (!\array_key_exists('fields', $data)) {
|
||||
throw new \Doctrine\DBAL\Exception\InvalidArgumentException('any fields have been checked');
|
||||
}
|
||||
|
||||
$qb = $this->em->createQueryBuilder();
|
||||
@@ -316,7 +301,7 @@ class ReportList implements ExportElementValidatedInterface, ListInterface
|
||||
// process fields which are not custom fields
|
||||
foreach ($this->fields as $f) {
|
||||
// do not add fields which are not selected
|
||||
if (!in_array($f, $data['fields'], true)) {
|
||||
if (!\in_array($f, $data['fields'], true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -367,8 +352,7 @@ class ReportList implements ExportElementValidatedInterface, ListInterface
|
||||
'person_' => $qb->addSelect(sprintf('person.%s as %s', $suffix, $f)),
|
||||
'report_' => $qb->addSelect(sprintf('report.%s as %s', $suffix, $f)),
|
||||
// no break
|
||||
default => throw new LogicException("this prefix {$prefix} should "
|
||||
. "not be encountered. Full field: {$f}"),
|
||||
default => throw new \LogicException("this prefix {$prefix} should not be encountered. Full field: {$f}"),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -376,7 +360,7 @@ class ReportList implements ExportElementValidatedInterface, ListInterface
|
||||
// process fields which are custom fields
|
||||
foreach ($this->getCustomFields() as $cf) {
|
||||
// do not add custom fields which are not selected
|
||||
if (!in_array($cf->getSlug(), $data['fields'], true)) {
|
||||
if (!\in_array($cf->getSlug(), $data['fields'], true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -438,7 +422,7 @@ class ReportList implements ExportElementValidatedInterface, ListInterface
|
||||
);
|
||||
|
||||
// check if there is one field starting with address in data
|
||||
if (count(array_intersect($data['fields'], $addressFields)) > 0) {
|
||||
if (\count(array_intersect($data['fields'], $addressFields)) > 0) {
|
||||
// if a field address is checked, the date must not be empty
|
||||
if (empty($data['address_date'])) {
|
||||
$context
|
||||
@@ -467,7 +451,7 @@ class ReportList implements ExportElementValidatedInterface, ListInterface
|
||||
private function getCustomFields()
|
||||
{
|
||||
return array_filter($this->customfieldsGroup
|
||||
->getCustomFields()->toArray(), static fn (CustomField $cf) => $cf->getType() !== 'title');
|
||||
->getCustomFields()->toArray(), static fn (CustomField $cf) => 'title' !== $cf->getType());
|
||||
}
|
||||
|
||||
private function getLabelForCustomField($key, array $values, $data)
|
||||
@@ -498,7 +482,7 @@ class ReportList implements ExportElementValidatedInterface, ListInterface
|
||||
$label = $cfType->getChoices($cf)[$slugChoice];
|
||||
|
||||
return $this->translatableStringHelper->localize($cf->getName())
|
||||
. ' | ' . $label;
|
||||
.' | '.$label;
|
||||
}
|
||||
|
||||
if ('_other' === $slugChoice && $cfType->isChecked($cf, $slugChoice, $decoded)) {
|
||||
@@ -514,7 +498,7 @@ class ReportList implements ExportElementValidatedInterface, ListInterface
|
||||
|
||||
private function slugToDQL($slug, $type = 'default', array $additionalInfos = [])
|
||||
{
|
||||
$uid = 'slug_' . uniqid('', true);
|
||||
$uid = 'slug_'.\uniqid('', true);
|
||||
|
||||
$this->slugs[$uid] = [
|
||||
'slug' => $slug,
|
||||
|
@@ -67,6 +67,7 @@ class ReportDateFilter implements FilterInterface
|
||||
'label' => 'Report is before this date',
|
||||
]);
|
||||
}
|
||||
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return ['date_from' => new RollingDate(RollingDate::T_YEAR_PREVIOUS_START), 'date_to' => new RollingDate(RollingDate::T_TODAY)];
|
||||
@@ -75,7 +76,7 @@ class ReportDateFilter implements FilterInterface
|
||||
public function describeAction($data, $format = 'string')
|
||||
{
|
||||
return ['Filtered by report\'s date: '
|
||||
. 'between %date_from% and %date_to%', [
|
||||
.'between %date_from% and %date_to%', [
|
||||
'%date_from%' => $this->rollingDateConverter->convert($data['date_from'])->format('d-m-Y'),
|
||||
'%date_to%' => $this->rollingDateConverter->convert($data['date_to'])->format('d-m-Y'),
|
||||
], ];
|
||||
|
Reference in New Issue
Block a user