{"record":{"id":"e2f15cb931606823","repo":"Intervention/image","slug":"invalid-sharpening-level-must-be-int-0-max","errorCode":null,"errorMessage":"Invalid sharpening level. Must be int<0, max>","messagePattern":"Invalid sharpening level\\. Must be int<0, max>","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Modifiers/SharpenModifier.php","lineNumber":18,"sourceCode":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Intervention\\Image\\Modifiers;\n\nuse Intervention\\Image\\Drivers\\SpecializableModifier;\nuse Intervention\\Image\\Exceptions\\InvalidArgumentException;\n\nclass SharpenModifier extends SpecializableModifier\n{\n    /**\n     * @throws InvalidArgumentException\n     */\n    public function __construct(public int $level)\n    {\n        if ($this->level < 0) {\n            throw new InvalidArgumentException('Invalid sharpening level. Must be int<0, max>');\n        }\n    }\n}\n","sourceCodeStart":1,"sourceCodeEnd":22,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Modifiers/SharpenModifier.php#L1-L22","documentation":"SharpenModifier backs $image->sharpen($level) and accepts any int greater than or equal to 0. The level controls sharpening intensity; 0 is a valid no-op value, but negative values have no defined meaning, so the constructor throws InvalidArgumentException with the message 'Invalid sharpening level. Must be int<0, max>' (the int<0, max> notation is the PHPStan range for non-negative integers).","triggerScenarios":"Calling $image->sharpen(-1) or new SharpenModifier(-10). Commonly the level is computed from user input, a signed calculation, or a config value that was mistyped with a minus sign.","commonSituations":"UI sliders or API parameters that allow the user to submit a negative sharpen amount; arithmetic on a delta (e.g. sharpen($current - $amount)) that underflows below 0; configuration files copied from another tool where the sign convention differs.","solutions":["Clamp the level to 0 before calling: $image->sharpen(max(0, $level))","Cast and validate external input: $level = (int) $input; if ($level < 0) reject or normalize","If a negative value means 'blur' in your domain, translate it to the appropriate blur() call instead of passing it to sharpen()"],"exampleFix":"// before\n$image->sharpen($request->input('sharpen'));\n\n// after\n$level = max(0, (int) $request->input('sharpen'));\n$image->sharpen($level);","handlingStrategy":"validation","validationCode":"// Clamp before sharpening\n$level = (int) $input['sharpen'];\nif ($level < 0) {\n    $level = 0; // or reject the request\n}\n$image->sharpen($level);","typeGuard":"function isValidSharpenLevel(mixed $level): bool\n{\n    return is_int($level) && $level >= 0;\n}","tryCatchPattern":"use Intervention\\Image\\Exceptions\\InvalidArgumentException;\n\ntry {\n    $image->sharpen($level);\n} catch (InvalidArgumentException $e) {\n    // message: 'Invalid sharpening level. Must be int<0, max>'\n    $image->sharpen(0);\n}","preventionTips":["Treat sharpen level as an unsigned int in your input validation (min: 0)","Clamp external values with max(0, (int) $value) before passing them to sharpen()","Keep sharpen presets in config and validate them once at load time"],"tags":["sharpen","filter","constructor","argument-validation","intervention-image"],"backgroundTag":"out-of-range-argument","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}