Skip to content

feat: add Document::page(int $n) to look up a page by number#12

Merged
pushpak1300 merged 2 commits into
shipfastlabs:mainfrom
impruthvi:feat/document-page-helper
Jun 7, 2026
Merged

feat: add Document::page(int $n) to look up a page by number#12
pushpak1300 merged 2 commits into
shipfastlabs:mainfrom
impruthvi:feat/document-page-helper

Conversation

@impruthvi

@impruthvi impruthvi commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds Document::page(int $number): Page — looks up a page by its 1-based page number
  • Adds Document::hasPage(int $number): bool — non-throwing existence check, so callers can probe without a try/catch
  • Throws PageNotFoundException (new, extends ParselException) when the number doesn't exist in the document
  • Gives callers a typed, descriptive exception instead of an Undefined array key error from direct array access
  • Both lookups share a private find() helper; page() is annotated with @throws

Usage

$document = Parsel::file('report.pdf')->parse();

if ($document->hasPage(3)) {
    $page = $document->page(3); // returns Page, guaranteed present
}

$document->page(99); // throws PageNotFoundException

Test plan

  • Returns correct Page instance for a valid page number
  • hasPage() returns true for an existing page and false for a missing one
  • Throws PageNotFoundException with message "Page 99 was not found in the document." for missing page
  • Lint (pint + rector), PHPStan, and unit suite pass

impruthvi and others added 2 commits June 2, 2026 12:54
Throws PageNotFoundException when the requested page number is absent,
giving callers a typed exception instead of an array index error.
Extract the page scan into a private find() helper, add a non-throwing
hasPage() companion to page(), and annotate page() with @throws.
@pushpak1300 pushpak1300 force-pushed the feat/document-page-helper branch from b8815ec to 5b69793 Compare June 7, 2026 09:40
@pushpak1300 pushpak1300 merged commit 047fbd2 into shipfastlabs:main Jun 7, 2026
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.

2 participants