{"record":{"id":"7fbe75ac02d64d8d","repo":"PHPOffice/PHPWord","slug":"invalid-value-alignments-of-implode-alignmenttypes-possible","errorCode":null,"errorMessage":"Invalid value, alignments of ' . implode(', ', $alignmentTypes) . ' possible","messagePattern":"Invalid value, alignments of ' \\. implode\\(', ', \\$alignmentTypes\\) \\. ' possible","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/PhpWord/ComplexType/RubyProperties.php","lineNumber":111,"sourceCode":"\n    /**\n     * Set the Ruby Alignment (center, distributeLetter, distributeSpace, left, right, rightVertical).\n     */\n    public function setAlignment(string $alignment): self\n    {\n        $alignmentTypes = [\n            self::ALIGNMENT_CENTER,\n            self::ALIGNMENT_DISTRIBUTE_LETTER,\n            self::ALIGNMENT_DISTRIBUTE_SPACE,\n            self::ALIGNMENT_LEFT,\n            self::ALIGNMENT_RIGHT,\n            self::ALIGNMENT_RIGHT_VERTICAL,\n        ];\n\n        if (in_array($alignment, $alignmentTypes)) {\n            $this->alignment = $alignment;\n        } else {\n            throw new InvalidArgumentException('Invalid value, alignments of ' . implode(', ', $alignmentTypes) . ' possible');\n        }\n\n        return $this;\n    }\n\n    /**\n     * Get the ruby font face size.\n     */\n    public function getFontFaceSize(): float\n    {\n        return $this->fontFaceSize;\n    }\n\n    /**\n     * Set the ruby font face size.\n     */\n    public function setFontFaceSize(float $size): self\n    {","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/PHPOffice/PHPWord/blob/aef95c04151b5633cc505f672ddd6a71da900ee1/src/PhpWord/ComplexType/RubyProperties.php#L93-L129","documentation":"RubyProperties::setAlignment() validates the ruby (furigana) text alignment against a whitelist of ALIGNMENT_* class constants (e.g. left/center/right, each with a vertical variant). Any other value throws an InvalidArgumentException listing all valid alignments.","triggerScenarios":"Calling setAlignment() with an arbitrary string (e.g. 'center' when only CENTER_VERTICAL exists, or 'justify') directly or via RubyProperties constructor/style array; also hit when the OOXML reader feeds unexpected values (readRubyProperties/parseRuby paths).","commonSituations":"Guessing alignment names instead of using constants; confusing horizontal-only names with the *_VERTICAL constants required; copying w:rubyAlign attribute values with wrong casing.","solutions":["Use one of the RubyProperties::ALIGNMENT_* constants exactly (check the constant list above the setter)","Use the *_VERTICAL variants where horizontal names alone are not in the whitelist","Validate user input against the constant list before calling"],"exampleFix":"// before\n$ruby->setAlignment('center');\n// after\n$ruby->setAlignment(RubyProperties::ALIGNMENT_CENTER_VERTICAL);","handlingStrategy":"validation","validationCode":"$allowed = [\n    RubyProperties::ALIGNMENT_LEFT_VERTICAL, RubyProperties::ALIGNMENT_CENTER_VERTICAL, RubyProperties::ALIGNMENT_RIGHT_VERTICAL,\n    RubyProperties::ALIGNMENT_LEFT, RubyProperties::ALIGNMENT_CENTER, RubyProperties::ALIGNMENT_RIGHT,\n    RubyProperties::ALIGNMENT_DISTRIBUTED_VERTICAL,\n];\nif (!in_array($alignment, $allowed, true)) {\n    throw new UnexpectedValueException('alignment must be a RubyProperties::ALIGNMENT_* constant');\n}","typeGuard":"function isValidRubyAlignment(?string $v): bool {\n    $ref = new ReflectionClass(RubyProperties::class);\n    return in_array($v, array_values($ref->getConstants()), true);\n}","tryCatchPattern":"try {\n    $ruby->setAlignment($alignment);\n} catch (\\InvalidArgumentException $e) {\n    $ruby->setAlignment(RubyProperties::ALIGNMENT_CENTER_VERTICAL);\n}","preventionTips":["Check the ALIGNMENT_* constant list in RubyProperties.php — horizontal-only names may not exist","Use the reflection-based constant list to validate dynamically","Prefer *_VERTICAL variants when rendering vertical ruby text"],"tags":["php","phpword","invalid-argument","enum"],"backgroundTag":"invalid-enum-value","analyzedSha":"aef95c04151b5633cc505f672ddd6a71da900ee1","analyzedAt":"2026-09-14T10:53:58.933Z","contentChangedAt":"2026-09-14T10:53:58.933Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}