{"record":{"id":"26f422469cce4a94","repo":"symfony/translation","slug":"the-expansion-factor-must-be-greater-than-or-equal-to-1","errorCode":null,"errorMessage":"The expansion factor must be greater than or equal to 1.","messagePattern":"The expansion factor must be greater than or equal to 1\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"PseudoLocalizationTranslator.php","lineNumber":75,"sourceCode":"     *      default: false\n     *      description: parse the translated string as HTML - looking for HTML tags has a performance impact but allows to preserve them from alterations - it also allows to compute the visible translated string length which is useful to correctly expand or when it contains HTML\n     *      warning: unclosed tags are unsupported, they will be fixed (closed) by the parser - eg, \"foo <div>bar\" => \"foo <div>bar</div>\"\n     *\n     *  * localizable_html_attributes:\n     *      type: string[]\n     *      default: []\n     *      description: the list of HTML attributes whose values can be altered - it is only useful when the \"parse_html\" option is set to true\n     *      example: if [\"title\"], and with the \"accents\" option set to true, \"<a href=\"#\" title=\"Go to your profile\">Profile</a>\" => \"<a href=\"#\" title=\"Ĝö ţö ýöûŕ þŕöƒîļé\">Þŕöƒîļé</a>\" - if \"title\" was not in the \"localizable_html_attributes\" list, the title attribute data would be left unchanged.\n     */\n    public function __construct(\n        private TranslatorInterface $translator,\n        array $options = [],\n    ) {\n        $this->translator = $translator;\n        $this->accents = $options['accents'] ?? true;\n\n        if (1.0 > ($this->expansionFactor = $options['expansion_factor'] ?? 1.0)) {\n            throw new \\InvalidArgumentException('The expansion factor must be greater than or equal to 1.');\n        }\n\n        $this->brackets = $options['brackets'] ?? true;\n\n        $this->parseHTML = $options['parse_html'] ?? false;\n        if ($this->parseHTML && !$this->accents && 1.0 === $this->expansionFactor) {\n            $this->parseHTML = false;\n        }\n\n        $this->localizableHTMLAttributes = $options['localizable_html_attributes'] ?? [];\n    }\n\n    public function trans(string $id, array $parameters = [], ?string $domain = null, ?string $locale = null): string\n    {\n        $trans = '';\n        $visibleText = '';\n\n        foreach ($this->getParts($this->translator->trans($id, $parameters, $domain, $locale)) as [$visible, $localizable, $text]) {","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/symfony/translation/blob/ae9e8a51bc29780d63c7f9efd6005d7c875e100b/PseudoLocalizationTranslator.php#L57-L93","documentation":"PseudoLocalizationTranslator validates the 'expansion_factor' option at construction: values below 1.0 would shrink or not expand pseudo-localized strings, defeating the purpose, so it throws InvalidArgumentException.","triggerScenarios":"new PseudoLocalizationTranslator($translator, ['expansion_factor' => 0.5]) or a config value read from YAML/env that is 0 or negative; a typo mapping e.g. 0.1 instead of 1.x.","commonSituations":"Loading the factor from an .env variable parsed as float 0 when unset; experimenting with exaggerated pseudo-localization configs in test environments.","solutions":["Set expansion_factor to a value >= 1.0 (e.g. 1.3)","Validate the config value before constructing the translator","Remove the option to use the default 1.0"],"exampleFix":"// before\n$t = new PseudoLocalizationTranslator($t, ['expansion_factor' => 0.5]);\n// after\n$factor = max(1.0, (float) ($_ENV['PSEUDO_EXPANSION'] ?? 1.0));\n$t = new PseudoLocalizationTranslator($t, ['expansion_factor' => $factor]);","handlingStrategy":"validation","validationCode":"$factor = $options['expansion_factor'] ?? 1.0;\nif (!is_numeric($factor) || (float) $factor < 1.0) {\n    throw new \\InvalidArgumentException('expansion_factor must be >= 1.0');\n}","typeGuard":"function isValidExpansionFactor(mixed $v): bool {\n    return is_numeric($v) && (float) $v >= 1.0;\n}","tryCatchPattern":"try {\n    $pseudo = new PseudoLocalizationTranslator($translator, $options);\n} catch (\\InvalidArgumentException $e) {\n    $pseudo = new PseudoLocalizationTranslator($translator); // safe defaults\n}","preventionTips":["Clamp configured values: max(1.0, (float)$envVar)","Validate option values from YAML/env before constructing","Use defaults when the option is unset or zero"],"tags":["php","translation","config"],"backgroundTag":"value-out-of-range","analyzedSha":"ae9e8a51bc29780d63c7f9efd6005d7c875e100b","analyzedAt":"2026-09-15T22:29:15.305Z","contentChangedAt":"2026-09-15T22:29:15.305Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}