{"record":{"id":"1e273424ca96f92d","repo":"laravel/framework","slug":"size-value-must-be-at-least-1","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/Collection.php","lineNumber":1319,"sourceCode":"     */\n    public function shuffle()\n    {\n        return $this->newInstance(Arr::shuffle($this->items));\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        $chunks = floor(($this->count() - $size) / $step) + 1;\n\n        return static::times($chunks, fn ($number) => $this->slice(($number - 1) * $step, $size));\n    }\n\n    /**\n     * Skip the first {$count} items.\n     *\n     * @param  int  $count\n     * @return static\n     */\n    public function skip($count)\n    {\n        return $this->slice($count);","sourceCodeStart":1301,"sourceCodeEnd":1337,"githubUrl":"https://github.com/laravel/framework/blob/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Collections/Collection.php#L1301-L1337","documentation":"Thrown by Collection::sliding($size, $step) when $size < 1. A sliding window of size 0 or negative is meaningless; the method guards size first, then step (see error 58). Default size is 2.","triggerScenarios":"Calling $collection->sliding(0) or ->sliding(-1, 1), or passing a computed size <= 0.","commonSituations":"Size derived from a configurable window that can be set to 0; mis-typed default in a wrapper function.","solutions":["Clamp size: $collection->sliding(max(1, $size), $step).","Validate $size >= 1 before calling.","Use the default sliding() when a window of 2 is acceptable."],"exampleFix":"// before\n$windows = $col->sliding($windowSize); // throws if 0\n// after\n$windows = $col->sliding(max(1, (int) $windowSize), $step);","handlingStrategy":"validation","validationCode":"$size = max(1, (int) $size);\n$result = $collection->sliding($size, $step);","typeGuard":"function isPositiveSize(int $size): bool { return $size >= 1; }","tryCatchPattern":"try {\n    $windows = $col->sliding($size, 1);\n} catch (\\InvalidArgumentException $e) {\n    $windows = $col->sliding();\n}","preventionTips":["Clamp dynamic window sizes with max(1, ...).","Validate user-supplied window sizes.","Use the default sliding() when a window of 2 suffices."],"tags":["collections","validation","laravel"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}