{"record":{"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":1198,"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":1180,"sourceCodeEnd":1216,"githubUrl":"https://github.com/laravel/framework/blob/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Collections/LazyCollection.php#L1180-L1216","documentation":"Thrown by LazyCollection::sliding($size, $step) when $size < 1. sliding builds overlapping 'window' chunks of $size elements advancing by $step; a window size below 1 cannot produce a valid chunk and is rejected with an InvalidArgumentException. The PHPDoc marks both params as positive-int.","triggerScenarios":"->sliding(0), ->sliding(-1); size derived from a length/width setting that can be zero; passing a configurable window size from a request.","commonSituations":"Time-series windowing where window size is configurable; pagination window math that yields 0 for small datasets; defaults left at 0 in config.","solutions":["Ensure size >= 1: ->sliding(max(1, $size), max(1, $step)).","Validate both size and step before calling.","Provide a sensible default (size=2) when sourced from user input."],"exampleFix":"// before\n$windows = $collection->sliding($windowSize, $step);\n// after\n$windowSize = max(1, $windowSize);\n$step = max(1, $step);\n$windows = $collection->sliding($windowSize, $step);","handlingStrategy":"validation","validationCode":"if ($size < 1 || $step < 1) {\n    throw new \\InvalidArgumentException('sliding size and step must be >= 1');\n}\nreturn $collection->sliding($size, $step);","typeGuard":"$size = (is_int($size) && $size >= 1) ? $size : 2;\n$step = (is_int($step) && $step >= 1) ? $step : 1;","tryCatchPattern":"try {\n    return $collection->sliding($size, $step);\n} catch (\\InvalidArgumentException $e) {\n    return $collection->sliding(2, 1);\n}","preventionTips":["Clamp both size and step: sliding(max(1,$size), max(1,$step)).","Validate window configs at the request boundary.","Default window size to 2 and step to 1 in config."],"tags":["lazy-collection","validation","argument-error","laravel"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}