Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
21 / 21
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
TrappedConstraint
100.00% covered (success)
100.00%
21 / 21
100.00% covered (success)
100.00%
1 / 1
5
100.00% covered (success)
100.00%
1 / 1
 check
100.00% covered (success)
100.00%
21 / 21
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/X: The Info dictionary /Trapped key must be /True or /False.
14 *
15 * /Unknown is not acceptable for PDF/X conformance — the trapping
16 * status must be explicitly declared for prepress workflows.
17 */
18final class TrappedConstraint implements ConformanceConstraint
19{
20    public function check(DocumentInspector $inspector, ConformanceProfile $profile): array
21    {
22        $info = $inspector->getInfo();
23
24        if ($info === null || $info->trapped === null) {
25            return [new ConformanceViolation(
26                clause: '6.3',
27                message: 'Info /Trapped must be set to /True or /False for ' . $profile->getFamily() . ' conformance',
28                severity: ViolationSeverity::Error,
29                objectPath: 'Info.Trapped',
30            )];
31        }
32
33        $value = $info->trapped->value;
34        if ($value !== 'True' && $value !== 'False') {
35            return [new ConformanceViolation(
36                clause: '6.3',
37                message: sprintf(
38                    'Info /Trapped is /%s — must be /True or /False for %s conformance',
39                    $value,
40                    $profile->getFamily(),
41                ),
42                severity: ViolationSeverity::Error,
43                objectPath: 'Info.Trapped',
44            )];
45        }
46
47        return [];
48    }
49}