Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
8 / 8 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
| XmpPacket | |
100.00% |
8 / 8 |
|
100.00% |
6 / 6 |
6 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| create | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| get | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| set | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| has | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| all | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Xmp; |
| 6 | |
| 7 | /** |
| 8 | * Immutable bag of XMP metadata properties. |
| 9 | * |
| 10 | * Properties are stored as namespace-prefixed keys (e.g., "dc:title"). |
| 11 | * `set()` returns a new instance — the original is never mutated. |
| 12 | */ |
| 13 | final class XmpPacket |
| 14 | { |
| 15 | /** @param array<string, string> $properties */ |
| 16 | private function __construct( |
| 17 | private readonly array $properties, |
| 18 | ) {} |
| 19 | |
| 20 | public static function create(): self |
| 21 | { |
| 22 | return new self([]); |
| 23 | } |
| 24 | |
| 25 | public function get(string $key): ?string |
| 26 | { |
| 27 | return $this->properties[$key] ?? null; |
| 28 | } |
| 29 | |
| 30 | public function set(string $key, string $value): self |
| 31 | { |
| 32 | $props = $this->properties; |
| 33 | $props[$key] = $value; |
| 34 | return new self($props); |
| 35 | } |
| 36 | |
| 37 | public function has(string $key): bool |
| 38 | { |
| 39 | return isset($this->properties[$key]); |
| 40 | } |
| 41 | |
| 42 | /** @return array<string, string> */ |
| 43 | public function all(): array |
| 44 | { |
| 45 | return $this->properties; |
| 46 | } |
| 47 | } |