Skip to content

#205 - Fix FileSplitterTask - #216

Merged
njoubert-cleverage merged 2 commits into
mainfrom
205
Sep 28, 2026
Merged

njoubert-cleverage merged 2 commits into
mainfrom
205

Conversation

@njoubert-cleverage

Copy link
Copy Markdown
Member

Description

Fixes #205.

FileSplitterTask does not split the source file correctly:

  • the first line of the source file is lost,
  • every line break is doubled (each line is followed by an extra empty line),
  • an extra empty file is emitted at the end of the iteration.

The produced files contain neither max_lines lines of the input nor the original content.

This PR:

  • Open the source without SplFileObject flags and without counting and rewinding, and read one line ahead to know whether another chunk remains.
  • Write exactly max_lines lines per file (the last one fewer), stripping only the trailing \r\n/\n of each line before writeLine(): no line is lost, content is preserved, line breaks are not doubled.
  • next() stops as soon as no line is left, so no empty file is emitted; an empty source file is skipped and produces no output.
  • Update the reference documentation, add unit tests.

The new regression tests fail on main and pass with this fix. PHPUnit, PHPStan, PHP-CS-Fixer and Rector pass.

Requirements

  • Documentation updates
    • Reference
    • Cookbooks
    • Changelog
  • Unit tests

Breaking changes

None: this fixes the content of the produced files (the task was introduced in v5.0, #174). Line breaks in produced files are written as PHP_EOL, and an empty source file now produces no output instead of an empty file.

🤖 Generated with Claude Code

njoubert-cleverage and others added 2 commits September 28, 2026 12:04
…ne, doubled line breaks and ended with an empty file; each file now contains exactly `max_lines` lines of the source. Update documentation, add tests.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@njoubert-cleverage
njoubert-cleverage merged commit f0d7add into main Sep 28, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FileSplitterTask produces wrong files: first line lost, line breaks doubled, trailing empty file

1 participant