{"record":{"id":"6efdc531829375b8","repo":"symfony/finder","slug":"invalid-operator-s","errorCode":null,"errorMessage":"Invalid operator \"%s\".","messagePattern":"Invalid operator \"(.+?)\"\\.","errorType":"validation","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"Comparator/Comparator.php","lineNumber":26,"sourceCode":" * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nnamespace Symfony\\Component\\Finder\\Comparator;\n\n/**\n * @author Fabien Potencier <fabien@symfony.com>\n */\nclass Comparator\n{\n    private string $operator;\n\n    public function __construct(\n        private string $target,\n        string $operator = '==',\n    ) {\n        if (!\\in_array($operator, ['>', '<', '>=', '<=', '==', '!='], true)) {\n            throw new \\InvalidArgumentException(\\sprintf('Invalid operator \"%s\".', $operator));\n        }\n\n        $this->operator = $operator;\n    }\n\n    /**\n     * Gets the target value.\n     */\n    public function getTarget(): string\n    {\n        return $this->target;\n    }\n\n    /**\n     * Gets the comparison operator.\n     */\n    public function getOperator(): string\n    {","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/symfony/finder/blob/4d6c057bfd67c5a93e8025c85ca9364cba7e260a/Comparator/Comparator.php#L8-L44","documentation":"Comparator::validate() (invoked from the constructor) rejects any comparison operator outside the whitelist ['>', '<', '>=', '<=', '==', '!=']. The library throws InvalidArgumentException to fail fast when an operator string is misspelled or unsupported.","triggerScenarios":"Passing any operator string other than the six supported ones to new Comparator($target, $operator), e.g. '=>', '=', '<>', '===', or with stray whitespace.","commonSituations":"Handwritten Finder date/size comparisons, config files supplying operators as free-form strings, porting code that used '=>' or '===' from other expression languages.","solutions":["Use one of the exact operators: >, <, >=, <=, ==, !=","Replace '=>' with '>=' and '=' with '==', '<>' with '!='","Trim/normalize operator input before constructing the Comparator"],"exampleFix":"// before\n$c = new Comparator('100', '=>');\n// after\n$c = new Comparator('100', '>=');","handlingStrategy":"validation","validationCode":"$allowed = ['>', '<', '>=', '<=', '==', '!=']; if (!in_array($op, $allowed, true)) { throw new \\InvalidArgumentException(\"Bad operator: $op\"); }","typeGuard":"function isValidComparatorOp(mixed $op): bool { return is_string($op) && in_array($op, ['>','<','>=','<=','==','!='], true); }","tryCatchPattern":"try { $c = new Comparator($target, $op); } catch (\\InvalidArgumentException $e) { /* handle invalid operator */ }","preventionTips":["Only ever pass the six whitelisted operator strings","Centralize operator construction in a helper that validates input","Trim and normalize user/config-supplied operators before use","Add unit tests covering each accepted operator"],"tags":["invalid-argument","validation","finder"],"backgroundTag":"invalid-enum-value","analyzedSha":"4d6c057bfd67c5a93e8025c85ca9364cba7e260a","analyzedAt":"2026-09-13T07:49:33.433Z","contentChangedAt":"2026-09-13T07:49:33.433Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}