{"record":{"id":"02b7fe774170060a","repo":"symfony/finder","slug":"invalid-number-s","errorCode":null,"errorMessage":"Invalid number \"%s\".","messagePattern":"Invalid number \"(.+?)\"\\.","errorType":"validation","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"Comparator/NumberComparator.php","lineNumber":50,"sourceCode":" *\n * @see http://physics.nist.gov/cuu/Units/binary.html\n */\nclass NumberComparator extends Comparator\n{\n    /**\n     * @param string|null $test A comparison string or null\n     *\n     * @throws \\InvalidArgumentException If the test is not understood\n     */\n    public function __construct(?string $test)\n    {\n        if (null === $test || !preg_match('#^\\s*(==|!=|[<>]=?)?\\s*([0-9\\.]+)\\s*([kmg]i?)?\\s*$#i', $test, $matches)) {\n            throw new \\InvalidArgumentException(\\sprintf('Don\\'t understand \"%s\" as a number test.', $test ?? 'null'));\n        }\n\n        $target = $matches[2];\n        if (!is_numeric($target)) {\n            throw new \\InvalidArgumentException(\\sprintf('Invalid number \"%s\".', $target));\n        }\n        if (isset($matches[3])) {\n            // magnitude\n            switch (strtolower($matches[3])) {\n                case 'k':\n                    $target *= 1000;\n                    break;\n                case 'ki':\n                    $target *= 1024;\n                    break;\n                case 'm':\n                    $target *= 1000000;\n                    break;\n                case 'mi':\n                    $target *= 1024 * 1024;\n                    break;\n                case 'g':\n                    $target *= 1000000000;","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/symfony/finder/blob/4d6c057bfd67c5a93e8025c85ca9364cba7e260a/Comparator/NumberComparator.php#L32-L68","documentation":"After NumberComparator's regex matched and captured a numeric-looking target, PHP's is_numeric() check failed on it — e.g. strings like '1.2.3' or '..' that match the loose [0-9\\.]+ pattern but aren't valid numbers — so InvalidArgumentException is thrown with 'Invalid number'.","triggerScenarios":"new NumberComparator('1.2.3'), ->size('..'), ->size('...5') — strings whose digit/dot-only pattern matches the regex but fail is_numeric().","commonSituations":"Malformed config values with multiple dots, typo'd decimal separators, concatenated strings producing '..' patterns.","solutions":["Supply a valid plain number with at most one decimal point: '10', '1.5'","Sanitize input with filter_var($v, FILTER_VALIDATE_FLOAT) or is_numeric() before constructing","Fix config parsing that concatenates or duplicates dots"],"exampleFix":"// before\n$finder->size('> 1.2.3'); // matches regex but is_numeric fails\n// after\n$finder->size('> 1.2');","handlingStrategy":"validation","validationCode":"if (!is_numeric($num)) { throw new \\InvalidArgumentException(\"Not a valid number: $num\"); }","typeGuard":"function isPlainNumber(mixed $v): bool { return is_numeric($v) && substr_count((string) $v, '.') <= 1; }","tryCatchPattern":"try { new NumberComparator('> 1.2'); } catch (\\InvalidArgumentException $e) { /* handle invalid number */ }","preventionTips":["Run is_numeric() or filter_var(..., FILTER_VALIDATE_FLOAT) before constructing","Reject inputs containing multiple dots","Sanitize values that pass through string concatenation or config parsing"],"tags":["numbers","parsing","finder"],"backgroundTag":"invalid-argument-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"}