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

@@ -58,7 +58,7 @@ class LoadAccompanyingPeriodClosingMotive extends AbstractFixture implements Ord
foreach (static::$closingMotives as $ref => $new) {
$motive = new ClosingMotive();
$motive->setName($new['name'])
->setActive(($new['active'] ?? true));
->setActive($new['active'] ?? true);
$manager->persist($motive);
$this->addReference($ref, $motive);

View File

@@ -17,13 +17,8 @@ use Chill\PersonBundle\Entity\SocialWork\SocialAction;
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
use Chill\PersonBundle\Repository\AccompanyingPeriodRepository;
use Chill\PersonBundle\Repository\SocialWork\EvaluationRepository;
use DateTimeImmutable;
use Doctrine\Persistence\ObjectManager;
use function array_pop;
use function array_rand;
use function count;
class LoadAccompanyingPeriodWork extends \Doctrine\Bundle\FixturesBundle\Fixture implements \Doctrine\Common\DataFixtures\DependentFixtureInterface
{
/**
@@ -48,8 +43,8 @@ class LoadAccompanyingPeriodWork extends \Doctrine\Bundle\FixturesBundle\Fixture
$i = 0;
while (null !== $period = array_pop($periods)) {
/** @var AccompanyingPeriod $period */
while (null !== $period = \array_pop($periods)) {
/* @var AccompanyingPeriod $period */
++$i;
if (0 === $i % 15) {
@@ -66,11 +61,11 @@ class LoadAccompanyingPeriodWork extends \Doctrine\Bundle\FixturesBundle\Fixture
$work
->setAccompanyingPeriod($period)
->setSocialAction($action)
->setStartDate(new DateTimeImmutable('today'))
->setStartDate(new \DateTimeImmutable('today'))
->addPerson($period->getPersons()->first())
->setCreatedAt(new DateTimeImmutable())
->setCreatedAt(new \DateTimeImmutable())
->setCreatedBy($this->getReference('center a_social'))
->setUpdatedAt(new DateTimeImmutable())
->setUpdatedAt(new \DateTimeImmutable())
->setUpdatedBy($this->getReference('center a_social'));
$manager->persist($work);
@@ -93,11 +88,11 @@ class LoadAccompanyingPeriodWork extends \Doctrine\Bundle\FixturesBundle\Fixture
$work
->setAccompanyingPeriod($period)
->setSocialAction($action)
->setStartDate(new DateTimeImmutable('today'))
->setStartDate(new \DateTimeImmutable('today'))
->addPerson($period->getPersons()->first())
->setCreatedAt(new DateTimeImmutable())
->setCreatedAt(new \DateTimeImmutable())
->setCreatedBy($this->getReference('center a_social'))
->setUpdatedAt(new DateTimeImmutable())
->setUpdatedAt(new \DateTimeImmutable())
->setUpdatedBy($this->getReference('center a_social'));
$manager->persist($work);
$ev = new AccompanyingPeriod\AccompanyingPeriodWorkEvaluation();
@@ -114,20 +109,20 @@ class LoadAccompanyingPeriodWork extends \Doctrine\Bundle\FixturesBundle\Fixture
{
$actions = $socialIssue->getRecursiveSocialActions()->toArray();
if (0 === count($actions)) {
if (0 === \count($actions)) {
return null;
}
return $actions[array_rand($actions)];
return $actions[\array_rand($actions)];
}
private function getRandomEvaluation(): Evaluation
{
if (0 === count($this->cacheEvaluations)) {
if (0 === \count($this->cacheEvaluations)) {
$this->cacheEvaluations = $this->evaluationRepository
->findAll();
}
return $this->cacheEvaluations[array_rand($this->cacheEvaluations)];
return $this->cacheEvaluations[\array_rand($this->cacheEvaluations)];
}
}

View File

@@ -17,27 +17,20 @@ use Chill\CustomFieldsBundle\CustomFields\CustomFieldTitle;
use Chill\CustomFieldsBundle\Entity\CustomField;
use Chill\CustomFieldsBundle\Entity\CustomFieldsDefaultGroup;
use Chill\CustomFieldsBundle\Entity\CustomFieldsGroup;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Entity\Person;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ObjectManager;
use RuntimeException;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Environment;
class LoadCustomFields extends AbstractFixture implements
OrderedFixtureInterface
class LoadCustomFields extends AbstractFixture implements OrderedFixtureInterface
{
private ?\Chill\CustomFieldsBundle\Entity\CustomField $cfText = null;
private ?\Chill\CustomFieldsBundle\Entity\CustomField $cfChoice = null;
/**
/**
* /**
* LoadCustomFields constructor.
*/
public function __construct(
@@ -46,7 +39,7 @@ class LoadCustomFields extends AbstractFixture implements
private readonly CustomFieldText $customFieldText,
) {}
//put your code here
// put your code here
public function getOrder()
{
return 10003;
@@ -85,7 +78,7 @@ class LoadCustomFields extends AbstractFixture implements
// select a set of people and add data
foreach ($personIds as $id) {
// add info on 1 person on 2
if (random_int(0, 1) === 1) {
if (1 === random_int(0, 1)) {
/** @var Person $person */
$person = $manager->getRepository(Person::class)->find($id);
$person->setCFData([

View File

@@ -19,20 +19,12 @@ use Chill\PersonBundle\Entity\Household\Household;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Entity\Person\PersonCenterHistory;
use Chill\PersonBundle\Household\MembersEditorFactory;
use DateInterval;
use DateTime;
use DateTimeImmutable;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ObjectManager;
use Nelmio\Alice\Loader\NativeLoader;
use function array_pop;
use function array_rand;
use function random_int;
use function shuffle;
class LoadHousehold extends Fixture implements DependentFixtureInterface
{
private const NUMBER_OF_HOUSEHOLD = 10;
@@ -64,43 +56,43 @@ class LoadHousehold extends Fixture implements DependentFixtureInterface
$this->generateHousehold(
$manager,
DateTimeImmutable::createFromFormat('Y-m-d', '2010-01-01')
\DateTimeImmutable::createFromFormat('Y-m-d', '2010-01-01')
);
$this->preparePersonIds();
$this->generateHousehold(
$manager,
DateTimeImmutable::createFromFormat('Y-m-d', '2015-01-01')
\DateTimeImmutable::createFromFormat('Y-m-d', '2015-01-01')
);
$manager->flush();
}
private function addAddressToHousehold(Household $household, DateTimeImmutable $date, ObjectManager $manager)
private function addAddressToHousehold(Household $household, \DateTimeImmutable $date, ObjectManager $manager)
{
if (random_int(0, 10) > 8) {
if (\random_int(0, 10) > 8) {
// 20% of household without address
return;
}
$nb = random_int(1, 6);
$nb = \random_int(1, 6);
$i = 0;
while ($i < $nb) {
$address = $this->createAddress();
$address->setValidFrom(DateTime::createFromImmutable($date));
$address->setValidFrom(\DateTime::createFromImmutable($date));
if (random_int(0, 20) < 1) {
$date = $date->add(new DateInterval('P' . random_int(8, 52) . 'W'));
$address->setValidTo(DateTime::createFromImmutable($date));
if (\random_int(0, 20) < 1) {
$date = $date->add(new \DateInterval('P'.\random_int(8, 52).'W'));
$address->setValidTo(\DateTime::createFromImmutable($date));
}
$household->addAddress($address);
$manager->persist($address);
$date = $date->add(new DateInterval('P' . random_int(8, 52) . 'W'));
$date = $date->add(new \DateInterval('P'.\random_int(8, 52).'W'));
++$i;
}
}
@@ -120,7 +112,7 @@ class LoadHousehold extends Fixture implements DependentFixtureInterface
return $objectSet->getObjects()['address1'];
}
private function generateHousehold(ObjectManager $manager, DateTimeImmutable $startDate)
private function generateHousehold(ObjectManager $manager, \DateTimeImmutable $startDate)
{
for ($i = 0; self::NUMBER_OF_HOUSEHOLD > $i; ++$i) {
$household = new Household();
@@ -134,7 +126,7 @@ class LoadHousehold extends Fixture implements DependentFixtureInterface
$k = 0;
foreach ($this->getRandomPersons(1, 3) as $person) {
$date = $startDate->add(new DateInterval('P' . random_int(1, 200) . 'W'));
$date = $startDate->add(new \DateInterval('P'.\random_int(1, 200).'W'));
$position = $this->getReference(LoadHouseholdPosition::ADULT);
$movement->addMovement($date, $person, $position, 0 === $k, 'self generated');
@@ -143,7 +135,7 @@ class LoadHousehold extends Fixture implements DependentFixtureInterface
// load children
foreach ($this->getRandomPersons(0, 3) as $person) {
$date = $startDate->add(new DateInterval('P' . random_int(1, 200) . 'W'));
$date = $startDate->add(new \DateInterval('P'.\random_int(1, 200).'W'));
$position = $this->getReference(LoadHouseholdPosition::CHILD);
$movement->addMovement($date, $person, $position, 0 === $k, 'self generated');
@@ -152,7 +144,7 @@ class LoadHousehold extends Fixture implements DependentFixtureInterface
// load children out
foreach ($this->getRandomPersons(0, 2) as $person) {
$date = $startDate->add(new DateInterval('P' . random_int(1, 200) . 'W'));
$date = $startDate->add(new \DateInterval('P'.\random_int(1, 200).'W'));
$position = $this->getReference(LoadHouseholdPosition::CHILD_OUT);
$movement->addMovement($date, $person, $position, 0 === $k, 'self generated');
@@ -167,7 +159,7 @@ class LoadHousehold extends Fixture implements DependentFixtureInterface
private function getPostalCode(): PostalCode
{
$ref = LoadPostalCodes::$refs[array_rand(LoadPostalCodes::$refs)];
$ref = LoadPostalCodes::$refs[\array_rand(LoadPostalCodes::$refs)];
return $this->getReference($ref);
}
@@ -176,10 +168,10 @@ class LoadHousehold extends Fixture implements DependentFixtureInterface
{
$persons = [];
$nb = random_int($min, $max);
$nb = \random_int($min, $max);
for ($i = 0; $i < $nb; ++$i) {
$personId = array_pop($this->personIds)['id'];
$personId = \array_pop($this->personIds)['id'];
$persons[] = $this->em->getRepository(Person::class)->find($personId);
}
@@ -193,17 +185,17 @@ class LoadHousehold extends Fixture implements DependentFixtureInterface
// @TODO: Remove this and make this service stateless
$this->personIds = $this->em
->createQuery(
'SELECT p.id FROM ' . Person::class . ' p ' .
'WHERE EXISTS( ' .
'SELECT 1 FROM ' . PersonCenterHistory::class . ' pch ' .
'JOIN pch.center c ' .
'WHERE pch.person = p.id ' .
'AND c.name IN (:authorized_centers)' .
'SELECT p.id FROM '.Person::class.' p '.
'WHERE EXISTS( '.
'SELECT 1 FROM '.PersonCenterHistory::class.' pch '.
'JOIN pch.center c '.
'WHERE pch.person = p.id '.
'AND c.name IN (:authorized_centers)'.
')'
)
->setParameter('authorized_centers', $centers)
->getScalarResult();
shuffle($this->personIds);
\shuffle($this->personIds);
}
}

View File

@@ -41,11 +41,11 @@ class LoadMaritalStatus extends AbstractFixture implements OrderedFixtureInterfa
echo "loading maritalStatuses... \n";
foreach ($this->maritalStatuses as $ms) {
echo $ms['name']['en'] . ' ';
echo $ms['name']['en'].' ';
$new_ms = new MaritalStatus();
$new_ms->setId($ms['id']);
$new_ms->setName($ms['name']);
$this->addReference('ms_' . $ms['id'], $new_ms);
$this->addReference('ms_'.$ms['id'], $new_ms);
$manager->persist($new_ms);
}

View File

@@ -12,7 +12,6 @@ declare(strict_types=1);
namespace Chill\PersonBundle\DataFixtures\ORM;
use Chill\MainBundle\DataFixtures\ORM\LoadPostalCodes;
use Chill\MainBundle\Doctrine\Model\Point;
use Chill\MainBundle\Entity\Address;
use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Entity\Country;
@@ -29,13 +28,9 @@ use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
use Chill\PersonBundle\Repository\MaritalStatusRepository;
use Chill\PersonBundle\Repository\SocialWork\SocialIssueRepository;
use DateInterval;
use DateTime;
use DateTimeImmutable;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Persistence\ObjectManager;
use Exception;
use Faker\Factory;
use Faker\Generator;
use Nelmio\Alice\Loader\NativeLoader;
@@ -43,10 +38,6 @@ use Nelmio\Alice\ObjectSet;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\Workflow\Registry;
use function count;
use function random_int;
use function ucfirst;
/**
* Load people into database.
*/
@@ -118,7 +109,7 @@ class LoadPeople extends AbstractFixture implements ContainerAwareInterface, Ord
],
],
[
//to have a person with same firstname as Gérard Depardieu
// to have a person with same firstname as Gérard Depardieu
'lastName' => 'Depardieu',
'firstName' => 'Jean',
'birthdate' => '1960-10-12',
@@ -128,7 +119,7 @@ class LoadPeople extends AbstractFixture implements ContainerAwareInterface, Ord
'maritalStatus' => 'ms_divorce',
],
[
//to have a person with same birthdate of Gérard Depardieu
// to have a person with same birthdate of Gérard Depardieu
'lastName' => 'Van Snick',
'firstName' => 'Bart',
'birthdate' => '1948-12-27',
@@ -136,7 +127,7 @@ class LoadPeople extends AbstractFixture implements ContainerAwareInterface, Ord
'maritalStatus' => 'ms_legalco',
],
[
//to have a woman with Depardieu as FirstName
// to have a woman with Depardieu as FirstName
'lastName' => 'Depardieu',
'firstName' => 'Charline',
'birthdate' => '1970-10-15',
@@ -145,14 +136,14 @@ class LoadPeople extends AbstractFixture implements ContainerAwareInterface, Ord
'maritalStatus' => 'ms_legalco',
],
[
//to have a special character in lastName
// to have a special character in lastName
'lastName' => 'Manço',
'firstName' => 'Étienne',
'center' => 'Center A',
'maritalStatus' => 'ms_unknown',
],
[
//to have true duplicate person
// to have true duplicate person
'lastName' => 'Depardieu',
'firstName' => 'Jean',
'birthdate' => '1960-10-12',
@@ -162,7 +153,7 @@ class LoadPeople extends AbstractFixture implements ContainerAwareInterface, Ord
'maritalStatus' => 'ms_divorce',
],
[
//to have false duplicate person
// to have false duplicate person
'lastName' => 'Depardieu',
'firstName' => 'Jeanne',
'birthdate' => '1966-11-13',
@@ -253,7 +244,7 @@ class LoadPeople extends AbstractFixture implements ContainerAwareInterface, Ord
*/
public function getRandomCenter(): Center
{
if (0 === count($this->cacheCenters)) {
if (0 === \count($this->cacheCenters)) {
$this->cacheCenters = $this->centerRepository->findAll();
}
@@ -263,15 +254,15 @@ class LoadPeople extends AbstractFixture implements ContainerAwareInterface, Ord
/**
* @internal This method is public and called by faker as a custom generator
*
* @throws Exception
* @throws \Exception
*/
public function getRandomCountry(int $nullPercentage = 20): ?Country
{
if (0 === count($this->cacheCountries)) {
if (0 === \count($this->cacheCountries)) {
$this->cacheCountries = $this->countryRepository->findAll();
}
if (random_int(0, 100) > $nullPercentage) {
if (\random_int(0, 100) > $nullPercentage) {
return null;
}
@@ -289,15 +280,15 @@ class LoadPeople extends AbstractFixture implements ContainerAwareInterface, Ord
/**
* @internal This method is public and called by faker as a custom generator
*
* @throws Exception
* @throws \Exception
*/
public function getRandomMaritalStatus(int $nullPercentage = 50): ?MaritalStatus
{
if (0 === count($this->cacheMaritalStatuses)) {
if (0 === \count($this->cacheMaritalStatuses)) {
$this->cacheMaritalStatuses = $this->maritalStatusRepository->findAll();
}
if (random_int(0, 100) > $nullPercentage) {
if (\random_int(0, 100) > $nullPercentage) {
return null;
}
@@ -335,22 +326,22 @@ class LoadPeople extends AbstractFixture implements ContainerAwareInterface, Ord
/**
* create a new person from array data.
*
* @throws Exception
* @throws \Exception
*/
private function addAPerson(Person $person, ObjectManager $manager)
{
$accompanyingPeriod = new AccompanyingPeriod(
(new DateTime())
(new \DateTime())
->sub(
new DateInterval('P' . random_int(0, 180) . 'D')
new \DateInterval('P'.\random_int(0, 180).'D')
)
);
$accompanyingPeriod->setCreatedBy($this->getRandomUser())
->setCreatedAt(new DateTimeImmutable('now'));
->setCreatedAt(new \DateTimeImmutable('now'));
$person->addAccompanyingPeriod($accompanyingPeriod);
$accompanyingPeriod->addSocialIssue($this->getRandomSocialIssue());
if (random_int(0, 10) > 3) {
if (\random_int(0, 10) > 3) {
// always add social scope:
$accompanyingPeriod->addScope($this->getReference('scope_social'));
$origin = $this->getReference(LoadAccompanyingPeriodOrigin::ACCOMPANYING_PERIOD_ORIGIN);
@@ -365,7 +356,7 @@ class LoadPeople extends AbstractFixture implements ContainerAwareInterface, Ord
$manager->persist($person);
$manager->persist($accompanyingPeriod);
$this->addReference(self::PERSON . $person->getId(), $person);
$this->addReference(self::PERSON.$person->getId(), $person);
}
private function createAddress(): Address
@@ -408,7 +399,7 @@ class LoadPeople extends AbstractFixture implements ContainerAwareInterface, Ord
foreach ($default as $key => $value) {
switch ($key) {
case 'birthdate':
$person->setBirthdate(new DateTime($value));
$person->setBirthdate(new \DateTime($value));
break;
@@ -471,7 +462,7 @@ class LoadPeople extends AbstractFixture implements ContainerAwareInterface, Ord
private function getRandomSocialIssue(): SocialIssue
{
if (0 === count($this->cacheSocialIssues)) {
if (0 === \count($this->cacheSocialIssues)) {
$this->cacheSocialIssues = $this->socialIssueRepository->findAll();
}
@@ -480,7 +471,7 @@ class LoadPeople extends AbstractFixture implements ContainerAwareInterface, Ord
private function getRandomUser(): User
{
if (0 === count($this->cacheUsers)) {
if (0 === \count($this->cacheUsers)) {
$this->cacheUsers = $this->userRepository->findAll();
}

View File

@@ -36,7 +36,7 @@ class LoadPersonACL extends AbstractFixture implements OrderedFixtureInterface
$permissionsGroup = $this->getReference($permissionsGroupRef);
$scopeSocial = $this->getReference('scope_social');
//create permission group
// create permission group
switch ($permissionsGroup->getName()) {
case 'social':
case 'direction':

View File

@@ -38,13 +38,13 @@ class LoadRelations extends Fixture implements FixtureGroupInterface
public function load(ObjectManager $manager)
{
foreach (self::RELATIONS as $key => $value) {
echo 'Creating a new relation type: relation' . $value['title']['fr'] . 'reverse relation: ' . $value['reverseTitle']['fr'] . "\n";
echo 'Creating a new relation type: relation'.$value['title']['fr'].'reverse relation: '.$value['reverseTitle']['fr']."\n";
$relation = new Relation();
$relation->setTitle($value['title'])
->setReverseTitle($value['reverseTitle']);
$manager->persist($relation);
$this->addReference(self::RELATION_KEY . $key, $relation);
$this->addReference(self::RELATION_KEY.$key, $relation);
}
$manager->flush();

View File

@@ -15,15 +15,11 @@ use Chill\MainBundle\DataFixtures\ORM\LoadUsers;
use Chill\MainBundle\Entity\User;
use Chill\PersonBundle\DataFixtures\Helper\PersonRandomHelper;
use Chill\PersonBundle\Entity\Relationships\Relationship;
use DateTimeImmutable;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ObjectManager;
use function array_key_exists;
use function count;
class LoadRelationships extends Fixture implements DependentFixtureInterface
{
use PersonRandomHelper;
@@ -45,12 +41,12 @@ class LoadRelationships extends Fixture implements DependentFixtureInterface
for ($i = 0; 20 > $i; ++$i) {
$user = $this->getRandomUser();
$date = new DateTimeImmutable();
$date = new \DateTimeImmutable();
$relationship = (new Relationship())
->setFromPerson($this->getRandomPerson($this->em))
->setToPerson($this->getRandomPerson($this->em))
->setRelation($this->getReference(LoadRelations::RELATION_KEY .
random_int(0, count(LoadRelations::RELATIONS) - 1)))
->setRelation($this->getReference(LoadRelations::RELATION_KEY.
random_int(0, \count(LoadRelations::RELATIONS) - 1)))
->setReverse((bool) random_int(0, 1))
->setCreatedBy($user)
->setUpdatedBy($user)
@@ -63,7 +59,7 @@ class LoadRelationships extends Fixture implements DependentFixtureInterface
max($relationship->getFromPerson()->getId(), $relationship->getToPerson()->getId()),
];
if (array_key_exists($set[0], $existing) && array_key_exists($set[1], $existing[$set[0]])) {
if (\array_key_exists($set[0], $existing) && \array_key_exists($set[1], $existing[$set[0]])) {
continue;
}
$existing[$set[0]][$set[1]] = 1;

View File

@@ -15,9 +15,7 @@ use Chill\PersonBundle\Service\Import\SocialWorkMetadata;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Persistence\ObjectManager;
use Exception;
use League\Csv\Reader;
use Throwable;
class LoadSocialWorkMetadata extends Fixture implements OrderedFixtureInterface
{
@@ -31,9 +29,9 @@ class LoadSocialWorkMetadata extends Fixture implements OrderedFixtureInterface
public function load(ObjectManager $manager)
{
try {
$csv = Reader::createFromPath(__DIR__ . '/data/social_work_metadata.csv');
} catch (Throwable $e) {
throw new Exception('Error while loading CSV.', 0, $e);
$csv = Reader::createFromPath(__DIR__.'/data/social_work_metadata.csv');
} catch (\Throwable $e) {
throw new \Exception('Error while loading CSV.', 0, $e);
}
$csv->setDelimiter(';');