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

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

08 May 2026 04:40AM UTC coverage: 24.082% (-1.2%) from 25.265%
25537160775

push

github

Enno Woortmann
Validate metadata on pre-existing MediaString pass-through; extract shared logic

When a MediaString or ImmutableMediaString instance is passed to a filter,
assert that its mediaType and encoding match the schema-declared values before
passing it through. Shared assertion logic extracted into AbstractMediaStringFilter.

0 of 31 new or added lines in 3 files covered. (0.0%)

1 existing line in 1 file now uncovered.

164 of 681 relevant lines covered (24.08%)

0.81 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 InvalidArgumentException;
8
use PHPModelGenerator\ValueObject\ImmutableMediaString;
9
use PHPModelGenerator\ValueObject\MediaString as MediaStringValue;
10

11
class MediaString extends AbstractMediaStringFilter
12
{
13
    /**
14
     * Wrap a raw string in a MediaString carrying the schema-defined media type and encoding.
15
     *
16
     * Pass-through rules:
17
     *   - null                 → null (nullable property)
18
     *   - MediaString          → returned unchanged after validating mediaType/encoding match
19
     *   - ImmutableMediaString → converted to MediaString after validating mediaType/encoding match
20
     *   - string               → wrapped with mediaType / encoding from $options
21
     *
22
     * @param string|MediaStringValue|ImmutableMediaString|null $value
23
     * @param array{mediaType?: string|null, encoding?: string|null} $options
24
     *
25
     * @throws InvalidArgumentException when a pre-existing wrapper's mediaType or encoding
26
     *                                  does not match the schema-declared values
27
     */
28
    public static function filter(
×
29
        string|MediaStringValue|ImmutableMediaString|null $value,
30
        array $options = [],
31
    ): ?MediaStringValue {
32
        if ($value === null) {
×
33
            return null;
×
34
        }
35

NEW
36
        if ($value instanceof MediaStringValue || $value instanceof ImmutableMediaString) {
×
NEW
37
            self::assertMetadataMatch($value->getMediaType(), $value->getEncoding(), $options);
×
38

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

NEW
43
            return new MediaStringValue($value->getValue(), $options['mediaType'] ?? null, $options['encoding'] ?? null);
×
44
        }
45

NEW
46
        return new MediaStringValue($value, $options['mediaType'] ?? null, $options['encoding'] ?? null);
×
47
    }
48

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