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

@@ -15,7 +15,6 @@ use Chill\CustomFieldsBundle\Entity\CustomField;
use Chill\CustomFieldsBundle\Entity\CustomFieldsGroup;
use Chill\CustomFieldsBundle\Service\CustomFieldProvider;
use Doctrine\ORM\EntityManager;
use RuntimeException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
@@ -26,8 +25,6 @@ use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Component\Yaml\Exception\ParseException;
use Symfony\Component\Yaml\Parser;
use function count;
/**
* Class for the command 'chill:custom_fields:populate_group' that
* Create custom fields from a yml file.
@@ -40,9 +37,6 @@ class CreateFieldsOnGroupCommand extends Command
/**
* CreateFieldsOnGroupCommand constructor.
*
* @param $availableLanguages
* @param $customizablesEntities
*/
public function __construct(
private readonly CustomFieldProvider $customFieldProvider,
@@ -95,9 +89,9 @@ class CreateFieldsOnGroupCommand extends Command
->getRepository(\Chill\CustomFieldsBundle\Entity\CustomFieldsGroup::class)
->findAll();
if (count($customFieldsGroups) === 0) {
if (0 === \count($customFieldsGroups)) {
$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);
@@ -120,7 +114,7 @@ class CreateFieldsOnGroupCommand extends Command
}
}
throw new RuntimeException('The id does not match an existing CustomFieldsGroup');
throw new \RuntimeException('The id does not match an existing CustomFieldsGroup');
}
);
$customFieldsGroup = $helper->ask($input, $output, $question);
@@ -135,6 +129,7 @@ class CreateFieldsOnGroupCommand extends Command
);
$fields = $this->_addFields($customFieldsGroup, $fieldsInput, $output);
return 0;
}
@@ -145,12 +140,11 @@ class CreateFieldsOnGroupCommand extends Command
$languages = $this->availableLanguages;
foreach ($values['fields'] as $slug => $field) {
//check the cf type exists
// check the cf type exists
$cfType = $this->customFieldProvider->getCustomFieldByType($field['type']);
if (null === $cfType) {
throw new RuntimeException('the type ' . $field['type'] . ' '
. 'does not exists');
throw new \RuntimeException('the type '.$field['type'].' does not exists');
}
$cf = new CustomField();
@@ -161,21 +155,21 @@ class CreateFieldsOnGroupCommand extends Command
->setType($field['type'])
->setCustomFieldsGroup($group);
//add to table
// add to table
$names = [];
foreach ($languages as $lang) {
//todo replace with service to find lang when available
// todo replace with service to find lang when available
$names[] = $cf->getName()[$lang] ?? 'Not available in this language';
}
if ($this->validator->validate($cf)) {
$em->persist($cf);
$output->writeln('<info>Adding Custom Field of type '
. $cf->getType() . "\t with slug " . $cf->getSlug() .
"\t and names : " . implode(', ', $names) . '</info>');
.$cf->getType()."\t with slug ".$cf->getSlug().
"\t and names : ".implode(', ', $names).'</info>');
} else {
throw new RuntimeException('Error in field ' . $slug);
throw new \RuntimeException('Error in field '.$slug);
}
}
@@ -187,13 +181,13 @@ class CreateFieldsOnGroupCommand extends Command
$parser = new Parser();
if (!file_exists($path)) {
throw new RuntimeException('file does not exist');
throw new \RuntimeException('file does not exist');
}
try {
$values = $parser->parse(file_get_contents($path));
} 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;
@@ -203,7 +197,7 @@ class CreateFieldsOnGroupCommand extends Command
{
$rows = [];
$languages = $this->availableLanguages;
//gather entitites and create an array to access them easily
// gather entitites and create an array to access them easily
$customizableEntities = [];
foreach ($this->customizablesEntities as $entry) {
@@ -213,14 +207,14 @@ class CreateFieldsOnGroupCommand extends Command
array_walk(
$customFieldsGroups,
static function (CustomFieldsGroup $customFieldGroup, $key) use ($languages, &$rows, $customizableEntities) {
//set id and entity
// set id and entity
$row = [
$customFieldGroup->getId(),
$customizableEntities[$customFieldGroup->getEntity()],
];
foreach ($languages as $lang) {
//todo replace with service to find lang when available
// todo replace with service to find lang when available
$row[] = $customFieldGroup->getName()[$lang] ?? 'Not available in this language';
}
$rows[] = $row;

View File

@@ -26,6 +26,7 @@ class CustomFieldController extends AbstractController
{
/**
* Creates a new CustomField entity.
*
* @Route("/{_locale}/admin/customfield/new", name="customfield_new")
*/
public function createAction(Request $request)
@@ -86,7 +87,7 @@ class CustomFieldController extends AbstractController
{
$entity = new CustomField();
//add the custom field group if defined in URL
// add the custom field group if defined in URL
$cfGroupId = $request->query->get('customFieldsGroup', null);
if (null !== $cfGroupId) {
@@ -95,8 +96,7 @@ class CustomFieldController extends AbstractController
->find($cfGroupId);
if (!$cfGroup) {
throw $this->createNotFoundException('CustomFieldsGroup with id '
. $cfGroupId . ' is not found !');
throw $this->createNotFoundException('CustomFieldsGroup with id '.$cfGroupId.' is not found !');
}
$entity->setCustomFieldsGroup($cfGroup);
}
@@ -111,6 +111,7 @@ class CustomFieldController extends AbstractController
/**
* Edits an existing CustomField entity.
*
* @Route("/{_locale}/admin/customfield/update", name="customfield_update")
*/
public function updateAction(Request $request, mixed $id)

View File

@@ -27,7 +27,6 @@ use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;
use function in_array;
/**
* Class CustomFieldsGroupController.
@@ -41,6 +40,7 @@ class CustomFieldsGroupController extends AbstractController
/**
* Creates a new CustomFieldsGroup entity.
*
* @Route("/{_locale}/admin/customfieldsgroup/create", name="customfieldsgroup_create")
*/
public function createAction(Request $request)
@@ -71,6 +71,7 @@ class CustomFieldsGroupController extends AbstractController
/**
* Displays a form to edit an existing CustomFieldsGroup entity.
*
* @Route("/{_locale}/admin/customfieldsgroup/{id}/edit", name="customfieldsgroup_edit")
*/
public function editAction(mixed $id)
@@ -106,7 +107,7 @@ class CustomFieldsGroupController extends AbstractController
$makeDefaultFormViews = [];
foreach ($cfGroups as $group) {
if (!in_array($group->getId(), $defaultGroups, true)) {
if (!\in_array($group->getId(), $defaultGroups, true)) {
$makeDefaultFormViews[$group->getId()] = $this->createMakeDefaultForm($group)->createView();
}
}
@@ -120,6 +121,7 @@ class CustomFieldsGroupController extends AbstractController
/**
* Set the CustomField Group with id $cFGroupId as default.
*
* @Route("/{_locale}/admin/customfieldsgroup/makedefault", name="customfieldsgroup_makedefault")
*/
public function makeDefaultAction(Request $request)
@@ -134,9 +136,7 @@ class CustomFieldsGroupController extends AbstractController
$cFGroup = $em->getRepository(\Chill\CustomFieldsBundle\Entity\CustomFieldsGroup::class)->findOneById($cFGroupId);
if (!$cFGroup) {
throw $this
->createNotFoundException('customFieldsGroup not found with '
. "id {$cFGroupId}");
throw $this->createNotFoundException('customFieldsGroup not found with '."id {$cFGroupId}");
}
$cFDefaultGroup = $em->getRepository(\Chill\CustomFieldsBundle\Entity\CustomFieldsDefaultGroup::class)
@@ -207,7 +207,7 @@ class CustomFieldsGroupController extends AbstractController
$this->get('twig.loader')
->addPath(
__DIR__ . '/../Tests/Fixtures/App/app/Resources/views/',
__DIR__.'/../Tests/Fixtures/App/app/Resources/views/',
$namespace = 'test'
);
@@ -219,8 +219,8 @@ class CustomFieldsGroupController extends AbstractController
]);
}
//dump($form->getData());
//dump(json_enccode($form->getData()));
// dump($form->getData());
// dump(json_enccode($form->getData()));
}
return $this
@@ -233,7 +233,6 @@ class CustomFieldsGroupController extends AbstractController
* Finds and displays a CustomFieldsGroup entity.
*
* @Route("/{_locale}/admin/customfieldsgroup/{id}/show", name="customfieldsgroup/show")
*
*/
public function showAction(mixed $id)
{
@@ -294,8 +293,7 @@ class CustomFieldsGroupController extends AbstractController
{
$fieldChoices = [];
foreach ($this->customFieldProvider->getAllFields()
as $key => $customType) {
foreach ($this->customFieldProvider->getAllFields() as $key => $customType) {
$fieldChoices[$key] = $customType->getName();
}
@@ -361,11 +359,9 @@ class CustomFieldsGroupController extends AbstractController
/**
* create a form to make the group default.
*
* @param CustomFieldsGroup $group
*
* @return \Symfony\Component\Form\Form
*/
private function createMakeDefaultForm(?CustomFieldsGroup $group = null)
private function createMakeDefaultForm(CustomFieldsGroup $group = null)
{
return $this->createFormBuilder($group, [
'method' => 'POST',
@@ -387,8 +383,8 @@ class CustomFieldsGroupController extends AbstractController
$em = $this->getDoctrine()->getManager();
$customFieldsGroupIds = $em->createQuery('SELECT g.id FROM '
. 'ChillCustomFieldsBundle:CustomFieldsDefaultGroup d '
. 'JOIN d.customFieldsGroup g')
.'ChillCustomFieldsBundle:CustomFieldsDefaultGroup d '
.'JOIN d.customFieldsGroup g')
->getResult(Query::HYDRATE_SCALAR);
$result = [];
@@ -409,7 +405,7 @@ class CustomFieldsGroupController extends AbstractController
private function getOptionsAvailable($entity)
{
$options = $this->getParameter('chill_custom_fields.'
. 'customizables_entities');
.'customizables_entities');
foreach ($options as $key => $definition) {
if ($definition['class'] === $entity) {

View File

@@ -18,18 +18,9 @@ use Chill\CustomFieldsBundle\Form\Type\ChoicesType;
use Chill\CustomFieldsBundle\Form\Type\ChoiceWithOtherType;
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use LogicException;
use Symfony\Bridge\Twig\TwigEngine;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Environment;
use function array_key_exists;
use function count;
use function in_array;
use function is_array;
use function LogicException;
class CustomFieldChoice extends AbstractCustomField
{
@@ -61,7 +52,7 @@ class CustomFieldChoice extends AbstractCustomField
public function buildForm(FormBuilderInterface $builder, CustomField $customField)
{
//prepare choices
// prepare choices
$choices = [];
$customFieldOptions = $customField->getOptions();
@@ -71,7 +62,7 @@ class CustomFieldChoice extends AbstractCustomField
}
}
//prepare $options
// prepare $options
$options = [
'multiple' => $customFieldOptions[self::MULTIPLE],
'choices' => array_combine(array_values($choices), array_keys($choices)),
@@ -79,11 +70,11 @@ class CustomFieldChoice extends AbstractCustomField
'label' => $this->translatableStringHelper->localize($customField->getName()),
];
//if allow_other = true
// if allow_other = true
if (true === $customFieldOptions[self::ALLOW_OTHER]) {
$otherValueLabel = null;
if (array_key_exists(self::OTHER_VALUE_LABEL, $customFieldOptions)) {
if (\array_key_exists(self::OTHER_VALUE_LABEL, $customFieldOptions)) {
$otherValueLabel = $this->translatableStringHelper->localize(
$customFieldOptions[self::OTHER_VALUE_LABEL]
);
@@ -99,8 +90,8 @@ class CustomFieldChoice extends AbstractCustomField
)
->addModelTransformer(new CustomFieldDataTransformer($this, $customField))
);
} else { //if allow_other = false
//we add the 'expanded' to options
} else { // if allow_other = false
// we add the 'expanded' to options
$options['expanded'] = $customFieldOptions[self::EXPANDED];
$builder->add(
@@ -164,7 +155,7 @@ class CustomFieldChoice extends AbstractCustomField
return $serialized;
}
public function extractOtherValue(CustomField $cf, ?array $data = null)
public function extractOtherValue(CustomField $cf, array $data = null)
{
return $data['_other'];
}
@@ -185,7 +176,7 @@ class CustomFieldChoice extends AbstractCustomField
if ($this->allowOtherChoice($cf)) {
$labels = $cf->getOptions()[self::OTHER_VALUE_LABEL];
if (!is_array($labels) || count($labels) === 0) {
if (!\is_array($labels) || 0 === \count($labels)) {
$labels['back'] = 'other value';
}
$choices['_other'] = $this->translatableStringHelper
@@ -210,8 +201,8 @@ class CustomFieldChoice extends AbstractCustomField
*
* Used in list exports.
*
* @param string $choiceSlug the slug of the choice we want to know if it was checked
* @param array|string $data the data of the field
* @param string $choiceSlug the slug of the choice we want to know if it was checked
* @param array|string $data the data of the field
*
* @return bool
*/
@@ -223,10 +214,10 @@ class CustomFieldChoice extends AbstractCustomField
if ($cf->getOptions()[self::MULTIPLE]) {
if ($cf->getOptions()[self::ALLOW_OTHER]) {
return in_array($choiceSlug, $this->deserialize($data, $cf)['_choices'], true);
return \in_array($choiceSlug, $this->deserialize($data, $cf)['_choices'], true);
}
return in_array($choiceSlug, $this->deserialize($data, $cf), true);
return \in_array($choiceSlug, $this->deserialize($data, $cf), true);
}
if ($cf->getOptions()[self::ALLOW_OTHER]) {
@@ -243,9 +234,9 @@ class CustomFieldChoice extends AbstractCustomField
}
// if multiple choice OR multiple/single choice with other
if (is_array($value)) {
if (\is_array($value)) {
// if allow other
if (array_key_exists('_choices', $value)) {
if (\array_key_exists('_choices', $value)) {
if (null === $value['_choices']) {
return true;
}
@@ -253,7 +244,7 @@ class CustomFieldChoice extends AbstractCustomField
return empty($value['_choices']);
} // we do not have 'allow other'
if (count($value) === 1) {
if (1 === \count($value)) {
return empty($value[0]);
}
@@ -262,7 +253,7 @@ class CustomFieldChoice extends AbstractCustomField
return empty($value);
throw LogicException('This case is not expected.');
throw \LogicException('This case is not expected.');
}
public function isMultiple(CustomField $cf)
@@ -273,19 +264,16 @@ class CustomFieldChoice extends AbstractCustomField
/**
* @internal this function is able to receive data whichever is the value of "other", "multiple"
*
* @param mixed $value
* @param mixed $documentType
*
* @return string html representation
*/
public function render($value, CustomField $customField, $documentType = 'html')
{
//extract the data. They are under a _choice key if they are stored with allow_other
// extract the data. They are under a _choice key if they are stored with allow_other
$data = $value['_choices'] ?? $value;
$selected = (is_array($data)) ? $data : [$data];
$selected = (\is_array($data)) ? $data : [$data];
$choices = $customField->getOptions()[self::CHOICES];
if (in_array('_other', $selected, true)) {
if (\in_array('_other', $selected, true)) {
$choices[] = ['name' => $value['_other'], 'slug' => '_other'];
}
@@ -323,7 +311,7 @@ class CustomFieldChoice extends AbstractCustomField
$value = $this->guessValue($serialized);
// set in an array : we want a multiple
$fixedValue = is_array($value) ? $value : [$value];
$fixedValue = \is_array($value) ? $value : [$value];
if ($allowOther) {
return $this->deserializeWithAllowOther($serialized, $fixedValue);
@@ -337,9 +325,9 @@ class CustomFieldChoice extends AbstractCustomField
$value = $this->guessValue($serialized);
// set in a single value. We must have a single string
$fixedValue = is_array($value) ?
$fixedValue = \is_array($value) ?
// check if the array has an element, if not replace by empty string
count($value) > 0 ? end($value) : ''
\count($value) > 0 ? end($value) : ''
:
$value;
@@ -372,16 +360,17 @@ class CustomFieldChoice extends AbstractCustomField
return null;
}
if (!is_array($value)) {
if (!\is_array($value)) {
return $value;
}
// we have a field with "allow other"
if (array_key_exists('_choices', $value)) {
if (\array_key_exists('_choices', $value)) {
return $value['_choices'];
}
// we have a field with "multiple"
return $value;
throw LogicException('This case is not expected.');
throw \LogicException('This case is not expected.');
}
}

View File

@@ -15,9 +15,6 @@ use Chill\CustomFieldsBundle\Entity\CustomField;
use Chill\CustomFieldsBundle\Form\DataTransformer\CustomFieldDataTransformer;
use Chill\MainBundle\Form\Type\ChillDateType;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use DateTime;
use Exception;
use Symfony\Bundle\TwigBundle\TwigEngine;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
@@ -34,7 +31,7 @@ use Twig\Environment;
*/
class CustomFieldDate extends AbstractCustomField
{
final public const DATE_FORMAT = DateTime::RFC3339;
final public const DATE_FORMAT = \DateTime::RFC3339;
final public const FORMAT = 'format';
@@ -71,8 +68,8 @@ class CustomFieldDate extends AbstractCustomField
{
$validatorFunction = static function ($value, ExecutionContextInterface $context) {
try {
$date = new DateTime($value);
} catch (Exception) {
$date = new \DateTime($value);
} catch (\Exception) {
$context->buildViolation('The expression "%expression%" is invalid', [
'%expression%' => $value,
])
@@ -107,7 +104,7 @@ class CustomFieldDate extends AbstractCustomField
return null;
}
return DateTime::createFromFormat(self::DATE_FORMAT, $serialized);
return \DateTime::createFromFormat(self::DATE_FORMAT, $serialized);
}
public function getName()
@@ -129,7 +126,7 @@ class CustomFieldDate extends AbstractCustomField
default:
$template = 'ChillCustomFieldsBundle:CustomFieldsRendering:date.'
. $documentType . '.twig';
.$documentType.'.twig';
return $this->templating
->render($template, [
@@ -165,7 +162,7 @@ class CustomFieldDate extends AbstractCustomField
// add required
$fieldOptions['required'] = false;
//add label
// add label
$fieldOptions['label'] = $this->translatableStringHelper->localize($customField->getName());
// add constraints if required
@@ -176,8 +173,8 @@ class CustomFieldDate extends AbstractCustomField
return;
}
$value = DateTime::createFromFormat(self::DATE_FORMAT, $timestamp);
$after = new DateTime($options[self::MIN]);
$value = \DateTime::createFromFormat(self::DATE_FORMAT, $timestamp);
$after = new \DateTime($options[self::MIN]);
if ($value < $after) {
$context
@@ -197,8 +194,8 @@ class CustomFieldDate extends AbstractCustomField
return;
}
$value = DateTime::createFromFormat(self::DATE_FORMAT, $timestamp);
$before = new DateTime($options[self::MAX]);
$value = \DateTime::createFromFormat(self::DATE_FORMAT, $timestamp);
$before = new \DateTime($options[self::MAX]);
if ($value > $before) {
$context

View File

@@ -21,7 +21,7 @@ interface CustomFieldInterface
* user.
*
* @param \Chill\CustomFieldsBundle\CustomField\FormBuilderInterface $builder
* @param \Chill\CustomFieldsBundle\CustomField\CustomField $customField
* @param \Chill\CustomFieldsBundle\CustomField\CustomField $customField
*
* @return \Symfony\Component\Form\FormTypeInterface the form type
*/
@@ -42,7 +42,6 @@ interface CustomFieldInterface
* value which may be used in the process.
*
* @param \Chill\CustomFieldsBundle\CustomField\CustomField $customField
* @param mixed $serialized
*/
public function deserialize($serialized, CustomField $customField);
@@ -58,9 +57,8 @@ interface CustomFieldInterface
/**
* Return a repsentation of the value of the CustomField.
*
* @param mixed $value the raw value, **not deserialized** (= as stored in the db)
* @param mixed $value the raw value, **not deserialized** (= as stored in the db)
* @param \Chill\CustomFieldsBundle\CustomField\CustomField $customField
* @param mixed $documentType
*
* @return string an html representation of the value
*/
@@ -69,7 +67,6 @@ interface CustomFieldInterface
/**
* Transform the value into a format that can be stored in DB.
*
* @param mixed $value
* @param \Chill\CustomFieldsBundle\CustomField\CustomField $customField
*/
public function serialize($value, CustomField $customField);

View File

@@ -15,19 +15,11 @@ use Chill\CustomFieldsBundle\Entity\CustomField;
use Chill\CustomFieldsBundle\Entity\CustomFieldLongChoice\Option;
use Chill\CustomFieldsBundle\EntityRepository\CustomFieldLongChoice\OptionRepository;
use Chill\CustomFieldsBundle\Form\DataTransformer\CustomFieldDataTransformer;
use Chill\FamilyMembersBundle\Templating\Twig;
use Chill\MainBundle\Form\Type\Select2ChoiceType;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use LogicException;
use Symfony\Bridge\Twig\TwigEngine;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Templating\EngineInterface;
use function get_class;
use function gettype;
use function is_object;
class CustomFieldLongChoice extends AbstractCustomField
{
final public const KEY = 'key';
@@ -46,7 +38,7 @@ class CustomFieldLongChoice extends AbstractCustomField
false,
true
);
//create a local copy of translatable string helper
// create a local copy of translatable string helper
$translatableStringHelper = $this->translatableStringHelper;
$builder->add($customField->getSlug(), Select2ChoiceType::class, [
'choices' => $entries,
@@ -73,7 +65,7 @@ class CustomFieldLongChoice extends AbstractCustomField
public function buildOptionsForm(FormBuilderInterface $builder)
{
//create a selector between different keys
// create a selector between different keys
$keys = $this->optionRepository->getKeys();
$choices = [];
@@ -105,7 +97,7 @@ class CustomFieldLongChoice extends AbstractCustomField
{
$option = $this->deserialize($value, $customField);
$template = 'ChillCustomFieldsBundle:CustomFieldsRendering:choice_long.'
. $documentType . '.twig';
.$documentType.'.twig';
return $this->templating
->render($template, [
@@ -120,9 +112,7 @@ class CustomFieldLongChoice extends AbstractCustomField
}
if (!$value instanceof Option) {
throw new LogicException('the value should be an instance of '
. 'Chill\CustomFieldsBundle\Entity\CustomFieldLongChoice\Option, '
. is_object($value) ? $value::class : gettype($value) . ' given');
throw new \LogicException('the value should be an instance of Chill\CustomFieldsBundle\Entity\CustomFieldLongChoice\Option, '.\is_object($value) ? $value::class : \gettype($value).' given');
}
// we place the id in array, to allow in the future multiple select

View File

@@ -13,7 +13,6 @@ namespace Chill\CustomFieldsBundle\CustomFields;
use Chill\CustomFieldsBundle\Entity\CustomField;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Symfony\Bundle\TwigBundle\TwigEngine;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
@@ -49,10 +48,10 @@ class CustomFieldNumber extends AbstractCustomField
{
$options = $customField->getOptions();
//select the type depending to the SCALE
// select the type depending to the SCALE
$type = (0 === $options[self::SCALE] || null === $options[self::SCALE]) ?
IntegerType::class : NumberType::class;
//'integer' : 'number';
// 'integer' : 'number';
$fieldOptions = $this->prepareFieldOptions($customField, $type);
@@ -97,7 +96,7 @@ class CustomFieldNumber extends AbstractCustomField
public function render($value, CustomField $customField, $documentType = 'html')
{
$template = 'ChillCustomFieldsBundle:CustomFieldsRendering:number.'
. $documentType . '.twig';
.$documentType.'.twig';
$options = $customField->getOptions();
return $this->templating
@@ -132,7 +131,7 @@ class CustomFieldNumber extends AbstractCustomField
// add required
$fieldOptions['required'] = false;
//add label
// add label
$fieldOptions['label'] = $this->translatableStringHelper->localize($customField->getName());
// add constraints if required

View File

@@ -13,16 +13,12 @@ namespace Chill\CustomFieldsBundle\CustomFields;
use Chill\CustomFieldsBundle\Entity\CustomField;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Symfony\Bundle\TwigBundle\TwigEngine;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Twig\Environment;
use function array_key_exists;
class CustomFieldText extends AbstractCustomField
{
@@ -51,7 +47,7 @@ class CustomFieldText extends AbstractCustomField
$attrArray = [];
if (
array_key_exists(self::MULTIPLE_CF_INLINE, $options)
\array_key_exists(self::MULTIPLE_CF_INLINE, $options)
&& $options[self::MULTIPLE_CF_INLINE]
) {
$attrArray['class'] = 'multiple-cf-inline';

View File

@@ -14,10 +14,8 @@ namespace Chill\CustomFieldsBundle\CustomFields;
use Chill\CustomFieldsBundle\Entity\CustomField;
use Chill\CustomFieldsBundle\Form\Type\CustomFieldsTitleType;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Symfony\Bundle\TwigBundle\TwigEngine;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Twig\Environment;
class CustomFieldTitle extends AbstractCustomField

View File

@@ -73,7 +73,7 @@ class LoadOption extends AbstractFixture implements OrderedFixtureInterface
->setText($text)
->setParent($parent)
->setActive(true)
->setInternalKey($parent->getKey() . '-' . $this->counter);
->setInternalKey($parent->getKey().'-'.$this->counter);
}
private function loadingCompanies(ObjectManager $manager)
@@ -103,7 +103,7 @@ class LoadOption extends AbstractFixture implements OrderedFixtureInterface
->setKey('company');
$manager->persist($parent);
//Load children
// Load children
$expected_nb_children = random_int(10, 50);
for ($i = 0; $i < $expected_nb_children; ++$i) {
@@ -143,7 +143,7 @@ class LoadOption extends AbstractFixture implements OrderedFixtureInterface
->setKey('word');
$manager->persist($parent);
//Load children
// Load children
$expected_nb_children = random_int(10, 50);
for ($i = 0; $i < $expected_nb_children; ++$i) {

View File

@@ -29,15 +29,15 @@ class ChillCustomFieldsExtension extends Extension implements PrependExtensionIn
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../config'));
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../config'));
$loader->load('services.yaml');
$loader->load('services/fixtures.yaml');
$loader->load('services/controller.yaml');
$loader->load('services/command.yaml');
$loader->load('services/menu.yaml');
//add at least a blank array at 'customizable_entities' options
//$customizable_entities = (isset($config['customizables_entities'])
// add at least a blank array at 'customizable_entities' options
// $customizable_entities = (isset($config['customizables_entities'])
// && $config['customizables_entities'] !== FALSE)
// ? $config['customizables_entities'] : array();
@@ -64,7 +64,7 @@ class ChillCustomFieldsExtension extends Extension implements PrependExtensionIn
];
$container->prependExtensionConfig('twig', $twigConfig);
//add routes for custom bundle
// add routes for custom bundle
$container->prependExtensionConfig('chill_main', [
'routing' => [
'resources' => [

View File

@@ -11,7 +11,6 @@ declare(strict_types=1);
namespace Chill\CustomFieldsBundle\DependencyInjection;
use LogicException;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
@@ -21,8 +20,7 @@ class CustomFieldCompilerPass implements CompilerPassInterface
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('chill.custom_field.provider')) {
throw new LogicException('service chill.custom_field.provider '
. 'is not defined.');
throw new \LogicException('service chill.custom_field.provider is not defined.');
}
$definition = $container->getDefinition(

View File

@@ -17,7 +17,9 @@ use Doctrine\ORM\Mapping as ORM;
* CustomField.
*
* @ORM\Entity
*
* @ORM\Table(name="customfield")
*
* @ORM\HasLifecycleCallbacks
*/
class CustomField
@@ -39,10 +41,10 @@ class CustomField
private ?\Chill\CustomFieldsBundle\Entity\CustomFieldsGroup $customFieldGroup = null;
/**
* @var int
*
* @ORM\Id
*
* @ORM\Column(name="id", type="integer")
*
* @ORM\GeneratedValue(strategy="AUTO")
*/
private ?int $id = null;
@@ -60,8 +62,6 @@ class CustomField
private array $options = [];
/**
* @var float
*
* @ORM\Column(type="float")
*/
private ?float $ordering = null;
@@ -72,15 +72,11 @@ class CustomField
private false $required = false;
/**
* @var string
*
* @ORM\Column(type="string", length=255)
*/
private ?string $slug = null;
/**
* @var string
*
* @ORM\Column(type="string", length=255)
*/
private ?string $type = null;
@@ -214,11 +210,9 @@ class CustomField
/**
* Set customFieldGroup.
*
* @param CustomFieldsGroup $customFieldGroup
*
* @return CustomField
*/
public function setCustomFieldsGroup(?CustomFieldsGroup $customFieldGroup = null)
public function setCustomFieldsGroup(CustomFieldsGroup $customFieldGroup = null)
{
$this->customFieldGroup = $customFieldGroup;
@@ -273,8 +267,6 @@ class CustomField
}
/**
* @param $slug
*
* @return $this
*/
public function setSlug($slug)

View File

@@ -18,6 +18,7 @@ use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(
* repositoryClass="Chill\CustomFieldsBundle\EntityRepository\CustomFieldLongChoice\OptionRepository")
*
* @ORM\Table(name="custom_field_long_choice_options")
*/
class Option
@@ -29,6 +30,7 @@ class Option
/**
* @var Collection<Option>
*
* @ORM\OneToMany(
* targetEntity="Chill\CustomFieldsBundle\Entity\CustomFieldLongChoice\Option",
* mappedBy="parent")
@@ -36,10 +38,10 @@ class Option
private Collection $children;
/**
* @var int
*
* @ORM\Id
*
* @ORM\Column(name="id", type="integer")
*
* @ORM\GeneratedValue(strategy="AUTO")
*/
private ?int $id = null;
@@ -58,6 +60,7 @@ class Option
* @ORM\ManyToOne(
* targetEntity="Chill\CustomFieldsBundle\Entity\CustomFieldLongChoice\Option",
* inversedBy="children")
*
* @ORM\JoinColumn(nullable=true)
*/
private ?\Chill\CustomFieldsBundle\Entity\CustomFieldLongChoice\Option $parent = null;
@@ -147,8 +150,6 @@ class Option
}
/**
* @param $active
*
* @return $this
*/
public function setActive($active)
@@ -159,8 +160,6 @@ class Option
}
/**
* @param $internal_key
*
* @return $this
*/
public function setInternalKey($internal_key)
@@ -171,8 +170,6 @@ class Option
}
/**
* @param $key
*
* @return $this
*/
public function setKey($key)
@@ -185,7 +182,7 @@ class Option
/**
* @return $this
*/
public function setParent(?Option $parent = null)
public function setParent(Option $parent = null)
{
$this->parent = $parent;
$this->key = $parent->getKey();

View File

@@ -17,6 +17,7 @@ use Doctrine\ORM\Mapping as ORM;
* CustomFieldsDefaultGroup.
*
* @ORM\Entity
*
* @ORM\Table(
* name="customfieldsdefaultgroup",
* uniqueConstraints={@ORM\UniqueConstraint(
@@ -27,8 +28,6 @@ use Doctrine\ORM\Mapping as ORM;
class CustomFieldsDefaultGroup
{
/**
* @var CustomFieldsGroup
*
* @ORM\ManyToOne(
* targetEntity="Chill\CustomFieldsBundle\Entity\CustomFieldsGroup")
*
@@ -37,17 +36,15 @@ class CustomFieldsDefaultGroup
private ?\Chill\CustomFieldsBundle\Entity\CustomFieldsGroup $customFieldsGroup = null;
/**
* @var string
*
* @ORM\Column(type="string", length=255)
*/
private ?string $entity = null;
/**
* @var int
*
* @ORM\Id
*
* @ORM\Column(name="id", type="integer")
*
* @ORM\GeneratedValue(strategy="AUTO")
*/
private ?int $id = null;
@@ -85,7 +82,7 @@ class CustomFieldsDefaultGroup
/**
* Set customFieldsGroup.
*
* @param CustomFieldsGroup $customFieldsGroup *
* @param CustomFieldsGroup $customFieldsGroup *
*
* @return CustomFieldsDefaultGroup
*/

View File

@@ -19,6 +19,7 @@ use Doctrine\ORM\Mapping as ORM;
* CustomFieldGroup.
*
* @ORM\Entity
*
* @ORM\Table(name="customfieldsgroup")
*/
class CustomFieldsGroup
@@ -34,25 +35,25 @@ class CustomFieldsGroup
* The custom fields are asc-ordered regarding to their property "ordering".
*
* @var Collection<CustomField>
*
* @ORM\OneToMany(
* targetEntity="Chill\CustomFieldsBundle\Entity\CustomField",
* mappedBy="customFieldGroup")
*
* @ORM\OrderBy({"ordering": "ASC"})
*/
private Collection $customFields;
/**
* @var string
*
* @ORM\Column(type="string", length=255)
*/
private ?string $entity = null;
/**
* @var int
*
* @ORM\Id
*
* @ORM\Column(name="id", type="integer")
*
* @ORM\GeneratedValue(strategy="AUTO")
*/
private ?int $id = null;
@@ -138,9 +139,9 @@ class CustomFieldsGroup
/**
* Get name.
*/
public function getName(?string $language = null): array|string
public function getName(string $language = null): array|string
{
//TODO set this in a service, PLUS twig function
// TODO set this in a service, PLUS twig function
if (null !== $language) {
if (isset($this->name[$language])) {
return $this->name[$language];

View File

@@ -16,7 +16,6 @@ use Chill\CustomFieldsBundle\Service\CustomFieldProvider;
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Doctrine\Persistence\ObjectManager;
use LogicException;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
@@ -54,14 +53,14 @@ class CustomFieldType extends AbstractType
$builder->get('customFieldsGroup')
->addViewTransformer(new CustomFieldsGroupToIdTransformer($this->om));
} else {
throw new LogicException('The value of group_widget is not handled');
throw new \LogicException('The value of group_widget is not handled');
}
$builder
->add('ordering', NumberType::class)
->add('required', CheckboxType::class, [
'required' => false,
//'expanded' => TRUE,
// 'expanded' => TRUE,
'label' => 'Required field',
])
->add('type', HiddenType::class, ['data' => $options['type']])

View File

@@ -21,22 +21,20 @@ use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Contracts\Translation\TranslatorInterface;
use function count;
class CustomFieldsGroupType extends AbstractType
{
public function __construct(
private readonly array $customizableEntities,
//TODO : add comment about this variable
// TODO : add comment about this variable
private readonly TranslatorInterface $translator
) {}
//TODO : details about the function
// TODO : details about the function
public function buildForm(FormBuilderInterface $builder, array $options)
{
//prepare translation
// prepare translation
$entities = [];
$customizableEntities = []; //TODO : change name too close than $this->customizableEntities
$customizableEntities = []; // TODO : change name too close than $this->customizableEntities
foreach ($this->customizableEntities as $key => $definition) {
$entities[$definition['class']] = $this->translator->trans($definition['name']);
@@ -55,14 +53,14 @@ class CustomFieldsGroupType extends AbstractType
$form = $event->getForm();
$group = $event->getData();
//stop the function if entity is not set
if ($group->getEntity() === null) {
// stop the function if entity is not set
if (null === $group->getEntity()) {
return;
}
$optionBuilder = null;
if (count($customizableEntities[$group->getEntity()]['options']) > 0) {
if (\count($customizableEntities[$group->getEntity()]['options']) > 0) {
$optionBuilder = $builder
->getFormFactory()
->createBuilderForProperty(CustomFieldsGroup::class, 'options')

View File

@@ -16,8 +16,6 @@ use Doctrine\Persistence\ObjectManager;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Exception\TransformationFailedException;
use function gettype;
class CustomFieldsGroupToIdTransformer implements DataTransformerInterface
{
public function __construct(private readonly ObjectManager $om) {}
@@ -25,35 +23,25 @@ class CustomFieldsGroupToIdTransformer implements DataTransformerInterface
/**
* Transforms a string (id) to an object (CustomFieldsGroup).
*
* @param string $id
* @param string $id
*
* @throws TransformationFailedException if object (report) is not found.
* @throws TransformationFailedException if object (report) is not found
*/
public function reverseTransform($id): ?\Chill\CustomFieldsBundle\Entity\CustomFieldsGroup
public function reverseTransform($id): ?CustomFieldsGroup
{
if (!$id) {
return null;
}
if ($id instanceof CustomFieldsGroup) {
throw new TransformationFailedException(
'The transformation failed: the expected argument on '
. 'reverseTransform is an object of type int,'
. 'Chill\CustomFieldsBundle\Entity\CustomFieldsGroup, '
. 'given'
);
throw new TransformationFailedException('The transformation failed: the expected argument on reverseTransform is an object of type int,Chill\CustomFieldsBundle\Entity\CustomFieldsGroup, given');
}
$customFieldsGroup = $this->om
->getRepository(CustomFieldsGroup::class)->find($id);
if (null === $customFieldsGroup) {
throw new TransformationFailedException(
sprintf(
'Le group avec le numéro "%s" ne peut pas être trouvé!',
$id
)
);
throw new TransformationFailedException(sprintf('Le group avec le numéro "%s" ne peut pas être trouvé!', $id));
}
return $customFieldsGroup;
@@ -62,7 +50,7 @@ class CustomFieldsGroupToIdTransformer implements DataTransformerInterface
/**
* Transforms an custom_field_group to a string (id).
*
* @param CustomFieldsGroup|null $customFieldsGroup
* @param CustomFieldsGroup|null $customFieldsGroup
*
* @return string
*/
@@ -73,14 +61,7 @@ class CustomFieldsGroupToIdTransformer implements DataTransformerInterface
}
if (!$customFieldsGroup instanceof CustomFieldsGroup) {
throw new TransformationFailedException(sprintf(
'Transformation failed: '
. 'the expected type of the transforme function is an '
. 'object of type Chill\CustomFieldsBundle\Entity\CustomFieldsGroup, '
. '%s given (value : %s)',
gettype($customFieldsGroup),
$customFieldsGroup
));
throw new TransformationFailedException(sprintf('Transformation failed: the expected type of the transforme function is an object of type Chill\CustomFieldsBundle\Entity\CustomFieldsGroup, %s given (value : %s)', \gettype($customFieldsGroup), $customFieldsGroup));
}
return $customFieldsGroup->getId();

View File

@@ -15,10 +15,6 @@ use Chill\CustomFieldsBundle\Entity\CustomField;
use Doctrine\Persistence\ObjectManager;
use Symfony\Component\Form\DataTransformerInterface;
use function array_key_exists;
use const JSON_THROW_ON_ERROR;
/**
* Not in use ? Deprecated ?
*/
@@ -58,22 +54,22 @@ class JsonCustomFieldToArrayTransformer implements DataTransformerInterface
echo "<br> - - 9 - <br>";
*/
//var_dump($customFieldsArray);
// var_dump($customFieldsArray);
$customFieldsArrayRet = [];
foreach ($customFieldsArray as $key => $value) {
$traited = false;
if (array_key_exists($key, $this->customField)) {
if (\array_key_exists($key, $this->customField)) {
$type = $this->customField[$key]->getType();
if (str_starts_with((string) $type, 'ManyToOne')) {
// pour le manytoone() faire
// un update du form en js ? : http://symfony.com/fr/doc/current/cookbook/form/form_collections.html
//
//$entityClass = substr($type, 10, -1);
//echo $entityClasss;
// $entityClass = substr($type, 10, -1);
// echo $entityClasss;
if (str_starts_with((string) $type, 'ManyToOnePersist')) {
// PEUT ETRE A FAIRE SI SEULEMENT $value->getId() ne renvoie rien...
//
@@ -100,9 +96,9 @@ class JsonCustomFieldToArrayTransformer implements DataTransformerInterface
}
}
//echo json_encode($customFieldsArrayRet);
// echo json_encode($customFieldsArrayRet);
return json_encode($customFieldsArrayRet, JSON_THROW_ON_ERROR);
return json_encode($customFieldsArrayRet, \JSON_THROW_ON_ERROR);
}
public function transform($customFieldsJSON)
@@ -112,7 +108,7 @@ class JsonCustomFieldToArrayTransformer implements DataTransformerInterface
if (null === $customFieldsJSON) {
$customFieldsArray = [];
} else {
$customFieldsArray = json_decode((string) $customFieldsJSON, true, 512, JSON_THROW_ON_ERROR);
$customFieldsArray = json_decode((string) $customFieldsJSON, true, 512, \JSON_THROW_ON_ERROR);
}
$customFieldsArrayRet = [];
@@ -120,7 +116,7 @@ class JsonCustomFieldToArrayTransformer implements DataTransformerInterface
foreach ($customFieldsArray as $key => $value) {
$traited = false;
if (array_key_exists($key, $this->customField)) {
if (\array_key_exists($key, $this->customField)) {
$type = $this->customField[$key]->getType();
if (str_starts_with((string) $type, 'ManyToOne')) {
@@ -131,7 +127,7 @@ class JsonCustomFieldToArrayTransformer implements DataTransformerInterface
}
$customFieldsArrayRet[$key] = $this->om
->getRepository('ChillCustomFieldsBundle:' . $entityClass)
->getRepository('ChillCustomFieldsBundle:'.$entityClass)
->findOneById($value);
$traited = true;
} elseif ('ManyToMany(Adress)' === $type) {

View File

@@ -16,8 +16,6 @@ use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolver;
use function array_key_exists;
/**
* This extension create the possibility to add some text
* after the input.
@@ -30,8 +28,8 @@ abstract class PostTextExtension extends AbstractTypeExtension
{
public function buildView(FormView $view, FormInterface $form, array $options)
{
if (array_key_exists('post_text', $options)) {
//set the post text variable to the view
if (\array_key_exists('post_text', $options)) {
// set the post text variable to the view
$view->vars['post_text'] = $options['post_text'];
}
}

View File

@@ -29,9 +29,9 @@ class ChoiceWithOtherType extends AbstractType
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
//add an 'other' entry in choices array
// add an 'other' entry in choices array
$options['choices'][$this->otherValueLabel] = '_other';
//ChoiceWithOther must always be expanded
// ChoiceWithOther must always be expanded
$options['expanded'] = true;
// adding a default value for choice
$options['empty_data'] = null;

View File

@@ -108,7 +108,7 @@ class LinkedCustomFieldsType extends AbstractType
*/
private function getRootForm(FormInterface $form)
{
if ($form->getParent() === null) {
if (null === $form->getParent()) {
return $form;
}

View File

@@ -11,7 +11,6 @@ declare(strict_types=1);
namespace Chill\CustomFieldsBundle\Service;
use LogicException;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -45,8 +44,8 @@ class CustomFieldProvider implements ContainerAwareInterface
* Add a new custom field to the provider.
*
* @param type $serviceName The name of the service (declared in service.yml)
* @param type $type The type of the service (that is used in the form to
* add this type)
* @param type $type The type of the service (that is used in the form to
* add this type)
*/
public function addCustomField($serviceName, $type)
{
@@ -56,7 +55,7 @@ class CustomFieldProvider implements ContainerAwareInterface
/**
* Get all the custom fields known by the provider.
*
* @return array Array of the known custom fields indexed by the type.
* @return array array of the known custom fields indexed by the type
*/
public function getAllFields()
{
@@ -77,8 +76,7 @@ class CustomFieldProvider implements ContainerAwareInterface
return $this->servicesByType[$type];
}
throw new LogicException('the custom field with type ' . $type . ' '
. 'is not found');
throw new \LogicException('the custom field with type '.$type.' is not found');
}
/**
@@ -86,10 +84,10 @@ class CustomFieldProvider implements ContainerAwareInterface
*
* @see \Symfony\Component\DependencyInjection\ContainerAwareInterface::setContainer()
*/
public function setContainer(?ContainerInterface $container = null)
public function setContainer(ContainerInterface $container = null)
{
if (null === $container) {
throw new LogicException('container should not be null');
throw new \LogicException('container should not be null');
}
$this->container = $container;

View File

@@ -25,9 +25,9 @@ class CustomFieldsHelper
/**
* Constructor.
*
* @param EntityManagerInterface $em The entity manager
* @param CustomFieldProvider $provider The customfield provider that
* contains all the declared custom fields
* @param EntityManagerInterface $em The entity manager
* @param CustomFieldProvider $provider The customfield provider that
* contains all the declared custom fields
*/
public function __construct(private readonly EntityManagerInterface $em, private readonly CustomFieldProvider $provider) {}
@@ -45,13 +45,13 @@ class CustomFieldsHelper
/**
* Render the value of a custom field.
*
* @param array $fields the **raw** array, as stored in the db
* @param CustomField $customField the customField entity
* @param string $documentType The type of document in which the rendered value is displayed ('html' or 'csv').
* @param array $fields the **raw** array, as stored in the db
* @param CustomField $customField the customField entity
* @param string $documentType the type of document in which the rendered value is displayed ('html' or 'csv')
*
* @return The representation of the value the customField
*
* @throws CustomFieldsHelperException if slug is missing
*
* @return The representation of the value the customField.
*/
public function renderCustomField(array $fields, CustomField $customField, $documentType = 'html')
{

View File

@@ -11,9 +11,7 @@ declare(strict_types=1);
namespace Chill\CustomFieldsBundle\Service;
use Exception;
class CustomFieldsHelperException extends Exception
class CustomFieldsHelperException extends \Exception
{
public static function customFieldsGroupNotFound($entity)
{

View File

@@ -13,9 +13,6 @@ namespace Chill\CustomFieldsBundle\Templating\Twig;
use Chill\CustomFieldsBundle\Entity\CustomField;
use Chill\CustomFieldsBundle\Service\CustomFieldsHelper;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Twig\Environment;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
@@ -77,9 +74,9 @@ class CustomFieldRenderingTwig extends AbstractExtension
* Twig Extension that is used to render the label of a custom field.
*
* @param CustomField $customField Either a customField OR a customizable_entity OR the FQDN of the entity
* @param array $params The parameters for rendering. Currently, 'label_layout' allow to choose a different label. Default is '@ChillCustomFields/CustomField/render_label.html.twig'
* @param array $params The parameters for rendering. Currently, 'label_layout' allow to choose a different label. Default is '@ChillCustomFields/CustomField/render_label.html.twig'
*
* @return string HTML representation of the custom field label.
* @return string HTML representation of the custom field label
*/
public function renderLabel(Environment $env, CustomField $customField, array $params = [])
{
@@ -93,9 +90,9 @@ class CustomFieldRenderingTwig extends AbstractExtension
*
* The presentation of the value is influenced by the document type.
*
* @param array $fields The array raw, as stored in the db
* @param CustomField $customField Either a customField OR a customizable_entity OR the FQDN of the entity
* @param string $documentType The type of the document (csv, html)
* @param array $fields The array raw, as stored in the db
* @param CustomField $customField Either a customField OR a customizable_entity OR the FQDN of the entity
* @param string $documentType The type of the document (csv, html)
*
* @return string HTML representation of the custom field value, as described in the CustomFieldInterface. Is HTML safe
*/

View File

@@ -11,9 +11,6 @@ declare(strict_types=1);
namespace Chill\CustomFieldsBundle\Templating\Twig;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Twig\Environment;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
@@ -71,16 +68,17 @@ final class CustomFieldsGroupRenderingTwig extends AbstractExtension
*
* The presentation of the value is influenced by the document type.
*
* @param array $fields The array raw, as stored in the db
* @param array $fields The array raw, as stored in the db
* @param CustomFieldsGroud $customFielsGroup The custom field group
* @param string $documentType The type of the document (csv, html)
* @param array $params The parameters for rendering :
* - layout : allow to choose a different layout by default :
* @param string $documentType The type of the document (csv, html)
* @param array $params The parameters for rendering :
* - layout : allow to choose a different layout by default :
*
* @ChillCustomFields/CustomFieldsGroup/render.html.twig
* - show_empty : force show empty field
*
* @return string HTML representation of the custom field group value, as described in
* the CustomFieldInterface. Is HTML safe
* the CustomFieldInterface. Is HTML safe
*/
public function renderWidget(Environment $env, array $fields, $customFielsGroup, $documentType = 'html', array $params = [])
{

View File

@@ -17,6 +17,7 @@ use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
* Test the option Customizables_entities.
*
* @internal
*
* @coversNothing
*/
final class ConfigCustomizablesEntitiesTest extends KernelTestCase

View File

@@ -15,6 +15,7 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
/**
* @internal
*
* @coversNothing
*/
final class CustomFieldControllerTest_TODO extends WebTestCase

View File

@@ -16,6 +16,7 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
/**
* @internal
*
* @coversNothing
*/
final class CustomFieldsGroupControllerTest extends WebTestCase
@@ -32,7 +33,7 @@ final class CustomFieldsGroupControllerTest extends WebTestCase
'PHP_AUTH_PW' => 'olala',
]);
//create the entity
// create the entity
$this->createCustomFieldsGroup($client);
// Edit the entity

View File

@@ -33,7 +33,7 @@ trait CustomFieldTestHelper
{
$kernel = static::$kernel;
//check a kernel is accessible
// check a kernel is accessible
$customFieldsGroup = $this->createMock(\Chill\CustomFieldsBundle\Entity\CustomFieldsGroup::class);
$customFieldsGroup->expects($this->once())
->method('getActiveCustomFields')
@@ -55,7 +55,7 @@ trait CustomFieldTestHelper
->getForm();
$kernel->getContainer()->get('twig.loader')
->addPath($kernel->getContainer()->getParameter('kernel.root_dir') .
->addPath($kernel->getContainer()->getParameter('kernel.root_dir').
'/Resources/views/', $namespace = 'test');
$content = $kernel

View File

@@ -23,6 +23,7 @@ use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
* - deserialize
*
* @internal
*
* @coversNothing
*/
final class CustomFieldsChoiceTest extends KernelTestCase
@@ -129,6 +130,7 @@ final class CustomFieldsChoiceTest extends KernelTestCase
* This test does not covers the case when the selected value is `_other`
*
* @param type $data
*
* @dataProvider serializedRepresentationDataProvider
*/
public function testDeserializeMultipleChoiceWithOther($data)
@@ -214,6 +216,7 @@ final class CustomFieldsChoiceTest extends KernelTestCase
* **without** an "allow_other" field.
*
* @param type $data
*
* @dataProvider serializedRepresentationDataProvider
*/
public function testDeserializeMultipleChoiceWithoutOther($data)
@@ -261,7 +264,7 @@ final class CustomFieldsChoiceTest extends KernelTestCase
$deserialized = $this->cfChoice->deserialize($data, $customField);
$this->assertSame([null], $deserialized);
//from single
// from single
$data = ['_other' => null, '_choices' => null];
$deserialized = $this->cfChoice->deserialize($data, $customField);
$this->assertSame([null], $deserialized);
@@ -274,6 +277,7 @@ final class CustomFieldsChoiceTest extends KernelTestCase
* If the value is in _other, the _other value should be in the _other field.
*
* @param type $data
*
* @dataProvider serializedRepresentationDataProvider
*/
public function testDeserializeSingleChoiceWithOther($data)
@@ -311,8 +315,8 @@ final class CustomFieldsChoiceTest extends KernelTestCase
$deserialized = $this->cfChoice->deserialize($data, $customField);
$this->assertSame(['_other' => 'something', '_choices' => '_other'], $deserialized);
//test with null data
//from a single to a single :
// test with null data
// from a single to a single :
$data = ['_other' => 'something', '_choices' => null];
$deserialized = $this->cfChoice->deserialize($data, $customField);
$this->assertSame(['_other' => 'something', '_choices' => null], $deserialized);
@@ -340,11 +344,11 @@ final class CustomFieldsChoiceTest extends KernelTestCase
$this->assertSame(['_other' => '', '_choices' => null], $deserialized);
}
/////////////////////////////////////////
// ///////////////////////////////////////
//
// test function deserialize
//
////////////////////////////////////////
// //////////////////////////////////////
/**
* Test if the representation of the data is deserialized to a single text.
@@ -352,6 +356,7 @@ final class CustomFieldsChoiceTest extends KernelTestCase
* If the value is in _other, the _other value should not be returned.
*
* @param type $data
*
* @dataProvider serializedRepresentationDataProvider
*/
public function testDeserializeSingleChoiceWithoutOther($data)
@@ -409,11 +414,11 @@ final class CustomFieldsChoiceTest extends KernelTestCase
$this->assertTrue($isEmpty);
}
/////////////////////////////////////////
// ///////////////////////////////////////
//
// test function isEmptyValue
//
////////////////////////////////////////
// //////////////////////////////////////
/**
* test the not empty with the not-empty data provider.
*

View File

@@ -11,15 +11,14 @@ declare(strict_types=1);
namespace Chill\CustomFieldsBundle\Tests\CustomFields;
use Chill\CustomFieldsBundle\CustomFields\CustomFieldNumber;
use Chill\CustomFieldsBundle\Entity\CustomField;
use Symfony\Component\Form\FormBuilderInterface;
use function count;
/**
* Test CustomFieldsNumber.
*
* @internal
*
* @coversNothing
*/
final class CustomFieldsNumberTest extends \Symfony\Bundle\FrameworkBundle\Test\WebTestCase
@@ -70,7 +69,7 @@ final class CustomFieldsNumberTest extends \Symfony\Bundle\FrameworkBundle\Test\
$this->assertTrue($form->isSynchronized());
$this->assertFalse($form->isValid());
$this->assertEquals(1, count($form['default']->getErrors()));
$this->assertEquals(1, \count($form['default']->getErrors()));
}
public function testCreateInvalidFormValueLowerThanMinimum()
@@ -90,7 +89,7 @@ final class CustomFieldsNumberTest extends \Symfony\Bundle\FrameworkBundle\Test\
$this->assertTrue($form->isSynchronized());
$this->assertFalse($form->isValid());
$this->assertEquals(1, count($form['default']->getErrors()));
$this->assertEquals(1, \count($form['default']->getErrors()));
}
public function testCreateValidForm()

View File

@@ -18,6 +18,7 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
/**
* @internal
*
* @coversNothing
*/
final class CustomFieldsTextTest extends WebTestCase

View File

@@ -18,6 +18,7 @@ use Symfony\Component\Form\Extension\Core\Type\IntegerType;
* Test the post-text extension.
*
* @internal
*
* @coversNothing
*/
final class PostTextIntegerExtensionTest extends KernelTestCase

View File

@@ -18,6 +18,7 @@ use Symfony\Component\Form\Extension\Core\Type\NumberType;
* Test the post-text extension.
*
* @internal
*
* @coversNothing
*/
final class PostTextNumberExtensionTest extends KernelTestCase

View File

@@ -18,6 +18,7 @@ use Symfony\Component\HttpFoundation\Response;
* Test that routes are correctly loaded.
*
* @internal
*
* @coversNothing
*/
final class RoutingLoaderTest extends WebTestCase

View File

@@ -12,13 +12,13 @@ declare(strict_types=1);
namespace Chill\CustomFields\Tests\Service;
use Chill\CustomFieldsBundle\Entity\CustomField;
use Chill\CustomFieldsBundle\Service\CustomFieldsHelper;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
/**
* Tests for custom fields helper.
*
* @internal
*
* @coversNothing
*/
final class CustomFieldsHelperTest extends KernelTestCase
@@ -52,7 +52,7 @@ final class CustomFieldsHelperTest extends KernelTestCase
$this->assertFalse($this->cfHelper->isEmptyValue($data, $this->randomCFText));
//empty value
// empty value
$data = [
$this->randomCFText->getSlug() => '',
];

View File

@@ -12,14 +12,13 @@ declare(strict_types=1);
namespace Chill\CustomFields\Tests\Templating\Twig;
use Chill\CustomFieldsBundle\Entity\CustomField;
use Chill\CustomFieldsBundle\Service\CustomFieldProvider;
use Chill\CustomFieldsBundle\Templating\Twig\CustomFieldRenderingTwig;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
/**
* Test the rendering of twig function which renders custom fields.
*
* @internal
*
* @coversNothing
*/
final class CustomFieldRenderingTwigTest extends KernelTestCase

View File

@@ -13,8 +13,6 @@ namespace Chill\CustomFields\Tests\Templating\Twig;
use Chill\CustomFieldsBundle\Entity\CustomField;
use Chill\CustomFieldsBundle\Entity\CustomFieldsGroup;
use Chill\CustomFieldsBundle\Service\CustomFieldProvider;
use Chill\CustomFieldsBundle\Templating\Twig\CustomFieldsGroupRenderingTwig;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
/**
@@ -22,6 +20,7 @@ use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
* the `chill_custom_fields_group_widget`.
*
* @internal
*
* @coversNothing
*/
final class CustomFieldsGroupRenderingTwigTest extends KernelTestCase
@@ -93,7 +92,6 @@ final class CustomFieldsGroupRenderingTwigTest extends KernelTestCase
}
/**
*
* @return CustomField
*/
private function getSimpleCustomFieldText(mixed $slug, mixed $name)

View File

@@ -22,7 +22,7 @@ class Version20151210155904 extends AbstractMigration
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('ALTER TABLE CustomField DROP required');
}
@@ -30,7 +30,7 @@ class Version20151210155904 extends AbstractMigration
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('ALTER TABLE customfield ADD required BOOLEAN DEFAULT FALSE');
}

View File

@@ -22,7 +22,7 @@ class Version20151210205610 extends AbstractMigration
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('ALTER TABLE custom_field_long_choice_options DROP CONSTRAINT cf_long_choice_self_referencing');
$this->addSql('DROP SEQUENCE custom_field_long_choice_options_id_seq CASCADE');
@@ -31,19 +31,19 @@ class Version20151210205610 extends AbstractMigration
public function up(Schema $schema): void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('CREATE SEQUENCE custom_field_long_choice_options_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
$this->addSql('CREATE TABLE custom_field_long_choice_options (id INT NOT NULL, '
. 'parent_id INT DEFAULT NULL, '
. 'key VARCHAR(15) NOT NULL, '
. 'text jsonb NOT NULL, '
. 'active boolean NOT NULL,'
. 'internal_key VARCHAR(50) NOT NULL DEFAULT \'\', '
. 'PRIMARY KEY(id))');
.'parent_id INT DEFAULT NULL, '
.'key VARCHAR(15) NOT NULL, '
.'text jsonb NOT NULL, '
.'active boolean NOT NULL,'
.'internal_key VARCHAR(50) NOT NULL DEFAULT \'\', '
.'PRIMARY KEY(id))');
$this->addSql('CREATE INDEX IDX_14BBB8E0727ACA70 ON custom_field_long_choice_options (parent_id)');
$this->addSql('ALTER TABLE custom_field_long_choice_options ADD CONSTRAINT cf_long_choice_self_referencing '
. 'FOREIGN KEY (parent_id) REFERENCES custom_field_long_choice_options (id) '
. 'NOT DEFERRABLE INITIALLY IMMEDIATE');
.'FOREIGN KEY (parent_id) REFERENCES custom_field_long_choice_options (id) '
.'NOT DEFERRABLE INITIALLY IMMEDIATE');
}
}