• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wol-soft / php-json-schema-model-generator-production / 24726187836

21 Apr 2026 01:50PM UTC coverage: 25.265% (-1.8%) from 27.11%
24726187836

push

github

Enno Woortmann
Add MediaString and ImmutableMediaString value objects with filter callables

Introduces two value object classes (ValueObject/MediaString and
ValueObject/ImmutableMediaString) and their corresponding filter/serializer
callables (Filter/MediaString and Filter/ImmutableMediaString) to support
the contentMediaType and contentEncoding JSON Schema keywords.

Value objects carry the raw string value alongside schema-defined mediaType
and encoding metadata. The mutable variant exposes setValue(); the immutable
variant is fully readonly. Both implement Stringable.

Filter callables are separated from the value objects to keep concerns clean:
the value objects are pure data holders while the filter classes own the
transformation and serialization logic for the generator's filter pipeline.

0 of 45 new or added lines in 4 files covered. (0.0%)

167 of 661 relevant lines covered (25.26%)

0.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Filter/ImmutableMediaString.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace PHPModelGenerator\Filter;
6

7
use PHPModelGenerator\ValueObject\ImmutableMediaString as ImmutableMediaStringValue;
8
use PHPModelGenerator\ValueObject\MediaString;
9

10
/**
11
 * Filter and serializer callables for the ImmutableMediaString value object.
12
 *
13
 * Separated from the value object to keep concerns clean: ImmutableMediaString is a pure data
14
 * holder, while this class owns the transformation and serialization logic for the filter pipeline.
15
 */
16
class ImmutableMediaString
17
{
18
    /**
19
     * Wrap a raw string in an ImmutableMediaString carrying the schema-defined media type and
20
     * encoding.
21
     *
22
     * Pass-through rules:
23
     *   - null                 → null (nullable property)
24
     *   - ImmutableMediaString → returned unchanged (already transformed)
25
     *   - MediaString          → converted to ImmutableMediaString preserving the raw value
26
     *   - string               → wrapped with mediaType / encoding from $options
27
     *
28
     * @param string|MediaString|ImmutableMediaStringValue|null $value
29
     * @param array{mediaType?: string|null, encoding?: string|null} $options
30
     */
NEW
31
    public static function filter(
×
32
        string|MediaString|ImmutableMediaStringValue|null $value,
33
        array $options = [],
34
    ): ?ImmutableMediaStringValue {
NEW
35
        if ($value === null) {
×
NEW
36
            return null;
×
37
        }
38

NEW
39
        if ($value instanceof ImmutableMediaStringValue) {
×
NEW
40
            return $value;
×
41
        }
42

NEW
43
        $rawValue = $value instanceof MediaString ? $value->getValue() : $value;
×
44

NEW
45
        return new ImmutableMediaStringValue(
×
NEW
46
            $rawValue,
×
NEW
47
            $options['mediaType'] ?? null,
×
NEW
48
            $options['encoding'] ?? null,
×
NEW
49
        );
×
50
    }
51

52
    /**
53
     * Serialize an ImmutableMediaString back to its raw string value.
54
     */
NEW
55
    public static function serialize(ImmutableMediaStringValue|null $value): ?string
×
56
    {
NEW
57
        return $value !== null ? (string) $value : null;
×
58
    }
59
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc