{"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/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Collections/Collection.php#L1301-L1337","documentation":"Thrown by Collection::sliding($size, $step) when $size < 1. sliding() emits overlapping windows of length $size advancing by $step; a zero/negative window size is meaningless and is rejected before computing the window count.","triggerScenarios":"Calling $collection->sliding(0), sliding(-1), or passing a computed size that resolves to 0/negative.","commonSituations":"Size derived from a smaller collection (e.g. sliding(count() - 1) on a 1-element collection yields 0); user-supplied window size; off-by-one in paging/window math.","solutions":["Clamp the size: $collection->sliding(max(1, $size), $step).","Validate before calling: if ($size >= 1 && $step >= 1) { ... }.","Guard for short collections: skip sliding() when count() < $size.","Re-check the math that produced the size."],"exampleFix":"// before\n$windows = $collection->sliding($size, $step);\n\n// after\nif ($collection->count() >= $size) {\n    $windows = $collection->sliding(max(1, (int) $size), max(1, (int) $step));\n} else {\n    $windows = collect();\n}","handlingStrategy":"validation","validationCode":"if ($collection->count() >= 1 && $size >= 1 && $step >= 1) {\n    $windows = $collection->sliding($size, $step);\n} else {\n    $windows = collect();\n}","typeGuard":"function isValidSlidingSize(int $size): bool {\n    return $size >= 1;\n}","tryCatchPattern":"try {\n    $windows = $collection->sliding($size, $step);\n} catch (\\InvalidArgumentException $e) {\n    $windows = collect();\n}","preventionTips":["Clamp size with max(1, $size).","Skip sliding() when the collection is smaller than the window.","Validate window size derived from count()-based math."],"tags":["collections","validation","laravel"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}