{"record":{"id":"0ea2b53f3bd0a8c6","repo":"PHPOffice/PhpSpreadsheet","slug":"invalid-operation-for-text-value-cf-rule-wizard","errorCode":null,"errorMessage":"Invalid Operation for Text Value CF Rule Wizard","messagePattern":"Invalid Operation for Text Value CF Rule Wizard","errorType":"exception","errorClass":"PhpOffice\\PhpSpreadsheet\\Exception","httpStatus":null,"severity":"error","filePath":"src/PhpSpreadsheet/Style/ConditionalFormatting/Wizard/TextValue.php","lineNumber":146,"sourceCode":"            $condition = self::reverseAdjustCellRef($condition, $cellRange);\n        } elseif (\n            preg_match('/\\(\\)/', $condition)\n            || preg_match('/' . Calculation::CALCULATION_REGEXP_CELLREF_RELATIVE . '/i', $condition)\n        ) {\n            $wizard->operandValueType = Wizard::VALUE_TYPE_FORMULA;\n        }\n        $wizard->operand = $condition;\n\n        return $wizard;\n    }\n\n    /**\n     * @param mixed[] $arguments\n     */\n    public function __call(string $methodName, array $arguments): self\n    {\n        if (!isset(self::MAGIC_OPERATIONS[$methodName])) {\n            throw new Exception('Invalid Operation for Text Value CF Rule Wizard');\n        }\n\n        $this->operator(self::MAGIC_OPERATIONS[$methodName]);\n        //$this->operand(...$arguments);\n        if (count($arguments) < 2) {\n            /** @var string */\n            $arg0 = $arguments[0];\n            $this->operand($arg0);\n        } else {\n            /** @var string */\n            $arg0 = $arguments[0];\n            /** @var string */\n            $arg1 = $arguments[1];\n            $this->operand($arg0, $arg1);\n        }\n\n        return $this;\n    }","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/PHPOffice/PhpSpreadsheet/blob/65b080eef4d9fd11a5796135ab145883e5c3d6a6/src/PhpSpreadsheet/Style/ConditionalFormatting/Wizard/TextValue.php#L128-L164","documentation":"TextValue's magic methods come from a fixed MAGIC_OPERATIONS map: contains, doesNotContain (alias doesntContain), beginsWith (alias startsWith) and endsWith. Each takes the text operand plus an optional operand-type hint. Any other name - includes(), containsText(), like(), matches() - throws Invalid Operation because __call finds no key.","triggerScenarios":"->includes('foo'); ->like('foo'); ->containsText('foo') (the Excel operator name, not the wizard method); names outside the six supported aliases.","commonSituations":"Translating SQL LIKE or collection contains() vocabulary into CF rules; developers using Excel's operator names instead of the wizard's method names; dynamic invocation from configuration.","solutions":["Use only contains, doesNotContain, doesntContain, beginsWith, startsWith, endsWith","Validate dynamic method names against that list before invoking","Catch PhpSpreadsheetException around dynamic calls","For substring patterns not expressible as contains/beginsWith/endsWith, use an Expression rule with SEARCH()"],"exampleFix":"// before\n$textWizard = (new Wizard('A1:E10'))->newRule(Wizard::TEXT_VALUE);\n$textWizard->includes('foo');   // throws\n\n// after\n$textWizard->contains('foo');   // or doesNotContain/doesntContain/beginsWith/startsWith/endsWith","handlingStrategy":"validation","validationCode":"$allowed = ['contains', 'doesNotContain', 'doesntContain', 'beginsWith', 'startsWith', 'endsWith'];\n$method = $config['textOperator'];\nif (!in_array($method, $allowed, true)) {\n    throw new InvalidArgumentException('Unknown TextValue operator: ' . $method);\n}\n$wizard->$method($text);","typeGuard":null,"tryCatchPattern":"use PhpOffice\\PhpSpreadsheet\\Exception as PhpSpreadsheetException;\n\ntry {\n    $textWizard->$method($text);\n} catch (PhpSpreadsheetException $e) {\n    throw new InvalidArgumentException('Invalid TextValue operator: ' . $method, 0, $e);\n}","preventionTips":["Use only contains, doesNotContain, doesntContain, beginsWith, startsWith, endsWith","Excel operator names (containsText, beginsWith) are not the method names for contains","Avoid SQL-style guesses like includes() or like()","Whitelist operator names arriving from config or user input"],"tags":["php","phpspreadsheet","conditional-formatting","wizard","text-value","magic-methods"],"backgroundTag":"invalid-fluent-builder-method","analyzedSha":"65b080eef4d9fd11a5796135ab145883e5c3d6a6","analyzedAt":"2026-08-17T05:40:41.646Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}