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

diego-ninja / granite / 34018013180

06 Sep 2026 07:01AM UTC coverage: 84.549% (+1.2%) from 83.371%
34018013180

Pull #22

github

web-flow
Merge ca5019787 into f40f1b915
Pull Request #22: fix: harden object pipelines and improve performance

822 of 986 new or added lines in 49 files covered. (83.37%)

14 existing lines in 13 files now uncovered.

3513 of 4155 relevant lines covered (84.55%)

16.56 hits per line

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

49.09
/src/Exceptions/SerializationException.php
1
<?php
2
// ABOUTME: Defines SerializationException as part of the library exception taxonomy.
3
// ABOUTME: Owns the SerializationException boundary within the library exception taxonomy.
4

5
namespace Ninja\Granite\Exceptions;
6

7
use Throwable;
8

9
/**
10
 * Exception thrown when serialization/deserialization fails.
11
 */
12
class SerializationException extends GraniteException
13
{
14
    private string $objectType;
15
    private string $operation;
16
    private ?string $propertyName;
17

18
    public function __construct(
6 ✔
19
        string $objectType,
20
        string $operation,
21
        string $message = "",
22
        ?string $propertyName = null,
23
        int $code = 0,
24
        ?Throwable $previous = null,
25
    ) {
26
        $this->objectType = $objectType;
6 ✔
27
        $this->operation = $operation;
6 ✔
28
        $this->propertyName = $propertyName;
6 ✔
29

30
        if (empty($message)) {
6 ✔
31
            $message = sprintf(
×
32
                'Serialization failed during %s for %s%s',
×
33
                $operation,
×
34
                $objectType,
×
35
                $propertyName ? " (property: {$propertyName})" : '',
×
36
            );
×
37
        }
38

39
        $context = [
6 ✔
40
            'object_type' => $objectType,
6 ✔
41
            'operation' => $operation,
6 ✔
42
            'property_name' => $propertyName,
6 ✔
43
        ];
6 ✔
44

45
        parent::__construct($message, $code, $previous, $context);
6 ✔
46
    }
47

48
    /**
49
     * Create exception for unsupported type during serialization.
50
     */
51
    public static function unsupportedType(string $objectType, string $propertyName, string $valueType): self
×
52
    {
53
        return new self(
×
54
            $objectType,
×
55
            'serialization',
×
56
            sprintf('Cannot serialize property "%s" of type "%s"', $propertyName, $valueType),
×
57
            $propertyName,
×
58
        );
×
59
    }
60

61
    /**
62
     * Create exception for deserialization errors.
63
     */
NEW
64
    public static function deserializationFailed(string $objectType, string $reason, ?Throwable $previous = null): self
×
65
    {
66
        return new self(
×
67
            $objectType,
×
68
            'deserialization',
×
69
            sprintf('Failed to deserialize %s: %s', $objectType, $reason),
×
70
            null,
×
71
            0,
×
72
            $previous,
×
73
        );
×
74
    }
75

76
    public static function missingRequiredValue(string $objectType, string $parameter): self
1 ✔
77
    {
78
        return new self(
1 ✔
79
            $objectType,
1 ✔
80
            'deserialization',
1 ✔
81
            sprintf('Missing required value for parameter "%s" in %s', $parameter, $objectType),
1 ✔
82
            $parameter,
1 ✔
83
        );
1 ✔
84
    }
85

86
    public static function conversionFailed(
5 ✔
87
        string $objectType,
88
        string $propertyName,
89
        string $targetType,
90
        ?Throwable $previous = null,
91
    ): self {
92
        return new self(
5 ✔
93
            $objectType,
5 ✔
94
            'deserialization',
5 ✔
95
            sprintf('Failed to convert property "%s" to "%s"', $propertyName, $targetType),
5 ✔
96
            $propertyName,
5 ✔
97
            0,
5 ✔
98
            $previous,
5 ✔
99
        );
5 ✔
100
    }
101

UNCOV
102
    public function getObjectType(): string
×
103
    {
104
        return $this->objectType;
×
105
    }
106

107
    public function getOperation(): string
×
108
    {
109
        return $this->operation;
×
110
    }
111

112
    public function getPropertyName(): ?string
×
113
    {
114
        return $this->propertyName;
×
115
    }
116
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc