Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
TextSearchResults
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
5 / 5
5
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 count
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 all
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 first
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getIterator
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Pdf\Toolkit;
6
7/**
8 * Collection of text search matches across a PDF document.
9 *
10 * @implements \IteratorAggregate<int, TextMatch>
11 */
12final class TextSearchResults implements \IteratorAggregate, \Countable
13{
14    /** @param list<TextMatch> $matches */
15    public function __construct(
16        private readonly array $matches,
17    ) {}
18
19    public function count(): int
20    {
21        return count($this->matches);
22    }
23
24    /** @return list<TextMatch> */
25    public function all(): array
26    {
27        return $this->matches;
28    }
29
30    public function first(): ?TextMatch
31    {
32        return $this->matches[0] ?? null;
33    }
34
35    /** @return \ArrayIterator<int, TextMatch> */
36    public function getIterator(): \ArrayIterator
37    {
38        return new \ArrayIterator($this->matches);
39    }
40}