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,33 +1,21 @@
<?php
/*
/**
* Chill is a software for social workers
*
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
*
* 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\ReportBundle\DataFixtures\ORM;
use Chill\CustomFieldsBundle\Entity\CustomField;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Persistence\ObjectManager;
use Chill\CustomFieldsBundle\Entity\CustomField;
/**
* Load CustomField for Report into database
* Load CustomField for Report into database.
*/
class LoadCustomField extends AbstractFixture implements OrderedFixtureInterface
{
@@ -39,53 +27,52 @@ class LoadCustomField extends AbstractFixture implements OrderedFixtureInterface
public function load(ObjectManager $manager)
{
$cFTypes = [
array('type' => 'text', 'options' => array('maxLength' => '255')),
array('type' => 'text', 'options' => array('maxLength' => '1000')),
array('type' => 'text', 'options' => array('maxLength' => '2000')),
array('type' => 'title', 'options' => array('type' => 'title')),
array('type' => 'title', 'options' => array('type' => 'subtitle')),
array('type' => 'choice', 'options' => array(
['type' => 'text', 'options' => ['maxLength' => '255']],
['type' => 'text', 'options' => ['maxLength' => '1000']],
['type' => 'text', 'options' => ['maxLength' => '2000']],
['type' => 'title', 'options' => ['type' => 'title']],
['type' => 'title', 'options' => ['type' => 'subtitle']],
['type' => 'choice', 'options' => [
'multiple' => false,
'expanded'=> false,
'expanded' => false,
'other' => false,
'choices'=> [
array(
'name' => array(
'choices' => [
[
'name' => [
'fr' => 'Options 1 FR',
'nl' => 'Options 1 NL',
'en' => 'Options 1 EN'),
'en' => 'Options 1 EN', ],
'active' => true,
'slug' => 'el-1-fr'),
array(
'name' => array(
'slug' => 'el-1-fr', ],
[
'name' => [
'fr' => 'Options 2 FR',
'nl' => 'Options 2 NL',
'en' => 'Options 2 EN'),
'en' => 'Options 2 EN', ],
'active' => true,
'slug' => 'el-2-fr'),
array(
'name' => array(
'slug' => 'el-2-fr', ],
[
'name' => [
'fr' => 'Options 2 FR',
'nl' => 'Options 2 NL',
'en' => 'Options 2 EN'),
'en' => 'Options 2 EN', ],
'active' => true,
'slug' => 'el-3-fr')
]
)
)
'slug' => 'el-3-fr', ],
],
],
],
];
for($i=0; $i <= 25; $i++) {
$cFType = $cFTypes[rand(0,sizeof($cFTypes) - 1)];
for ($i = 0; 25 >= $i; ++$i) {
$cFType = $cFTypes[rand(0, sizeof($cFTypes) - 1)];
$customField = (new CustomField())
->setSlug("cf_report_{$i}")
->setType($cFType['type'])
->setOptions($cFType['options'])
->setName(array("fr" => "CustomField {$i}"))
->setOrdering(rand(0,1000) / 1000)
->setCustomFieldsGroup($this->getReference('cf_group_report_'.(rand(0,3))))
;
->setName(['fr' => "CustomField {$i}"])
->setOrdering(rand(0, 1000) / 1000)
->setCustomFieldsGroup($this->getReference('cf_group_report_' . (rand(0, 3))));
$manager->persist($customField);
}
@@ -101,119 +88,108 @@ class LoadCustomField extends AbstractFixture implements OrderedFixtureInterface
$reportLogement = $this->getReference('cf_group_report_logement');
$houseTitle = (new CustomField())
->setSlug('house_title')
->setType('title')
->setOptions(array('type' => 'title'))
->setName(array('fr' => 'Situation de logement'))
->setOrdering(10)
->setCustomFieldsGroup($reportLogement)
;
->setSlug('house_title')
->setType('title')
->setOptions(['type' => 'title'])
->setName(['fr' => 'Situation de logement'])
->setOrdering(10)
->setCustomFieldsGroup($reportLogement);
$manager->persist($houseTitle);
$hasLogement = (new CustomField())
->setSlug('has_logement')
->setName(array('fr' => 'Logement actuel'))
->setType('choice')
->setOptions(array(
'multiple' => FALSE,
'expanded' => TRUE,
'other' => TRUE,
'choices' => [
array(
'name' => ['fr' => 'Locataire d\' un logement'],
'slug' => 'rent_house',
'active' => true
),
array(
'name' => ['fr' => 'Propriétaire d\' un logement'],
'slug' => 'own_house',
'active' => true
),
array(
'name' => ['fr' => 'Par-ci, par là (amis, famille, ...)'],
'slug' => 'here-and-there',
'active' => true
),
array(
'name' => ['fr' => 'A la rue'],
'slug' => 'street',
'active' => true
)
]
))
->setOrdering(20)
->setCustomFieldsGroup($reportLogement)
;
->setSlug('has_logement')
->setName(['fr' => 'Logement actuel'])
->setType('choice')
->setOptions([
'multiple' => false,
'expanded' => true,
'other' => true,
'choices' => [
[
'name' => ['fr' => 'Locataire d\' un logement'],
'slug' => 'rent_house',
'active' => true,
],
[
'name' => ['fr' => 'Propriétaire d\' un logement'],
'slug' => 'own_house',
'active' => true,
],
[
'name' => ['fr' => 'Par-ci, par là (amis, famille, ...)'],
'slug' => 'here-and-there',
'active' => true,
],
[
'name' => ['fr' => 'A la rue'],
'slug' => 'street',
'active' => true,
],
],
])
->setOrdering(20)
->setCustomFieldsGroup($reportLogement);
$manager->persist($hasLogement);
$descriptionLogement = (new CustomField())
->setSlug('house-desc')
->setName(array('fr' => 'Plaintes éventuelles sur le logement'))
->setType('text')
->setOptions(['maxLength' => 1500])
->setOrdering(30)
->setCustomFieldsGroup($reportLogement)
;
->setSlug('house-desc')
->setName(['fr' => 'Plaintes éventuelles sur le logement'])
->setType('text')
->setOptions(['maxLength' => 1500])
->setOrdering(30)
->setCustomFieldsGroup($reportLogement);
$manager->persist($descriptionLogement);
//report problems
$reportEducation = $this->getReference('cf_group_report_education');
$title = (new CustomField())
->setSlug('title')
->setType('title')
->setOptions(array('type' => 'title'))
->setName(array('fr' => 'Éducation'))
->setOrdering(10)
->setCustomFieldsGroup($reportEducation)
;
->setSlug('title')
->setType('title')
->setOptions(['type' => 'title'])
->setName(['fr' => 'Éducation'])
->setOrdering(10)
->setCustomFieldsGroup($reportEducation);
$manager->persist($title);
$educationLevel = (new CustomField())
->setSlug('level')
->setName(array('fr' => 'Niveau du plus haut diplôme'))
->setType('choice')
->setOptions(array(
'multiple' => FALSE,
'expanded' => FALSE,
'other' => FALSE,
'choices' => [
array(
'name' => ['fr' => 'Supérieur'],
'slug' => 'superieur',
'active' => true
),
array(
'name' => ['fr' => 'Secondaire supérieur (CESS)'],
'slug' => 'cess',
'active' => true
),
array(
'name' => ['fr' => 'Secondaire deuxième degré ou inférieur (C2D)'],
'slug' => 'c2d',
'active' => true
),
array(
'name' => ['fr' => 'Primaire'],
'slug' => 'low',
'active' => true
),
array(
'name' => ['fr' => 'Aucun diplome'],
'slug' => 'no',
'active' => true
)
]
))
->setOrdering(20)
->setCustomFieldsGroup($reportEducation)
;
->setSlug('level')
->setName(['fr' => 'Niveau du plus haut diplôme'])
->setType('choice')
->setOptions([
'multiple' => false,
'expanded' => false,
'other' => false,
'choices' => [
[
'name' => ['fr' => 'Supérieur'],
'slug' => 'superieur',
'active' => true,
],
[
'name' => ['fr' => 'Secondaire supérieur (CESS)'],
'slug' => 'cess',
'active' => true,
],
[
'name' => ['fr' => 'Secondaire deuxième degré ou inférieur (C2D)'],
'slug' => 'c2d',
'active' => true,
],
[
'name' => ['fr' => 'Primaire'],
'slug' => 'low',
'active' => true,
],
[
'name' => ['fr' => 'Aucun diplome'],
'slug' => 'no',
'active' => true,
],
],
])
->setOrdering(20)
->setCustomFieldsGroup($reportEducation);
$manager->persist($educationLevel);
}
}

View File

@@ -1,33 +1,21 @@
<?php
/*
* Chill is a software for social workers
/**
* Chill is a software for social workers
*
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
*
* 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\ReportBundle\DataFixtures\ORM;
use Chill\CustomFieldsBundle\Entity\CustomFieldsGroup;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Persistence\ObjectManager;
use Chill\CustomFieldsBundle\Entity\CustomFieldsGroup;
/**
* Load CustomFieldsGroup for Report into database
* Load CustomFieldsGroup for Report into database.
*/
class LoadCustomFieldsGroup extends AbstractFixture implements OrderedFixtureInterface
{
@@ -35,55 +23,53 @@ class LoadCustomFieldsGroup extends AbstractFixture implements OrderedFixtureInt
{
return 15000;
}
public function load(ObjectManager $manager)
{
echo "loading customFieldsGroup...\n";
$report = $this->createReport($manager,
array('fr' => 'Situation de logement'),
['summary_fields' => ['has_logement', 'house-desc']]);
$report = $this->createReport(
$manager,
['fr' => 'Situation de logement'],
['summary_fields' => ['has_logement', 'house-desc']]
);
$this->addReference(
'cf_group_report_logement',
$report
);
$report = $this->createReport($manager, array('fr' => 'Alphabétisme'));
'cf_group_report_logement',
$report
);
$report = $this->createReport($manager, ['fr' => 'Alphabétisme']);
$this->addReference('cf_group_report_education', $report);
for($i=0; $i <= 3; $i++) {
$report = $this->createReport($manager, array('fr' => 'ZZ Rapport aléatoire '.$i));
for ($i = 0; 3 >= $i; ++$i) {
$report = $this->createReport($manager, ['fr' => 'ZZ Rapport aléatoire ' . $i]);
$this->addReference('cf_group_report_'.$i, $report);
$this->addReference('cf_group_report_' . $i, $report);
}
$manager->flush();
}
/**
* create a report and persist in the db
*
* @param ObjectManager $manager
* @param array $name
* create a report and persist in the db.
*
* @return CustomFieldsGroup
*/
private function createReport(
ObjectManager $manager,
array $name,
array $options = array())
ObjectManager $manager,
array $name,
array $options = []
)
{
echo $name['fr']." \n";
echo $name['fr'] . " \n";
$cFGroup = (new CustomFieldsGroup())
->setName($name)
->setEntity('Chill\ReportBundle\Entity\Report')
->setOptions($options);
$manager->persist($cFGroup);
return $cFGroup;
}
}
}

