mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
fix: SA: Fix "incorrect case" rule.
SA stands for Static Analysis.
This commit is contained in:
parent
196cddab09
commit
a7b96f1756
@ -170,11 +170,6 @@ parameters:
|
|||||||
count: 1
|
count: 1
|
||||||
path: src/Bundle/ChillCalendarBundle/Entity/Calendar.php
|
path: src/Bundle/ChillCalendarBundle/Entity/Calendar.php
|
||||||
|
|
||||||
-
|
|
||||||
message: "#^Class RuntimeException referenced with incorrect case\\: RunTimeException\\.$#"
|
|
||||||
count: 5
|
|
||||||
path: src/Bundle/ChillCustomFieldsBundle/Command/CreateFieldsOnGroupCommand.php
|
|
||||||
|
|
||||||
-
|
-
|
||||||
message: "#^Only booleans are allowed in an if condition, mixed given\\.$#"
|
message: "#^Only booleans are allowed in an if condition, mixed given\\.$#"
|
||||||
count: 1
|
count: 1
|
||||||
@ -685,11 +680,6 @@ parameters:
|
|||||||
count: 1
|
count: 1
|
||||||
path: src/Bundle/ChillMainBundle/Export/Formatter/CSVFormatter.php
|
path: src/Bundle/ChillMainBundle/Export/Formatter/CSVFormatter.php
|
||||||
|
|
||||||
-
|
|
||||||
message: "#^Call to method Chill\\\\MainBundle\\\\Export\\\\Formatter\\\\SpreadSheetFormatter\\:\\:generateContent\\(\\) with incorrect case\\: generatecontent$#"
|
|
||||||
count: 1
|
|
||||||
path: src/Bundle/ChillMainBundle/Export/Formatter/SpreadSheetFormatter.php
|
|
||||||
|
|
||||||
-
|
-
|
||||||
message: "#^Foreach overwrites \\$key with its key variable\\.$#"
|
message: "#^Foreach overwrites \\$key with its key variable\\.$#"
|
||||||
count: 1
|
count: 1
|
||||||
@ -1020,11 +1010,6 @@ parameters:
|
|||||||
count: 1
|
count: 1
|
||||||
path: src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php
|
path: src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php
|
||||||
|
|
||||||
-
|
|
||||||
message: "#^Call to method Chill\\\\PersonBundle\\\\Entity\\\\AccompanyingPeriod\\:\\:getOpenParticipations\\(\\) with incorrect case\\: getOPenParticipations$#"
|
|
||||||
count: 2
|
|
||||||
path: src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php
|
|
||||||
|
|
||||||
-
|
-
|
||||||
message: "#^Implicit array creation is not allowed \\- variable \\$centers might not exist\\.$#"
|
message: "#^Implicit array creation is not allowed \\- variable \\$centers might not exist\\.$#"
|
||||||
count: 1
|
count: 1
|
||||||
|
@ -45,25 +45,25 @@ class CreateFieldsOnGroupCommand extends Command
|
|||||||
{
|
{
|
||||||
const ARG_PATH = 'path';
|
const ARG_PATH = 'path';
|
||||||
const ARG_DELETE = 'delete';
|
const ARG_DELETE = 'delete';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var CustomFieldProvider
|
* @var CustomFieldProvider
|
||||||
*/
|
*/
|
||||||
private $customFieldProvider;
|
private $customFieldProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var EntityManager
|
* @var EntityManager
|
||||||
*/
|
*/
|
||||||
private $entityManager;
|
private $entityManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var ValidatorInterface
|
* @var ValidatorInterface
|
||||||
*/
|
*/
|
||||||
private $validator;
|
private $validator;
|
||||||
|
|
||||||
private $availableLanguages;
|
private $availableLanguages;
|
||||||
private $customizablesEntities;
|
private $customizablesEntities;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CreateFieldsOnGroupCommand constructor.
|
* CreateFieldsOnGroupCommand constructor.
|
||||||
*
|
*
|
||||||
@ -87,7 +87,7 @@ class CreateFieldsOnGroupCommand extends Command
|
|||||||
$this->customizablesEntities = $customizablesEntities;
|
$this->customizablesEntities = $customizablesEntities;
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function configure()
|
protected function configure()
|
||||||
{
|
{
|
||||||
$this->setName('chill:custom_fields:populate_group')
|
$this->setName('chill:custom_fields:populate_group')
|
||||||
@ -111,7 +111,7 @@ class CreateFieldsOnGroupCommand extends Command
|
|||||||
$em->remove($field);
|
$em->remove($field);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param InputInterface $input
|
* @param InputInterface $input
|
||||||
* @param OutputInterface $output
|
* @param OutputInterface $output
|
||||||
@ -120,18 +120,18 @@ class CreateFieldsOnGroupCommand extends Command
|
|||||||
protected function execute(InputInterface $input, OutputInterface $output)
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
{
|
{
|
||||||
$helper = $this->getHelperSet()->get('question');
|
$helper = $this->getHelperSet()->get('question');
|
||||||
|
|
||||||
$em = $this->entityManager;
|
$em = $this->entityManager;
|
||||||
|
|
||||||
$customFieldsGroups = $em
|
$customFieldsGroups = $em
|
||||||
->getRepository('ChillCustomFieldsBundle:CustomFieldsGroup')
|
->getRepository('ChillCustomFieldsBundle:CustomFieldsGroup')
|
||||||
->findAll();
|
->findAll();
|
||||||
|
|
||||||
if (count($customFieldsGroups) === 0) {
|
if (count($customFieldsGroups) === 0) {
|
||||||
$output->writeln('<error>There aren\'t any CustomFieldsGroup recorded'
|
$output->writeln('<error>There aren\'t any CustomFieldsGroup recorded'
|
||||||
. ' Please create at least one.</error>');
|
. ' Please create at least one.</error>');
|
||||||
}
|
}
|
||||||
|
|
||||||
$table = new Table($output);
|
$table = new Table($output);
|
||||||
$table
|
$table
|
||||||
->setHeaders(array_merge(
|
->setHeaders(array_merge(
|
||||||
@ -141,7 +141,7 @@ class CreateFieldsOnGroupCommand extends Command
|
|||||||
->setRows($this->_prepareRows($customFieldsGroups))
|
->setRows($this->_prepareRows($customFieldsGroups))
|
||||||
->render()
|
->render()
|
||||||
;
|
;
|
||||||
|
|
||||||
$question = new Question(
|
$question = new Question(
|
||||||
"Enter the customfieldGroup's id on which the custom fields should be added: ");
|
"Enter the customfieldGroup's id on which the custom fields should be added: ");
|
||||||
$question->setNormalizer(
|
$question->setNormalizer(
|
||||||
@ -151,24 +151,23 @@ class CreateFieldsOnGroupCommand extends Command
|
|||||||
return $customFieldsGroup;
|
return $customFieldsGroup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new \RunTimeException('The id does not match an existing '
|
throw new \RuntimeException('The id does not match an existing CustomFieldsGroup');
|
||||||
. 'CustomFieldsGroup');
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
$customFieldsGroup = $helper->ask($input, $output, $question);
|
$customFieldsGroup = $helper->ask($input, $output, $question);
|
||||||
|
|
||||||
|
|
||||||
if ($input->getOption(self::ARG_DELETE)) {
|
if ($input->getOption(self::ARG_DELETE)) {
|
||||||
$this->deleteFieldsForCFGroup($customFieldsGroup);
|
$this->deleteFieldsForCFGroup($customFieldsGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
$fieldsInput = $this->_parse($input->getArgument(self::ARG_PATH),
|
$fieldsInput = $this->_parse($input->getArgument(self::ARG_PATH),
|
||||||
$output);
|
$output);
|
||||||
|
|
||||||
$fields = $this->_addFields($customFieldsGroup, $fieldsInput, $output);
|
$fields = $this->_addFields($customFieldsGroup, $fieldsInput, $output);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function _prepareRows ($customFieldsGroups)
|
private function _prepareRows ($customFieldsGroups)
|
||||||
{
|
{
|
||||||
$rows = array();
|
$rows = array();
|
||||||
$languages = $this->availableLanguages;
|
$languages = $this->availableLanguages;
|
||||||
@ -177,8 +176,8 @@ class CreateFieldsOnGroupCommand extends Command
|
|||||||
foreach ($this->customizablesEntities as $entry) {
|
foreach ($this->customizablesEntities as $entry) {
|
||||||
$customizableEntities[$entry['class']] = $entry['name'];
|
$customizableEntities[$entry['class']] = $entry['name'];
|
||||||
}
|
}
|
||||||
|
|
||||||
array_walk($customFieldsGroups,
|
array_walk($customFieldsGroups,
|
||||||
function(CustomFieldsGroup $customFieldGroup, $key)
|
function(CustomFieldsGroup $customFieldGroup, $key)
|
||||||
use ($languages, &$rows, $customizableEntities) {
|
use ($languages, &$rows, $customizableEntities) {
|
||||||
//set id and entity
|
//set id and entity
|
||||||
@ -186,7 +185,7 @@ class CreateFieldsOnGroupCommand extends Command
|
|||||||
$customFieldGroup->getId(),
|
$customFieldGroup->getId(),
|
||||||
$customizableEntities[$customFieldGroup->getEntity()]
|
$customizableEntities[$customFieldGroup->getEntity()]
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ($languages as $lang) {
|
foreach ($languages as $lang) {
|
||||||
//todo replace with service to find lang when available
|
//todo replace with service to find lang when available
|
||||||
$row[] = (isset($customFieldGroup->getName()[$lang])) ?
|
$row[] = (isset($customFieldGroup->getName()[$lang])) ?
|
||||||
@ -196,42 +195,42 @@ class CreateFieldsOnGroupCommand extends Command
|
|||||||
$rows[] = $row;
|
$rows[] = $row;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
return $rows;
|
return $rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function _parse($path, OutputInterface $output)
|
private function _parse($path, OutputInterface $output)
|
||||||
{
|
{
|
||||||
$parser = new Parser();
|
$parser = new Parser();
|
||||||
|
|
||||||
if (!file_exists($path)) {
|
if (!file_exists($path)) {
|
||||||
throw new \RunTimeException("file does not exist");
|
throw new \RuntimeException("file does not exist");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$values = $parser->parse(file_get_contents($path));
|
$values = $parser->parse(file_get_contents($path));
|
||||||
} catch (ParseException $ex) {
|
} catch (ParseException $ex) {
|
||||||
throw new \RunTimeException("The yaml file is not valid", 0, $ex);
|
throw new \RuntimeException("The yaml file is not valid", 0, $ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $values;
|
return $values;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function _addFields(CustomFieldsGroup $group, $values, OutputInterface $output)
|
private function _addFields(CustomFieldsGroup $group, $values, OutputInterface $output)
|
||||||
{
|
{
|
||||||
|
|
||||||
$em = $this->entityManager;
|
$em = $this->entityManager;
|
||||||
|
|
||||||
$languages = $this->availableLanguages;
|
$languages = $this->availableLanguages;
|
||||||
|
|
||||||
foreach($values['fields'] as $slug => $field) {
|
foreach($values['fields'] as $slug => $field) {
|
||||||
//check the cf type exists
|
//check the cf type exists
|
||||||
$cfType = $this->customFieldProvider->getCustomFieldByType($field['type']);
|
$cfType = $this->customFieldProvider->getCustomFieldByType($field['type']);
|
||||||
if ($cfType === NULL) {
|
if ($cfType === NULL) {
|
||||||
throw new \RunTimeException('the type '.$field['type'].' '
|
throw new \RuntimeException('the type '.$field['type'].' '
|
||||||
. 'does not exists');
|
. 'does not exists');
|
||||||
}
|
}
|
||||||
|
|
||||||
$cf = new CustomField();
|
$cf = new CustomField();
|
||||||
$cf->setSlug($slug)
|
$cf->setSlug($slug)
|
||||||
->setName($field['name'])
|
->setName($field['name'])
|
||||||
@ -239,7 +238,7 @@ class CreateFieldsOnGroupCommand extends Command
|
|||||||
->setOrdering($field['ordering'])
|
->setOrdering($field['ordering'])
|
||||||
->setType($field['type'])
|
->setType($field['type'])
|
||||||
->setCustomFieldsGroup($group);
|
->setCustomFieldsGroup($group);
|
||||||
|
|
||||||
//add to table
|
//add to table
|
||||||
$names = array();
|
$names = array();
|
||||||
foreach ($languages as $lang) {
|
foreach ($languages as $lang) {
|
||||||
@ -248,17 +247,17 @@ class CreateFieldsOnGroupCommand extends Command
|
|||||||
$cf->getName()[$lang] :
|
$cf->getName()[$lang] :
|
||||||
'Not available in this language';
|
'Not available in this language';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->validator->validate($cf)) {
|
if ($this->validator->validate($cf)) {
|
||||||
$em->persist($cf);
|
$em->persist($cf);
|
||||||
$output->writeln("<info>Adding Custom Field of type "
|
$output->writeln("<info>Adding Custom Field of type "
|
||||||
.$cf->getType()."\t with slug ".$cf->getSlug().
|
.$cf->getType()."\t with slug ".$cf->getSlug().
|
||||||
"\t and names : ".implode($names, ', ')."</info>");
|
"\t and names : ".implode($names, ', ')."</info>");
|
||||||
} else {
|
} else {
|
||||||
throw new \RunTimeException("Error in field ".$slug);
|
throw new \RuntimeException("Error in field ".$slug);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$em->flush();
|
$em->flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -229,7 +229,7 @@ class SpreadSheetFormatter implements FormatterInterface
|
|||||||
$this->getContentType($this->formatterData['format']));
|
$this->getContentType($this->formatterData['format']));
|
||||||
|
|
||||||
$this->tempfile = \tempnam(\sys_get_temp_dir(), '');
|
$this->tempfile = \tempnam(\sys_get_temp_dir(), '');
|
||||||
$this->generatecontent();
|
$this->generateContent();
|
||||||
|
|
||||||
$f = \fopen($this->tempfile, 'r');
|
$f = \fopen($this->tempfile, 'r');
|
||||||
$response->setContent(\stream_get_contents($f));
|
$response->setContent(\stream_get_contents($f));
|
||||||
|
@ -544,7 +544,7 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
|
|||||||
*/
|
*/
|
||||||
public function actualParticipationsByHousehold(): array
|
public function actualParticipationsByHousehold(): array
|
||||||
{
|
{
|
||||||
$participations = $this->getOPenParticipations()->toArray();
|
$participations = $this->getOpenParticipations()->toArray();
|
||||||
|
|
||||||
$households = [];
|
$households = [];
|
||||||
foreach ($participations as $p) {
|
foreach ($participations as $p) {
|
||||||
@ -1074,7 +1074,7 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
|
|||||||
*/
|
*/
|
||||||
public function getAvailablePersonLocation(): Collection
|
public function getAvailablePersonLocation(): Collection
|
||||||
{
|
{
|
||||||
return $this->getOPenParticipations()
|
return $this->getOpenParticipations()
|
||||||
->filter(function(AccompanyingPeriodParticipation $p) {
|
->filter(function(AccompanyingPeriodParticipation $p) {
|
||||||
return $p->getPerson()->hasCurrentHouseholdAddress();
|
return $p->getPerson()->hasCurrentHouseholdAddress();
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user