mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
cs: Fix code style (safe rules only).
This commit is contained in:
@@ -1,21 +1,38 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\ThirdPartyBundle\DataFixtures\ORM;
|
||||
|
||||
use Chill\MainBundle\DataFixtures\ORM\LoadCenters;
|
||||
use Chill\MainBundle\DataFixtures\ORM\LoadPostalCodes;
|
||||
use Chill\MainBundle\Entity\Address;
|
||||
use Chill\MainBundle\Entity\PostalCode;
|
||||
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Iterator;
|
||||
use Nelmio\Alice\Loader\NativeLoader;
|
||||
use Nelmio\Alice\ObjectSet;
|
||||
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
||||
use Chill\MainBundle\Entity\Address;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use function array_map;
|
||||
|
||||
class LoadThirdParty extends Fixture Implements DependentFixtureInterface
|
||||
class LoadThirdParty extends Fixture implements DependentFixtureInterface
|
||||
{
|
||||
public function getDependencies()
|
||||
{
|
||||
return [
|
||||
LoadCenters::class,
|
||||
LoadPostalCodes::class,
|
||||
];
|
||||
}
|
||||
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
$thirdParties = $this->getThirdParties()->getObjects();
|
||||
@@ -25,10 +42,10 @@ class LoadThirdParty extends Fixture Implements DependentFixtureInterface
|
||||
// this is an address
|
||||
continue;
|
||||
}
|
||||
$thirdParty->setCreatedAt(new \DateTimeImmutable('today'));
|
||||
$thirdParty->setCreatedAt(new DateTimeImmutable('today'));
|
||||
|
||||
foreach ($this->getCenters() as $center) {
|
||||
$thirdParty->addCenter($center);
|
||||
$thirdParty->addCenter($center);
|
||||
}
|
||||
|
||||
$manager->persist($thirdParty);
|
||||
@@ -37,13 +54,31 @@ class LoadThirdParty extends Fixture Implements DependentFixtureInterface
|
||||
$manager->flush();
|
||||
}
|
||||
|
||||
private function getCenters(): \Iterator
|
||||
private function createAddress(): ObjectSet
|
||||
{
|
||||
$references = \array_map(function($a) { return $a['ref']; },
|
||||
LoadCenters::$centers);
|
||||
$loader = new NativeLoader();
|
||||
|
||||
return $loader->loadData([
|
||||
Address::class => [
|
||||
'address1' => [
|
||||
'name' => '<fr_FR:company()>',
|
||||
'telephone' => '<fr_FR:phonenumber()>',
|
||||
'email' => '<email()>',
|
||||
'comment' => '<fr_FR:realTextBetween(10, 500)>',
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
private function getCenters(): Iterator
|
||||
{
|
||||
$references = array_map(
|
||||
function ($a) { return $a['ref']; },
|
||||
LoadCenters::$centers
|
||||
);
|
||||
$number = random_int(1, count($references));
|
||||
|
||||
if ($number === 1) {
|
||||
if (1 === $number) {
|
||||
yield $this->getReference($references[\array_rand($references)]);
|
||||
} else {
|
||||
foreach (array_rand($references, $number) as $index) {
|
||||
@@ -52,40 +87,6 @@ class LoadThirdParty extends Fixture Implements DependentFixtureInterface
|
||||
}
|
||||
}
|
||||
|
||||
public function getDependencies()
|
||||
{
|
||||
return [
|
||||
LoadCenters::class,
|
||||
LoadPostalCodes::class
|
||||
];
|
||||
}
|
||||
|
||||
private function getThirdParties(): ObjectSet
|
||||
{
|
||||
$loader = new NativeLoader();
|
||||
$objectSet = $loader->loadData([
|
||||
Address::class => [
|
||||
'address{1..75}' => [
|
||||
'street' => '<fr_FR:streetName()>',
|
||||
'streetNumber' => '<fr_FR:buildingNumber()>',
|
||||
'validFrom' => '<dateTimeBetween(\'-1 year\', \'now\')>',
|
||||
'postCode' => $this->getPostalCode()
|
||||
],
|
||||
],
|
||||
ThirdParty::class => [
|
||||
'thirdparty{1..75}' => [
|
||||
'name' => '<fr_FR:company()>',
|
||||
'telephone' => '<fr_FR:phonenumber()>',
|
||||
'email' => '<email()>',
|
||||
'comment' => '<fr_FR:realTextBetween(10, 500)>',
|
||||
'address' => '@address<current()>'
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
||||
return $objectSet;
|
||||
}
|
||||
|
||||
private function getPostalCode(): PostalCode
|
||||
{
|
||||
$ref = LoadPostalCodes::$refs[\array_rand(LoadPostalCodes::$refs)];
|
||||
@@ -93,22 +94,28 @@ class LoadThirdParty extends Fixture Implements DependentFixtureInterface
|
||||
return $this->getReference($ref);
|
||||
}
|
||||
|
||||
private function createAddress(): ObjectSet
|
||||
private function getThirdParties(): ObjectSet
|
||||
{
|
||||
$loader = new NativeLoader();
|
||||
$objectSet = $loader->loadData([
|
||||
|
||||
return $loader->loadData([
|
||||
Address::class => [
|
||||
'address1' => [
|
||||
'address{1..75}' => [
|
||||
'street' => '<fr_FR:streetName()>',
|
||||
'streetNumber' => '<fr_FR:buildingNumber()>',
|
||||
'validFrom' => '<dateTimeBetween(\'-1 year\', \'now\')>',
|
||||
'postCode' => $this->getPostalCode(),
|
||||
],
|
||||
],
|
||||
ThirdParty::class => [
|
||||
'thirdparty{1..75}' => [
|
||||
'name' => '<fr_FR:company()>',
|
||||
'telephone' => '<fr_FR:phonenumber()>',
|
||||
'email' => '<email()>',
|
||||
'comment' => '<fr_FR:realTextBetween(10, 500)>'
|
||||
]
|
||||
]
|
||||
'comment' => '<fr_FR:realTextBetween(10, 500)>',
|
||||
'address' => '@address<current()>',
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
return $objectSet;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user