Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
TabOrderConstraint
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
1 / 1
5
100.00% covered (success)
100.00%
1 / 1
 check
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
1 / 1
5
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Pdf\Conformance\Constraint;
6
7use Phpdftk\Pdf\Conformance\Inspection\DocumentInspector;
8use Phpdftk\Pdf\Conformance\Profile\ConformanceProfile;
9use Phpdftk\Pdf\Conformance\Result\ConformanceViolation;
10use Phpdftk\Pdf\Conformance\Result\ViolationSeverity;
11
12/**
13 * PDF/UA-1 clause 7.5: Every page that contains annotations must
14 * have /Tabs set to /S (structure order).
15 *
16 * This ensures that keyboard tab order follows the logical structure
17 * tree rather than visual layout, which is critical for screen readers.
18 */
19final class TabOrderConstraint implements ConformanceConstraint
20{
21    public function check(DocumentInspector $inspector, ConformanceProfile $profile): array
22    {
23        $violations = [];
24        $pageIndex = 0;
25
26        foreach ($inspector->getPages() as $page) {
27            // Only require /Tabs on pages that have annotations
28            $hasAnnotations = !empty($page->annots);
29
30            if ($hasAnnotations && ($page->tabs === null || $page->tabs->value !== 'S')) {
31                $violations[] = new ConformanceViolation(
32                    clause: '7.5',
33                    message: sprintf(
34                        'Page %d has annotations but /Tabs is not set to /S (structure order)',
35                        $pageIndex,
36                    ),
37                    severity: ViolationSeverity::Error,
38                    objectPath: "Page[{$pageIndex}].Tabs",
39                );
40            }
41            $pageIndex++;
42        }
43
44        return $violations;
45    }
46}