{"record":{"id":"a12bfa2afbdcb14a","repo":"symfony/translation","slug":"batch-argument-must-be-one-of-s-s-s","errorCode":null,"errorMessage":"$batch argument must be one of [\"%s\", \"%s\", \"%s\"].","messagePattern":"\\$batch argument must be one of \\[\"(.+?)\", \"(.+?)\", \"(.+?)\"\\]\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"Catalogue/AbstractOperation.php","lineNumber":161,"sourceCode":"    }\n\n    /**\n     * @param self::*_BATCH $batch\n     */\n    public function moveMessagesToIntlDomainsIfPossible(string $batch = self::ALL_BATCH): void\n    {\n        // If MessageFormatter class does not exist, intl domains are not supported.\n        if (!class_exists(\\MessageFormatter::class)) {\n            return;\n        }\n\n        foreach ($this->getDomains() as $domain) {\n            $intlDomain = $domain.MessageCatalogueInterface::INTL_DOMAIN_SUFFIX;\n            $messages = match ($batch) {\n                self::OBSOLETE_BATCH => $this->getObsoleteMessages($domain),\n                self::NEW_BATCH => $this->getNewMessages($domain),\n                self::ALL_BATCH => $this->getMessages($domain),\n                default => throw new \\InvalidArgumentException(\\sprintf('$batch argument must be one of [\"%s\", \"%s\", \"%s\"].', self::ALL_BATCH, self::NEW_BATCH, self::OBSOLETE_BATCH)),\n            };\n\n            if (!$messages || (!$this->source->all($intlDomain) && $this->source->all($domain))) {\n                continue;\n            }\n\n            $result = $this->getResult();\n            $allIntlMessages = $result->all($intlDomain);\n            $currentMessages = array_diff_key($messages, $result->all($domain));\n            $result->replace($currentMessages, $domain);\n            $result->replace($allIntlMessages + $messages, $intlDomain);\n\n            foreach ($result->getCatalogueMetadata('', $domain) ?? [] as $key => $value) {\n                if (null === $this->result->getCatalogueMetadata($key, $intlDomain)) {\n                    $result->setCatalogueMetadata($key, $value, $intlDomain);\n                }\n            }\n        }","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/symfony/translation/blob/ae9e8a51bc29780d63c7f9efd6005d7c875e100b/Catalogue/AbstractOperation.php#L143-L179","documentation":"moveMessagesToIntlDomainsIfPossible() validates the $batch argument against the three class constants ALL_BATCH, NEW_BATCH, OBSOLETE_BATCH inside a match expression. Any other value hits the default arm and throws InvalidArgumentException.","triggerScenarios":"Calling $operation->moveMessagesToIntlDomainsIfPossible('new') or 'all' instead of the constants; passing null, an int, or a mistyped string.","commonSituations":"Wrapping diff()/intersect()/custom operations and forwarding an unvalidated batch parameter; older code written before the constants existed.","solutions":["Use the constants: AbstractOperation::ALL_BATCH, ::NEW_BATCH, ::OBSOLETE_BATCH","Validate/normalize the $batch input before forwarding it to the operation"],"exampleFix":"// before\n$operation->moveMessagesToIntlDomainsIfPossible('new');\n// after\n$operation->moveMessagesToIntlDomainsIfPossible(AbstractOperation::NEW_BATCH);","handlingStrategy":"validation","validationCode":"if (!in_array($batch, [AbstractOperation::ALL_BATCH, AbstractOperation::NEW_BATCH, AbstractOperation::OBSOLETE_BATCH], true)) {\n    throw new \\InvalidArgumentException('Invalid batch');\n}","typeGuard":"function isValidBatch(string $batch): bool {\n    return in_array($batch, [AbstractOperation::ALL_BATCH, AbstractOperation::NEW_BATCH, AbstractOperation::OBSOLETE_BATCH], true);\n}","tryCatchPattern":"try {\n    $operation->moveMessagesToIntlDomainsIfPossible($batch);\n} catch (\\InvalidArgumentException $e) {\n    $this->logger->warning('Invalid batch argument', ['batch' => $batch]);\n}","preventionTips":["Only pass AbstractOperation::*_BATCH constants","Typehint batch params as string and validate at boundaries","Grep codebase for literal 'all'/'new'/'obsolete' batch strings when upgrading"],"tags":["php","translation","invalid-argument"],"backgroundTag":"invalid-enum-argument","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"}