• 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/MediaString.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace PHPModelGenerator\Filter;
6

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

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

NEW
38
        if ($value instanceof MediaStringValue) {
×
NEW
39
            return $value;
×
40
        }
41

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

NEW
44
        return new MediaStringValue($rawValue, $options['mediaType'] ?? null, $options['encoding'] ?? null);
×
45
    }
46

47
    /**
48
     * Serialize a MediaString back to its raw string value.
49
     */
NEW
50
    public static function serialize(MediaStringValue|null $value): ?string
×
51
    {
NEW
52
        return $value !== null ? (string) $value : null;
×
53
    }
54
}
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