{"record":{"id":"198532aed58912fb","repo":"PHPOffice/PHPWord","slug":"invalid-value-dirty-or-clean-possible","errorCode":null,"errorMessage":"Invalid value, dirty or clean possible","messagePattern":"Invalid value, dirty or clean possible","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/PhpWord/ComplexType/ProofState.php","lineNumber":66,"sourceCode":"     * Grammatical Checking State.\n     *\n     * @var string\n     */\n    private $grammar;\n\n    /**\n     * Set the Spell Checking State (dirty or clean).\n     *\n     * @param string $spelling\n     *\n     * @return self\n     */\n    public function setSpelling($spelling)\n    {\n        if ($spelling == self::CLEAN || $spelling == self::DIRTY) {\n            $this->spelling = $spelling;\n        } else {\n            throw new InvalidArgumentException('Invalid value, dirty or clean possible');\n        }\n\n        return $this;\n    }\n\n    /**\n     * Get the Spell Checking State.\n     *\n     * @return string\n     */\n    public function getSpelling()\n    {\n        return $this->spelling;\n    }\n\n    /**\n     * Set the Grammatical Checking State (dirty or clean).\n     *","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/PHPOffice/PHPWord/blob/aef95c04151b5633cc505f672ddd6a71da900ee1/src/PhpWord/ComplexType/ProofState.php#L48-L84","documentation":"ProofState::setSpelling() only accepts the class constants CLEAN or DIRTY (compared loosely with ==). Any other value throws an InvalidArgumentException with the message 'Invalid value, dirty or clean possible'. It mirrors the OOXML proofState spelling attribute, which may only be 'clean' or 'dirty'.","triggerScenarios":"Calling setSpelling() with a value other than ProofState::CLEAN or ProofState::DIRTY, e.g. true/false, 0/1, or strings like 'ok' or 'checked', directly or through a style array.","commonSituations":"Passing booleans to indicate proof state; using lowercase literals with different casing; porting values from other document libraries that use different enums.","solutions":["Pass ProofState::CLEAN or ProofState::DIRTY constants exactly","Map your boolean/state value to the constants before calling: $state ? ProofState::DIRTY : ProofState::CLEAN","Validate input with in_array($value, [ProofState::CLEAN, ProofState::DIRTY]) before the call"],"exampleFix":"// before\n$proofState->setSpelling(true);\n// after\n$proofState->setSpelling(ProofState::DIRTY);","handlingStrategy":"validation","validationCode":"if ($spelling !== ProofState::CLEAN && $spelling !== ProofState::DIRTY) {\n    throw new UnexpectedValueException('spelling must be ProofState::CLEAN or ProofState::DIRTY');\n}","typeGuard":"function isValidProofState(?string $v): bool {\n    return $v === ProofState::CLEAN || $v === ProofState::DIRTY;\n}","tryCatchPattern":"try {\n    $proofState->setSpelling($value);\n} catch (\\InvalidArgumentException $e) {\n    $proofState->setSpelling(ProofState::CLEAN);\n}","preventionTips":["Never pass booleans or integers; only the CLEAN/DIRTY constants","Map application state to constants in one helper function","Note the setter uses loose == comparison, but strict constant usage avoids surprises"],"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"}