Skip to content

Commit 4c00003

Browse files
committed
refactor phpstan-types
1 parent 2058afe commit 4c00003

4 files changed

Lines changed: 100 additions & 236 deletions

File tree

src/Parser.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
* @SuppressWarnings("PHPMD.ExcessiveClassComplexity")
3636
*
3737
* @phpstan-import-type RawObjectArray from \Com\Tecnick\Pdf\Parser\Process\RawObject
38+
* @phpstan-import-type XrefData from \Com\Tecnick\Pdf\Parser\Process\XrefStream
3839
*/
3940
class Parser extends \Com\Tecnick\Pdf\Parser\Process\Xref
4041
{
@@ -71,16 +72,7 @@ public function __construct(array $cfg = [])
7172
* @param string $data PDF data to parse.
7273
*
7374
* @return array{
74-
* 0: array{
75-
* 'trailer': array{
76-
* 'encrypt'?: string,
77-
* 'id': array<int, string>,
78-
* 'info': string,
79-
* 'root': string,
80-
* 'size': int,
81-
* },
82-
* 'xref': array<string, int>,
83-
* },
75+
* 0: XrefData,
8476
* 1: array<string, array<int, RawObjectArray>>,
8577
* }
8678
*/

src/Process/RawObject.php

Lines changed: 32 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@
6060
* 2: int,
6161
* 3?: array{string, array<string>},
6262
* }
63+
*
64+
* @phpstan-type RawObjectValue string|array<int, array{
65+
* 0: string,
66+
* 1: string|array<int, array{
67+
* 0: string,
68+
* 1: string,
69+
* 2: int,
70+
* }>,
71+
* 2: int,
72+
* }>
6373
*/
6474
abstract class RawObject
6575
{
@@ -142,18 +152,10 @@ protected function getRawObject(int $offset = 0): array
142152
* Process name object
143153
* \x2F SOLIDUS
144154
*
145-
* @param string $char Symbol to process
146-
* @param int $offset Offset
147-
* @param string $objtype Object type
148-
* @param string|array<int, array{
149-
* 0: string,
150-
* 1: string|array<int, array{
151-
* 0: string,
152-
* 1: string,
153-
* 2: int,
154-
* }>,
155-
* 2: int,
156-
* }> $objval Object content
155+
* @param string $char Symbol to process
156+
* @param int $offset Offset
157+
* @param string $objtype Object type
158+
* @param RawObjectValue $objval Object content
157159
*/
158160
protected function processSolidus(string $char, int &$offset, string &$objtype, string|array &$objval): void
159161
{
@@ -175,18 +177,10 @@ protected function processSolidus(string $char, int &$offset, string &$objtype,
175177
* Process literal string object
176178
* \x28 LEFT PARENTHESIS and \x29 RIGHT PARENTHESIS
177179
*
178-
* @param string $char Symbol to process
179-
* @param int $offset Offset
180-
* @param string $objtype Object type
181-
* @param string|array<int, array{
182-
* 0: string,
183-
* 1: string|array<int, array{
184-
* 0: string,
185-
* 1: string,
186-
* 2: int,
187-
* }>,
188-
* 2: int,
189-
* }> $objval Object content
180+
* @param string $char Symbol to process
181+
* @param int $offset Offset
182+
* @param string $objtype Object type
183+
* @param RawObjectValue $objval Object content
190184
*/
191185
protected function processParenthesis(string $char, int &$offset, string &$objtype, string|array &$objval): void
192186
{
@@ -229,18 +223,10 @@ protected function processParenthesis(string $char, int &$offset, string &$objty
229223
* Process array content
230224
* \x5B LEFT SQUARE BRACKET and \x5D RIGHT SQUARE BRACKET
231225
*
232-
* @param string $char Symbol to process
233-
* @param int $offset Offset
234-
* @param string $objtype Object type
235-
* @param string|array<int, array{
236-
* 0: string,
237-
* 1: string|array<int, array{
238-
* 0: string,
239-
* 1: string,
240-
* 2: int,
241-
* }>,
242-
* 2: int,
243-
* }> $objval Object content
226+
* @param string $char Symbol to process
227+
* @param int $offset Offset
228+
* @param string $objtype Object type
229+
* @param RawObjectValue $objval Object content
244230
*/
245231
protected function processBracket(string $char, int &$offset, string &$objtype, string|array &$objval): void
246232
{
@@ -266,18 +252,10 @@ protected function processBracket(string $char, int &$offset, string &$objtype,
266252
/**
267253
* Process \x3C LESS-THAN SIGN and \x3E GREATER-THAN SIGN
268254
*
269-
* @param string $char Symbol to process
270-
* @param int $offset Offset
271-
* @param string $objtype Object type
272-
* @param string|array<int, array{
273-
* 0: string,
274-
* 1: string|array<int, array{
275-
* 0: string,
276-
* 1: string,
277-
* 2: int,
278-
* }>,
279-
* 2: int,
280-
* }> $objval Object content
255+
* @param string $char Symbol to process
256+
* @param int $offset Offset
257+
* @param string $objtype Object type
258+
* @param RawObjectValue $objval Object content
281259
*/
282260
protected function processAngular(string $char, int &$offset, string &$objtype, string|array &$objval): void
283261
{
@@ -323,17 +301,9 @@ protected function processAngular(string $char, int &$offset, string &$objtype,
323301
/**
324302
* Process default
325303
*
326-
* @param int $offset Offset
327-
* @param string $objtype Object type
328-
* @param string|array<int, array{
329-
* 0: string,
330-
* 1: string|array<int, array{
331-
* 0: string,
332-
* 1: string,
333-
* 2: int,
334-
* }>,
335-
* 2: int,
336-
* }> $objval Object content
304+
* @param int $offset Offset
305+
* @param string $objtype Object type
306+
* @param RawObjectValue $objval Object content
337307
*
338308
* @return bool True in case of match, flase otherwise
339309
*/
@@ -396,17 +366,9 @@ protected function processDefaultName(int &$offset, string &$objtype, string|arr
396366
/**
397367
* Process default
398368
*
399-
* @param int $offset Offset
400-
* @param string $objtype Object type
401-
* @param string|array<int, array{
402-
* 0: string,
403-
* 1: string|array<int, array{
404-
* 0: string,
405-
* 1: string,
406-
* 2: int,
407-
* }>,
408-
* 2: int,
409-
* }> $objval Object content
369+
* @param int $offset Offset
370+
* @param string $objtype Object type
371+
* @param RawObjectValue $objval Object content
410372
*/
411373
protected function processDefault(int &$offset, string &$objtype, string|array &$objval): void
412374
{

src/Process/Xref.php

Lines changed: 38 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,38 @@
3030
* @copyright 2011-2026 Nicola Asuni - Tecnick.com LTD
3131
* @license https://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
3232
* @link https://github.com/tecnickcom/tc-lib-pdf-parser
33+
*
34+
* @phpstan-import-type RawObjectArray from \Com\Tecnick\Pdf\Parser\Process\RawObject
35+
* @phpstan-import-type XrefData from \Com\Tecnick\Pdf\Parser\Process\XrefStream
36+
*
37+
* @phpstan-type XrefDataPartial array{
38+
* 'trailer'?: array{
39+
* 'encrypt'?: string,
40+
* 'id': array<int, string>,
41+
* 'info': string,
42+
* 'root': string,
43+
* 'size': int,
44+
* },
45+
* 'xref': array<string, int>,
46+
* }
47+
*
48+
* @phpstan-type XrefDataInput array{
49+
* 'trailer'?: array{
50+
* 'encrypt'?: string,
51+
* 'id': array<int, string>,
52+
* 'info': string,
53+
* 'root': string,
54+
* 'size': int,
55+
* },
56+
* 'xref'?: array<string, int>,
57+
* }
3358
*/
3459
abstract class Xref extends \Com\Tecnick\Pdf\Parser\Process\XrefStream
3560
{
3661
/**
3762
* Default empty XREF data.
3863
*
39-
* @var array{
40-
* 'trailer': array{
41-
* 'encrypt'?: string,
42-
* 'id': array<int, string>,
43-
* 'info': string,
44-
* 'root': string,
45-
* 'size': int,
46-
* },
47-
* 'xref': array<string, int>,
48-
* }
64+
* @var XrefData
4965
*/
5066
protected const XREF_EMPTY = [
5167
'trailer' => [
@@ -61,16 +77,7 @@ abstract class Xref extends \Com\Tecnick\Pdf\Parser\Process\XrefStream
6177
/**
6278
* XREF data.
6379
*
64-
* @var array{
65-
* 'trailer': array{
66-
* 'encrypt'?: string,
67-
* 'id': array<int, string>,
68-
* 'info': string,
69-
* 'root': string,
70-
* 'size': int,
71-
* },
72-
* 'xref': array<string, int>,
73-
* }
80+
* @var XrefData
7481
*/
7582
protected array $xref = self::XREF_EMPTY;
7683

@@ -100,28 +107,10 @@ abstract protected function getIndirectObject(string $obj_ref, int $offset = 0,
100107
/**
101108
* Get Cross-Reference (xref) table and trailer data from PDF document data.
102109
*
103-
* @param int $offset Xref offset (if know).
104-
* @param array{
105-
* 'trailer'?: array{
106-
* 'encrypt'?: string,
107-
* 'id': array<int, string>,
108-
* 'info': string,
109-
* 'root': string,
110-
* 'size': int,
111-
* },
112-
* 'xref'?: array<string, int>,
113-
* } $xref Previous xref array (if any).
110+
* @param int $offset Xref offset (if know).
111+
* @param XrefDataInput $xref Previous xref array (if any).
114112
*
115-
* @return array{
116-
* 'trailer': array{
117-
* 'encrypt'?: string,
118-
* 'id': array<int, string>,
119-
* 'info': string,
120-
* 'root': string,
121-
* 'size': int,
122-
* },
123-
* 'xref': array<string, int>,
124-
* } Xref and trailer data.
113+
* @return XrefData Xref and trailer data.
125114
*
126115
* @SuppressWarnings("PHPMD.CyclomaticComplexity")
127116
*/
@@ -196,28 +185,10 @@ protected function getXrefData(int $offset = 0, array $xref = []): array
196185
/**
197186
* Decode the Cross-Reference section
198187
*
199-
* @param int $startxref Offset at which the xref section starts (position of the 'xref' keyword).
200-
* @param array{
201-
* 'trailer'?: array{
202-
* 'encrypt'?: string,
203-
* 'id': array<int, string>,
204-
* 'info': string,
205-
* 'root': string,
206-
* 'size': int,
207-
* },
208-
* 'xref': array<string, int>,
209-
* } $xref Previous xref array (if any).
188+
* @param int $startxref Offset at which the xref section starts (position of the 'xref' keyword).
189+
* @param XrefDataPartial $xref Previous xref array (if any).
210190
*
211-
* @return array{
212-
* 'trailer': array{
213-
* 'encrypt'?: string,
214-
* 'id': array<int, string>,
215-
* 'info': string,
216-
* 'root': string,
217-
* 'size': int,
218-
* },
219-
* 'xref': array<string, int>,
220-
* } Xref and trailer data.
191+
* @return XrefData Xref and trailer data.
221192
*/
222193
protected function decodeXref(int $startxref, array $xref): array
223194
{
@@ -278,28 +249,10 @@ protected function decodeXref(int $startxref, array $xref): array
278249
/**
279250
* Decode the Cross-Reference section
280251
*
281-
* @param array{
282-
* 'trailer'?: array{
283-
* 'encrypt'?: string,
284-
* 'id': array<int, string>,
285-
* 'info': string,
286-
* 'root': string,
287-
* 'size': int,
288-
* },
289-
* 'xref': array<string, int>,
290-
* } $xref Previous xref array (if any).
252+
* @param XrefDataPartial $xref Previous xref array (if any).
291253
* @param array<array<int, int<-1, max>|string>> $matches Matches containing trailer sections
292254
*
293-
* @return array{
294-
* 'trailer': array{
295-
* 'encrypt'?: string,
296-
* 'id': array<int, string>,
297-
* 'info': string,
298-
* 'root': string,
299-
* 'size': int,
300-
* },
301-
* 'xref': array<string, int>,
302-
* } Xref and trailer data.
255+
* @return XrefData Xref and trailer data.
303256
*/
304257
protected function getTrailerData(array $xref, array $matches): array
305258
{
@@ -348,28 +301,10 @@ protected function getTrailerData(array $xref, array $matches): array
348301
/**
349302
* Decode the Cross-Reference Stream section
350303
*
351-
* @param int $startxref Offset at which the xref section starts.
352-
* @param array{
353-
* 'trailer'?: array{
354-
* 'encrypt'?: string,
355-
* 'id': array<int, string>,
356-
* 'info': string,
357-
* 'root': string,
358-
* 'size': int,
359-
* },
360-
* 'xref': array<string, int>,
361-
* } $xref Previous xref array (if any).
304+
* @param int $startxref Offset at which the xref section starts.
305+
* @param XrefDataPartial $xref Previous xref array (if any).
362306
*
363-
* @return array{
364-
* 'trailer': array{
365-
* 'encrypt'?: string,
366-
* 'id': array<int, string>,
367-
* 'info': string,
368-
* 'root': string,
369-
* 'size': int,
370-
* },
371-
* 'xref': array<string, int>,
372-
* } Xref and trailer data.
307+
* @return XrefData Xref and trailer data.
373308
*
374309
* @SuppressWarnings("PHPMD.CyclomaticComplexity")
375310
*/

0 commit comments

Comments
 (0)