cs: Fix code style (safe rules only).

This commit is contained in:
Pol Dellaiera
2021-11-23 14:06:38 +01:00
parent 149d7ce991
commit 8f96a1121d
1223 changed files with 65199 additions and 64625 deletions

View File

@@ -1,28 +1,19 @@
<?php
/*
* Copyright (C) 2017 Champs-Libres <info@champs-libres.coop>
/**
* Chill is a software for social workers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\PersonBundle\Export\Aggregator;
use Chill\MainBundle\Export\AggregatorInterface;
use Chill\MainBundle\Export\ExportElementValidatedInterface;
use DateTime;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Chill\MainBundle\Export\ExportElementValidatedInterface;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
@@ -54,48 +45,47 @@ final class AgeAggregator implements AggregatorInterface, ExportElementValidated
public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder)
{
$builder->add('date_age_calculation', DateType::class, array(
'label' => "Calculate age in relation to this date",
'data' => new \DateTime(),
'attr' => array('class' => 'datepicker'),
'widget'=> 'single_text',
'format' => 'dd-MM-yyyy'
));
}
public function validateForm($data, ExecutionContextInterface $context)
{
if ($data['date_age_calculation'] === null) {
$context->buildViolation("The date should not be empty")
->addViolation();
}
$builder->add('date_age_calculation', DateType::class, [
'label' => 'Calculate age in relation to this date',
'data' => new DateTime(),
'attr' => ['class' => 'datepicker'],
'widget' => 'single_text',
'format' => 'dd-MM-yyyy',
]);
}
public function getLabels($key, array $values, $data)
{
return function($value) {
if ($value === '_header') {
return "Age";
return function ($value) {
if ('_header' === $value) {
return 'Age';
}
if ($value === NULL) {
return $this->translator->trans("without data");
if (null === $value) {
return $this->translator->trans('without data');
}
return $value;
};
}
public function getQueryKeys($data)
{
return array(
'person_age'
);
return [
'person_age',
];
}
public function getTitle()
{
return "Aggregate by age";
return 'Aggregate by age';
}
public function validateForm($data, ExecutionContextInterface $context)
{
if (null === $data['date_age_calculation']) {
$context->buildViolation('The date should not be empty')
->addViolation();
}
}
}

View File

@@ -1,37 +1,25 @@
<?php
/*
* Copyright (C) 2016 Champs-Libres <info@champs-libres.coop>
/**
* Chill is a software for social workers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\PersonBundle\Export\Aggregator;
use Chill\MainBundle\Export\AggregatorInterface;
use Symfony\Component\Form\FormBuilderInterface;
use Doctrine\ORM\QueryBuilder;
use Doctrine\ORM\EntityRepository;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Symfony\Component\Translation\TranslatorInterface;
use Chill\MainBundle\Util\CountriesInfo;
use Symfony\Component\Security\Core\Role\Role;
use Chill\PersonBundle\Security\Authorization\PersonVoter;
use Chill\MainBundle\Export\ExportElementValidatedInterface;
use Chill\MainBundle\Repository\CountryRepository;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\MainBundle\Util\CountriesInfo;
use Doctrine\ORM\QueryBuilder;
use LogicException;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
final class CountryOfBirthAggregator implements AggregatorInterface, ExportElementValidatedInterface
{
@@ -51,38 +39,17 @@ final class CountryOfBirthAggregator implements AggregatorInterface, ExportEleme
$this->translator = $translator;
}
public function applyOn()
public function addRole()
{
return 'person';
}
public function buildForm(FormBuilderInterface $builder)
{
$builder->add('group_by_level', ChoiceType::class, array(
'choices' => array(
'Group by continents' => 'continent',
'Group by country' => 'country'
),
'expanded' => true,
'multiple' => false
));
}
public function validateForm($data, ExecutionContextInterface $context)
{
if ($data['group_by_level'] === null) {
$context->buildViolation("You should select an option")
->addViolation();
}
return null;
}
public function alterQuery(QueryBuilder $qb, $data)
{
// add a clause in select part
if ($data['group_by_level'] === 'country') {
if ('country' === $data['group_by_level']) {
$qb->addSelect('countryOfBirth.countryCode as country_of_birth_aggregator');
} elseif ($data['group_by_level'] === 'continent') {
} elseif ('continent' === $data['group_by_level']) {
$clause = 'CASE '
. 'WHEN countryOfBirth.countryCode IN(:cob_africa_codes) THEN \'AF\' '
. 'WHEN countryOfBirth.countryCode IN(:cob_asia_codes) THEN \'AS\' '
@@ -95,24 +62,24 @@ final class CountryOfBirthAggregator implements AggregatorInterface, ExportEleme
. 'END as country_of_birth_aggregator ';
$qb->addSelect($clause);
$params =
array(
[
'cob_africa_codes' => CountriesInfo::getCountriesCodeByContinent('AF'),
'cob_asia_codes' => CountriesInfo::getCountriesCodeByContinent('AS'),
'cob_europe_codes' => CountriesInfo::getCountriesCodeByContinent('EU'),
'cob_north_america_codes' => CountriesInfo::getCountriesCodeByContinent('NA'),
'cob_south_america_codes' => CountriesInfo::getCountriesCodeByContinent('SA'),
'cob_oceania_codes' => CountriesInfo::getCountriesCodeByContinent('OC'),
'cob_antartica_codes' => CountriesInfo::getCountriesCodeByContinent('AN')
);
'cob_antartica_codes' => CountriesInfo::getCountriesCodeByContinent('AN'),
];
foreach ($params as $k => $v) {
$qb->setParameter($k, $v);
}
} else {
throw new \LogicException("The group_by_level '".$data['group_by_level']
." is not known.");
throw new LogicException("The group_by_level '" . $data['group_by_level']
. ' is not known.');
}
$qb->leftJoin('person.countryOfBirth', 'countryOfBirth');
// add group by
@@ -123,36 +90,37 @@ final class CountryOfBirthAggregator implements AggregatorInterface, ExportEleme
} else {
$qb->groupBy('country_of_birth_aggregator');
}
}
public function getTitle()
public function applyOn()
{
return "Group people by country of birth";
return 'person';
}
public function getQueryKeys($data)
public function buildForm(FormBuilderInterface $builder)
{
return array('country_of_birth_aggregator');
}
public function addRole()
{
return NULL;
$builder->add('group_by_level', ChoiceType::class, [
'choices' => [
'Group by continents' => 'continent',
'Group by country' => 'country',
],
'expanded' => true,
'multiple' => false,
]);
}
public function getLabels($key, array $values, $data)
{
$labels = [];
if ($data['group_by_level'] === 'country') {
if ('country' === $data['group_by_level']) {
$qb = $this->countriesRepository->createQueryBuilder('c');
$countries = $qb
->andWhere($qb->expr()->in('c.countryCode', ':countries'))
->setParameter('countries', $values)
->getQuery()
->getResult(\Doctrine\ORM\Query::HYDRATE_SCALAR);
->andWhere($qb->expr()->in('c.countryCode', ':countries'))
->setParameter('countries', $values)
->getQuery()
->getResult(\Doctrine\ORM\Query::HYDRATE_SCALAR);
// initialize array and add blank key for null values
$labels = [
@@ -160,13 +128,13 @@ final class CountryOfBirthAggregator implements AggregatorInterface, ExportEleme
'_header' => $this->translator->trans('Country of birth'),
];
foreach($countries as $row) {
foreach ($countries as $row) {
$labels[$row['c_countryCode']] = $this->translatableStringHelper->localize($row['c_name']);
}
}
if ($data['group_by_level'] === 'continent') {
$labels = array(
if ('continent' === $data['group_by_level']) {
$labels = [
'EU' => $this->translator->trans('Europe'),
'AS' => $this->translator->trans('Asia'),
'AN' => $this->translator->trans('Antartica'),
@@ -175,13 +143,30 @@ final class CountryOfBirthAggregator implements AggregatorInterface, ExportEleme
'NA' => $this->translator->trans('North America'),
'OC' => $this->translator->trans('Oceania'),
'' => $this->translator->trans('without data'),
'_header' => $this->translator->trans('Continent of birth')
);
'_header' => $this->translator->trans('Continent of birth'),
];
}
return function(string $value) use ($labels): string {
return function (string $value) use ($labels): string {
return $labels[$value];
};
}
public function getQueryKeys($data)
{
return ['country_of_birth_aggregator'];
}
public function getTitle()
{
return 'Group people by country of birth';
}
public function validateForm($data, ExecutionContextInterface $context)
{
if (null === $data['group_by_level']) {
$context->buildViolation('You should select an option')
->addViolation();
}
}
}

View File

@@ -1,30 +1,21 @@
<?php
/*
* Copyright (C) 2016 Champs-Libres <info@champs-libres.coop>
/**
* Chill is a software for social workers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\PersonBundle\Export\Aggregator;
use Chill\MainBundle\Export\AggregatorInterface;
use Symfony\Component\Form\FormBuilderInterface;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Translation\TranslatorInterface;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\QueryBuilder;
use LogicException;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Translation\TranslatorInterface;
final class GenderAggregator implements AggregatorInterface
{
@@ -35,6 +26,18 @@ final class GenderAggregator implements AggregatorInterface
$this->translator = $translator;
}
public function addRole()
{
return null;
}
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->addSelect('person.gender as gender');
$qb->addGroupBy('gender');
}
public function applyOn()
{
return Declarations::PERSON_TYPE;
@@ -42,51 +45,40 @@ final class GenderAggregator implements AggregatorInterface
public function buildForm(FormBuilderInterface $builder)
{
}
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->addSelect('person.gender as gender');
$qb->addGroupBy('gender');
}
public function getTitle()
{
return "Group people by gender";
}
public function getQueryKeys($data)
{
return array('gender');
}
public function getLabels($key, array $values, $data)
{
return function($value) {
{
return function ($value) {
switch ($value) {
case Person::FEMALE_GENDER :
case Person::FEMALE_GENDER:
return $this->translator->trans('woman');
case Person::MALE_GENDER :
case Person::MALE_GENDER:
return $this->translator->trans('man');
case Person::BOTH_GENDER:
return $this->translator->trans('both');
case null:
return $this->translator->trans('Not given');
case '_header' :
case '_header':
return $this->translator->trans('Gender');
default:
throw new \LogicException(sprintf("The value %s is not valid", $value));
throw new LogicException(sprintf('The value %s is not valid', $value));
}
};
}
public function addRole()
public function getQueryKeys($data)
{
return NULL;
return ['gender'];
}
public function getTitle()
{
return 'Group people by gender';
}
}

View File

@@ -1,37 +1,25 @@
<?php
/*
* Copyright (C) 2016 Champs-Libres <info@champs-libres.coop>
/**
* Chill is a software for social workers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\PersonBundle\Export\Aggregator;
use Chill\MainBundle\Export\AggregatorInterface;
use Symfony\Component\Form\FormBuilderInterface;
use Doctrine\ORM\QueryBuilder;
use Doctrine\ORM\EntityRepository;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Symfony\Component\Translation\TranslatorInterface;
use Chill\MainBundle\Util\CountriesInfo;
use Symfony\Component\Security\Core\Role\Role;
use Chill\PersonBundle\Security\Authorization\PersonVoter;
use Chill\MainBundle\Export\ExportElementValidatedInterface;
use Chill\MainBundle\Repository\CountryRepository;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\MainBundle\Util\CountriesInfo;
use Doctrine\ORM\QueryBuilder;
use LogicException;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
final class NationalityAggregator implements AggregatorInterface, ExportElementValidatedInterface
{
@@ -51,39 +39,17 @@ final class NationalityAggregator implements AggregatorInterface, ExportElementV
$this->translator = $translator;
}
public function applyOn()
public function addRole()
{
return 'person';
}
public function buildForm(FormBuilderInterface $builder)
{
$builder->add('group_by_level', ChoiceType::class, array(
'choices' => array(
'Group by continents' => 'continent',
'Group by country' => 'country'
),
'expanded' => true,
'multiple' => false
));
}
public function validateForm($data, ExecutionContextInterface $context)
{
if ($data['group_by_level'] === null) {
$context->buildViolation("You should select an option")
->addViolation();
}
return null;
}
public function alterQuery(QueryBuilder $qb, $data)
{
// add a clause in select part
if ($data['group_by_level'] === 'country') {
if ('country' === $data['group_by_level']) {
$qb->addSelect('nationality.countryCode as nationality_aggregator');
} elseif ($data['group_by_level'] === 'continent') {
} elseif ('continent' === $data['group_by_level']) {
$clause = 'CASE '
. 'WHEN nationality.countryCode IN(:africa_codes) THEN \'AF\' '
. 'WHEN nationality.countryCode IN(:asia_codes) THEN \'AS\' '
@@ -96,24 +62,24 @@ final class NationalityAggregator implements AggregatorInterface, ExportElementV
. 'END as nationality_aggregator ';
$qb->addSelect($clause);
$params =
array(
[
'africa_codes' => CountriesInfo::getCountriesCodeByContinent('AF'),
'asia_codes' => CountriesInfo::getCountriesCodeByContinent('AS'),
'europe_codes' => CountriesInfo::getCountriesCodeByContinent('EU'),
'north_america_codes' => CountriesInfo::getCountriesCodeByContinent('NA'),
'south_america_codes' => CountriesInfo::getCountriesCodeByContinent('SA'),
'oceania_codes' => CountriesInfo::getCountriesCodeByContinent('OC'),
'antartica_codes' => CountriesInfo::getCountriesCodeByContinent('AN')
);
'antartica_codes' => CountriesInfo::getCountriesCodeByContinent('AN'),
];
foreach ($params as $k => $v) {
$qb->setParameter($k, $v);
}
} else {
throw new \LogicException("The group_by_level '".$data['group_by_level']
." is not known.");
throw new LogicException("The group_by_level '" . $data['group_by_level']
. ' is not known.');
}
$qb->leftJoin('person.nationality', 'nationality');
// add group by
@@ -124,36 +90,37 @@ final class NationalityAggregator implements AggregatorInterface, ExportElementV
} else {
$qb->groupBy('nationality_aggregator');
}
}
public function getTitle()
public function applyOn()
{
return "Group people by nationality";
return 'person';
}
public function getQueryKeys($data)
public function buildForm(FormBuilderInterface $builder)
{
return array('nationality_aggregator');
}
public function addRole()
{
return NULL;
$builder->add('group_by_level', ChoiceType::class, [
'choices' => [
'Group by continents' => 'continent',
'Group by country' => 'country',
],
'expanded' => true,
'multiple' => false,
]);
}
public function getLabels($key, array $values, $data)
{
$labels = [];
if ($data['group_by_level'] === 'country') {
if ('country' === $data['group_by_level']) {
$qb = $this->countriesRepository->createQueryBuilder('c');
$countries = $qb
->andWhere($qb->expr()->in('c.countryCode', ':countries'))
->setParameter('countries', $values)
->getQuery()
->getResult(\Doctrine\ORM\Query::HYDRATE_SCALAR);
->andWhere($qb->expr()->in('c.countryCode', ':countries'))
->setParameter('countries', $values)
->getQuery()
->getResult(\Doctrine\ORM\Query::HYDRATE_SCALAR);
// initialize array and add blank key for null values
$labels = [
@@ -161,13 +128,13 @@ final class NationalityAggregator implements AggregatorInterface, ExportElementV
'_header' => $this->translator->trans('Nationality'),
];
foreach($countries as $row) {
foreach ($countries as $row) {
$labels[$row['c_countryCode']] = $this->translatableStringHelper->localize($row['c_name']);
}
}
if ($data['group_by_level'] === 'continent') {
$labels = array(
if ('continent' === $data['group_by_level']) {
$labels = [
'EU' => $this->translator->trans('Europe'),
'AS' => $this->translator->trans('Asia'),
'AN' => $this->translator->trans('Antartica'),
@@ -175,14 +142,31 @@ final class NationalityAggregator implements AggregatorInterface, ExportElementV
'SA' => $this->translator->trans('South America'),
'NA' => $this->translator->trans('North America'),
'OC' => $this->translator->trans('Oceania'),
'' => $this->translator->trans('without data'),
'_header' => $this->translator->trans('Continent')
);
'' => $this->translator->trans('without data'),
'_header' => $this->translator->trans('Continent'),
];
}
return function(string $value) use ($labels): string {
return function (string $value) use ($labels): string {
return $labels[$value];
};
}
public function getQueryKeys($data)
{
return ['nationality_aggregator'];
}
public function getTitle()
{
return 'Group people by nationality';
}
public function validateForm($data, ExecutionContextInterface $context)
{
if (null === $data['group_by_level']) {
$context->buildViolation('You should select an option')
->addViolation();
}
}
}