Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
ReferenceXObjectConstraint
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
5
100.00% covered (success)
100.00%
1 / 1
 check
100.00% covered (success)
100.00%
12 / 12
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\Profile\PdfXProfile;
10use Phpdftk\Pdf\Conformance\Result\ConformanceViolation;
11use Phpdftk\Pdf\Conformance\Result\ViolationSeverity;
12
13/**
14 * ISO 15930-8/9 (PDF/X-5): Reference XObject validation.
15 *
16 * PDF/X-5g, X-5pg, and X-5n profiles support external graphical content
17 * via reference XObjects. When present, the FormXObject's /Ref dictionary
18 * must be valid. This constraint is a no-op for non-X-5 profiles.
19 */
20final class ReferenceXObjectConstraint implements ConformanceConstraint
21{
22    public function check(DocumentInspector $inspector, ConformanceProfile $profile): array
23    {
24        // Only applies to X-5 profiles
25        if (!$profile instanceof PdfXProfile || !$profile->supportsReferenceXObjects()) {
26            return [];
27        }
28
29        $violations = [];
30
31        foreach ($inspector->getReferenceXObjects() as $formXObject) {
32            // /Ref is already non-null (that's how getReferenceXObjects filters),
33            // but the reference must point to a valid object
34            if ($formXObject->ref === null) {
35                $violations[] = new ConformanceViolation(
36                    clause: '6.8',
37                    message: 'Reference XObject is missing required /Ref dictionary',
38                    severity: ViolationSeverity::Error,
39                    objectPath: 'FormXObject',
40                );
41            }
42        }
43
44        return $violations;
45    }
46}