Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| EmbeddedFileConstraint | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
7 | |
100.00% |
1 / 1 |
| check | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
7 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Pdf\Conformance\Constraint; |
| 6 | |
| 7 | use Phpdftk\Pdf\Conformance\Inspection\DocumentInspector; |
| 8 | use Phpdftk\Pdf\Conformance\Profile\ConformanceProfile; |
| 9 | use Phpdftk\Pdf\Conformance\Profile\PdfAProfile; |
| 10 | use Phpdftk\Pdf\Conformance\Profile\ZugferdProfile; |
| 11 | use Phpdftk\Pdf\Conformance\Result\ConformanceViolation; |
| 12 | use Phpdftk\Pdf\Conformance\Result\ViolationSeverity; |
| 13 | |
| 14 | /** |
| 15 | * PDF/A-1 clause 6.9 / PDF/A-2 clause 6.10: Embedded files are prohibited. |
| 16 | * PDF/A-3 (ISO 19005-3): Embedded files are allowed (associated via /AF). |
| 17 | * |
| 18 | * This constraint checks for the presence of embedded files via the |
| 19 | * Catalog /Names dictionary. PDF/A-3+ allows them, so the constraint |
| 20 | * is skipped for those profiles. ZUGFeRD/Factur-X profiles are based on |
| 21 | * PDF/A-3 and require embedded files. |
| 22 | */ |
| 23 | final class EmbeddedFileConstraint implements ConformanceConstraint |
| 24 | { |
| 25 | public function check(DocumentInspector $inspector, ConformanceProfile $profile): array |
| 26 | { |
| 27 | // PDF/A-3+ allows embedded files |
| 28 | if ($profile instanceof PdfAProfile && $profile->allowsEmbeddedFiles()) { |
| 29 | return []; |
| 30 | } |
| 31 | |
| 32 | // ZUGFeRD/Factur-X is based on PDF/A-3 which allows embedded files |
| 33 | if ($profile instanceof ZugferdProfile) { |
| 34 | return []; |
| 35 | } |
| 36 | |
| 37 | if ($inspector->hasEmbeddedFiles()) { |
| 38 | $clause = $profile instanceof PdfAProfile && $profile->getPart() === 1 |
| 39 | ? '6.9' |
| 40 | : '6.10'; |
| 41 | |
| 42 | return [new ConformanceViolation( |
| 43 | clause: $clause, |
| 44 | message: 'Embedded files are prohibited in ' . $profile->getFamily() . '-' . $profile->getLevel(), |
| 45 | severity: ViolationSeverity::Error, |
| 46 | )]; |
| 47 | } |
| 48 | |
| 49 | return []; |
| 50 | } |
| 51 | } |