View File

@@ -1,36 +1,24 @@
<?php
/*
* Copyright (C) 2015 Julien Fastré <julien.fastre@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\ReportBundle\DataFixtures\ORM;
use Chill\MainBundle\DataFixtures\ORM\LoadPermissionsGroup;
use Chill\MainBundle\DataFixtures\ORM\LoadScopes;
use Chill\MainBundle\Entity\RoleScope;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Persistence\ObjectManager;
use Chill\MainBundle\DataFixtures\ORM\LoadPermissionsGroup;
use Chill\MainBundle\Entity\RoleScope;
use Chill\MainBundle\DataFixtures\ORM\LoadScopes;
/**
* Add a role CHILL_REPORT_UPDATE & CHILL_REPORT_CREATE for all groups except administrative,
* and a role CHILL_REPORT_SEE for administrative
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
* and a role CHILL_REPORT_SEE for administrative.
*/
class LoadReportACL extends AbstractFixture implements OrderedFixtureInterface
{
@@ -39,13 +27,13 @@ class LoadReportACL extends AbstractFixture implements OrderedFixtureInterface
return 14999;
}
public function load(ObjectManager $manager)
{
foreach (LoadPermissionsGroup::$refs as $permissionsGroupRef) {
$permissionsGroup = $this->getReference($permissionsGroupRef);
printf("processing permission group %s \n", $permissionsGroup->getName());
foreach (LoadScopes::$references as $scopeRef){
foreach (LoadScopes::$references as $scopeRef) {
$scope = $this->getReference($scopeRef);
printf("processing scope %s \n", $scope->getName()['en']);
//create permission group
@@ -53,36 +41,42 @@ class LoadReportACL extends AbstractFixture implements OrderedFixtureInterface
case 'social':
if ($scope->getName()['en'] === 'administrative') {
printf("denying power on administrative \n");
break 2; // we do not want any power on administrative
}
break;
case 'administrative':
case 'direction':
if (in_array($scope->getName()['en'], array('administrative', 'social'))) {
if (in_array($scope->getName()['en'], ['administrative', 'social'])) {
printf("denying power on %s\n", $scope->getName()['en']);
break 2; // we do not want any power on social or administrative
}
}
break;
}
printf("Adding CHILL_REPORT_UPDATE & CHILL_REPORT_CREATE to %s "
. "permission group, scope '%s' \n",
$permissionsGroup->getName(), $scope->getName()['en']);
printf(
'Adding CHILL_REPORT_UPDATE & CHILL_REPORT_CREATE to %s '
. "permission group, scope '%s' \n",
$permissionsGroup->getName(),
$scope->getName()['en']
);
$roleScopeUpdate = (new RoleScope())
->setRole('CHILL_REPORT_UPDATE')
->setScope($scope);
->setRole('CHILL_REPORT_UPDATE')
->setScope($scope);
$permissionsGroup->addRoleScope($roleScopeUpdate);
$roleScopeCreate = (new RoleScope())
->setRole('CHILL_REPORT_CREATE')
->setScope($scope);
->setRole('CHILL_REPORT_CREATE')
->setScope($scope);
$permissionsGroup->addRoleScope($roleScopeCreate);
$manager->persist($roleScopeUpdate);
$manager->persist($roleScopeCreate);
}
}
$manager->flush();
}
}

