{"record":{"id":"bd562ed6193d07d5","repo":"symfony/finder","slug":"don-t-understand-s-as-a-number-test","errorCode":null,"errorMessage":"Don't understand \"%s\" as a number test.","messagePattern":"Don't understand \"(.+?)\" as a number test\\.","errorType":"validation","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"Comparator/NumberComparator.php","lineNumber":45,"sourceCode":" *\n * @author    Fabien Potencier <fabien@symfony.com> PHP port\n * @author    Richard Clamp <richardc@unixbeard.net> Perl version\n * @copyright 2004-2005 Fabien Potencier <fabien@symfony.com>\n * @copyright 2002 Richard Clamp <richardc@unixbeard.net>\n *\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;","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/symfony/finder/blob/4d6c057bfd67c5a93e8025c85ca9364cba7e260a/Comparator/NumberComparator.php#L27-L63","documentation":"NumberComparator's constructor validates the test against '#^\\s*(==|!=|[<>]=?)?\\s*([0-9\\.]+)\\s*([kmg]i?)?\\s*$#i'; if the string is null or doesn't match (wrong characters, unsupported operators, text mixed in), it throws InvalidArgumentException with this message, echoing 'null' when null was passed.","triggerScenarios":"Finder::size(null), ->size('about 100'), ->size('==100MB') (unsupported 'b' suffix/multi-char units), ->size('>1,000') (comma), ->size('<>10'), or any string with characters outside digits, dot, optional k/m/g/i suffix.","commonSituations":"Users writing human sizes like '10 MB' instead of '10M' or '10Mi', passing null from unresolved config, using '===' or '=>' operators, thousands separators.","solutions":["Format the test as [operator] number [k|m|g][i], e.g. '> 10M', '>= 1Gi', '== 500k'","Reject/normalize null before calling, and validate with the same regex","Remove commas, currency signs, and unsupported unit suffixes like 'b' or 'KB'"],"exampleFix":"// before\n$finder->size('>= 10 MB'); // no match\n// after\n$finder->size('>= 10M'); // or '>= 10Mi' for binary megabytes","handlingStrategy":"validation","validationCode":"if (!is_string($size) || !preg_match('#^\\s*(==|!=|[<>]=?)?\\s*([0-9\\.]+)\\s*([kmg]i?)?\\s*$#i', $size)) { throw new \\InvalidArgumentException(\"Bad size test: $size\"); }","typeGuard":"function isValidSizeTest(mixed $v): bool { return is_string($v) && (bool) preg_match('#^\\s*(==|!=|[<>]=?)?\\s*([0-9\\.]+)\\s*([kmg]i?)?\\s*$#i', $v); }","tryCatchPattern":"try { $finder->size($size); } catch (\\InvalidArgumentException $e) { /* handle bad size test */ }","preventionTips":["Use the documented format: [op] number [k|m|g][i], e.g. '> 10M'","Never pass null; default to a valid expression","Strip commas, spaces inside the number, and unsupported units like 'MB'","Reuse the library's regex in a shared validator for config values"],"tags":["numbers","parsing","finder","size-filter"],"backgroundTag":"invalid-argument-format","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"}