php-translation / extractor

Extracts translation strings from source code
MIT License
126 stars 33 forks source link

Ignoring extract errors #85

Open lsv opened 6 years ago

lsv commented 6 years ago

In a choicetype form element, Im using a Enumtype for choices

$builder->add('gender', ChoiceType::class, [
            'label' => 'Gender',
            'choices' => GenderEnumType::getChoices(),
            'required' => $options['fullprofile'],
            'validation_groups' => $validationGroups,
        ]);

The extractor says this

[ERROR] /home/lsv/Projects/findfesten.dk/src/Form/ProfileType.php                                                      
         Line: 65                                                                                                       
         Message: Form choice is not an array       

Which is indeed 'choices' => GenderEnumType::getChoices(), I know that this is a an array

protected static $choices = [
        self::UNKNOWN => 'Not provided',
        self::MALE => 'Male',
        self::FEMALE => 'Female',
    ];

public static function getChoices(): array
{
    return \array_flip(static::$choices);
}

Is there a way to ignore this line? with a annotations or something? - I dont want to ignore the whole form, but just this single line - Something like this

$builder->add('gender', ChoiceType::class, [
            'label' => 'Gender',
            /** @IgnoreTransNextLine */
            'choices' => GenderEnumType::getChoices(),
            'required' => $options['fullprofile'],
            'validation_groups' => $validationGroups,
        ]);
Nyholm commented 6 years ago

Thank you for this issue. Im not sure if this is documented or not. But this should work:

$builder->add('gender', ChoiceType::class, [
            'label' => 'Gender',
            /** @Ignore */
            'choices' => GenderEnumType::getChoices(),
            'required' => $options['fullprofile'],
            'validation_groups' => $validationGroups,
        ]);