View File

@@ -1,46 +1,33 @@
<?php
/*
* Chill is a suite of a modules, Chill is a software for social workers
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.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\ReportBundle\DataFixtures\ORM;
use Chill\CustomFieldsBundle\Entity\CustomField;
use Chill\MainBundle\DataFixtures\ORM\LoadScopes;
use Chill\MainBundle\DataFixtures\ORM\LoadUsers;
use Chill\ReportBundle\Entity\Report;
use DateTime;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Persistence\ObjectManager;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Chill\ReportBundle\Entity\Report;
use Chill\MainBundle\DataFixtures\ORM\LoadUsers;
use Faker\Factory as FakerFactory;
use Chill\CustomFieldsBundle\Entity\CustomField;
use Chill\MainBundle\DataFixtures\ORM\LoadScopes;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
/**
* Load reports into DB
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
* Load reports into DB.
*/
class LoadReports extends AbstractFixture implements OrderedFixtureInterface, ContainerAwareInterface
{
use \Symfony\Component\DependencyInjection\ContainerAwareTrait;
/**
*
* @var \Faker\Generator
*/
private $faker;
@@ -66,6 +53,26 @@ class LoadReports extends AbstractFixture implements OrderedFixtureInterface, Co
$manager->flush();
}
private function createExpected(ObjectManager $manager)
{
$charline = $this->container->get('doctrine.orm.entity_manager')
->getRepository('ChillPersonBundle:Person')
->findOneBy(['firstName' => 'Charline', 'lastName' => 'DEPARDIEU']);
if (null !== $charline) {
$report = (new Report())
->setPerson($charline)
->setCFGroup($this->getReference('cf_group_report_logement'))
->setDate(new DateTime('2015-01-05'))
->setScope($this->getReference('scope_social'));
$this->fillReport($report);
$manager->persist($report);
} else {
echo 'WARNING: Charline DEPARDIEU not found in database';
}
}
private function createRandom(ObjectManager $manager, $percentage)
{
$people = $this->getPeopleRandom($percentage);
@@ -73,100 +80,57 @@ class LoadReports extends AbstractFixture implements OrderedFixtureInterface, Co
foreach ($people as $person) {
//create a report, set logement or education report
$report = (new Report())
->setPerson($person)
->setCFGroup(rand(0,10) > 5 ?
->setPerson($person)
->setCFGroup(
rand(0, 10) > 5 ?
$this->getReference('cf_group_report_logement') :
$this->getReference('cf_group_report_education')
)
->setScope($this->getScopeRandom())
;
)
->setScope($this->getScopeRandom());
$this->fillReport($report);
$manager->persist($report);
}
}
private function createExpected(ObjectManager $manager)
{
$charline = $this->container->get('doctrine.orm.entity_manager')
->getRepository('ChillPersonBundle:Person')
->findOneBy(array('firstName' => 'Charline', 'lastName' => 'DEPARDIEU'))
;
if (NULL !== $charline) {
$report = (new Report())
->setPerson($charline)
->setCFGroup($this->getReference('cf_group_report_logement'))
->setDate(new \DateTime('2015-01-05'))
->setScope($this->getReference('scope_social'))
;
$this->fillReport($report);
$manager->persist($report);
} else {
print("WARNING: Charline DEPARDIEU not found in database");
}
}
/**
*
* @return \Chill\MainBundle\Entity\Scope
*/
private function getScopeRandom()
{
$ref = LoadScopes::$references[array_rand(LoadScopes::$references)];
return $this->getReference($ref);
}
private function getPeopleRandom($percentage)
{
$people = $this->container->get('doctrine.orm.entity_manager')
->getRepository('ChillPersonBundle:Person')
->findAll()
;
//keep only a part ($percentage) of the people
$selectedPeople = array();
foreach($people as $person) {
if (rand(0,100) < $percentage) {
$selectedPeople[] = $person;
}
}
return $selectedPeople;
}
private function fillReport(Report $report)
{
//setUser
$usernameRef = array_rand(LoadUsers::$refs);
$report->setUser(
$this->getReference($usernameRef)
);
$this->getReference($usernameRef)
);
//set date if null
if ($report->getDate() === NULL) {
if ($report->getDate() === null) {
//set date. 30% of the dates are 2015-05-01
$expectedDate = new \DateTime('2015-01-05');
if (rand(0,100) < 30) {
$expectedDate = new DateTime('2015-01-05');
if (rand(0, 100) < 30) {
$report->setDate($expectedDate);
} else {
$report->setDate($this->faker->dateTimeBetween('-1 year', 'now')
->setTime(0, 0, 0));
->setTime(0, 0, 0));
}
}
//fill data
$datas = array();
$datas = [];
foreach ($report->getCFGroup()->getCustomFields() as $field) {
switch ($field->getType()) {
case 'title' :
$datas[$field->getSlug()] = array();
case 'title':
$datas[$field->getSlug()] = [];
break;
case 'choice' :
case 'choice':
$datas[$field->getSlug()] = $this->getRandomChoice($field);
break;
case 'text' :
case 'text':
$datas[$field->getSlug()] = $this->faker->realText($field->getOptions()['maxLength']);
break;
}
}
@@ -175,11 +139,28 @@ class LoadReports extends AbstractFixture implements OrderedFixtureInterface, Co
return $report;
}
private function getPeopleRandom($percentage)
{
$people = $this->container->get('doctrine.orm.entity_manager')
->getRepository('ChillPersonBundle:Person')
->findAll();
//keep only a part ($percentage) of the people
$selectedPeople = [];
foreach ($people as $person) {
if (rand(0, 100) < $percentage) {
$selectedPeople[] = $person;
}
}
return $selectedPeople;
}
/**
* pick a random choice
* pick a random choice.
*
* @param CustomField $field
* @return string[]|string the array of slug if multiple, a single slug otherwise
* @return string|string[] the array of slug if multiple, a single slug otherwise
*/
private function getRandomChoice(CustomField $field)
{
@@ -188,21 +169,22 @@ class LoadReports extends AbstractFixture implements OrderedFixtureInterface, Co
$other = $field->getOptions()['other'];
//add other if allowed
if($other) {
$choices[] = array('slug' => '_other');
if ($other) {
$choices[] = ['slug' => '_other'];
}
//initialize results
$picked = array();
$picked = [];
if ($multiple) {
$numberSelected = rand(1, count($choices) -1);
for ($i = 0; $i < $numberSelected; $i++) {
$numberSelected = rand(1, count($choices) - 1);
for ($i = 0; $i < $numberSelected; ++$i) {
$picked[] = $this->pickChoice($choices);
}
if ($other) {
$result = array("_other" => NULL, "_choices" => $picked);
$result = ['_other' => null, '_choices' => $picked];
if (in_array('_other', $picked)) {
$result['_other'] = $this->faker->realText(70);
@@ -210,35 +192,38 @@ class LoadReports extends AbstractFixture implements OrderedFixtureInterface, Co
return $result;
}
} else {
$picked = $this->pickChoice($choices);
if ($other) {
$result = array('_other' => NULL, '_choices' => $picked);
$result = ['_other' => null, '_choices' => $picked];
if ($picked === '_other') {
if ('_other' === $picked) {
$result['_other'] = $this->faker->realText(70);
}
return $result;
}
}
}
/**
* pick a choice within a 'choices' options (for choice type)
* @return \Chill\MainBundle\Entity\Scope
*/
private function getScopeRandom()
{
$ref = LoadScopes::$references[array_rand(LoadScopes::$references)];
return $this->getReference($ref);
}
/**
* pick a choice within a 'choices' options (for choice type).
*
* @param array $choices
* @return the slug of the selected choice
*/
private function pickChoice(array $choices)
{
return $choices[array_rand($choices)]['slug'];
}
}