{"id":"366743ac97778e9a","repo":"laravel/framework","slug":"size-value-must-be-at-least-1-366743","errorCode":null,"errorMessage":"Size value must be at least 1.","messagePattern":"Size value must be at least 1\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Collections/LazyCollection.php","lineNumber":1196,"sourceCode":"    #[\\Override]\n    public function shuffle()\n    {\n        return $this->passthru(__FUNCTION__, []);\n    }\n\n    /**\n     * Create chunks representing a \"sliding window\" view of the items in the collection.\n     *\n     * @param  positive-int  $size\n     * @param  positive-int  $step\n     * @return static<int, static>\n     *\n     * @throws \\InvalidArgumentException\n     */\n    public function sliding($size = 2, $step = 1)\n    {\n        if ($size < 1) {\n            throw new InvalidArgumentException('Size value must be at least 1.');\n        } elseif ($step < 1) {\n            throw new InvalidArgumentException('Step value must be at least 1.');\n        }\n\n        return new static(function () use ($size, $step) {\n            $iterator = $this->getIterator();\n\n            $chunk = [];\n\n            while ($iterator->valid()) {\n                $chunk[$iterator->key()] = $iterator->current();\n\n                if (count($chunk) == $size) {\n                    yield (new static($chunk))->tap(function () use (&$chunk, $step) {\n                        $chunk = array_slice($chunk, $step, null, true);\n                    });\n\n                    // If the $step between chunks is bigger than each chunk's $size","sourceCodeStart":1178,"sourceCodeEnd":1214,"githubUrl":"https://github.com/laravel/framework/blob/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Collections/LazyCollection.php#L1178-L1214","documentation":"Thrown by LazyCollection::sliding($size, $step) when $size is less than 1. sliding() creates a moving window of $size elements; a window size of 0 or negative has no meaning. The size guard runs before the step guard.","triggerScenarios":"Calling $lazy->sliding(0) or $lazy->sliding(-1). Typically $size is computed from a config or input value that can be 0.","commonSituations":"Config-driven window sizes that default to 0 when unset. Computing window size from a length that may be 0.","solutions":["Pass a size >= 1; clamp with max(1, $size).","Default the source variable to a positive value (default arg is already 2).","Guard the call when size may be 0."],"exampleFix":"// before\n$windows = $lazy->sliding($windowSize);\n\n// after\n$windows = $lazy->sliding(max(1, (int) $windowSize));","handlingStrategy":"validation","validationCode":"$size = max(1, (int) $size);\n$windows = $lazy->sliding($size, $step);","typeGuard":"function isPositiveWindowSize($size): bool { return is_int($size) && $size >= 1; }","tryCatchPattern":"try {\n    $windows = $lazy->sliding($size, $step);\n} catch (\\InvalidArgumentException $e) {\n    $windows = $lazy->sliding(2, max(1, $step));\n}","preventionTips":["Default window-size config to a positive value.","Guard dynamically computed sizes against 0."],"tags":["laravel","collections","lazy","validation","invalid-argument"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}