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

diego-ninja / granite / 16609029965

29 Jul 2025 10:42PM UTC coverage: 50.423%. First build
16609029965

Pull #5

github

web-flow
Merge 722918909 into 6a6caca51
Pull Request #5: code: adds phpstan level max, pint with per and github actions

321 of 632 new or added lines in 77 files covered. (50.79%)

1132 of 2245 relevant lines covered (50.42%)

9.88 hits per line

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

0.0
/src/Exceptions/SerializationException.php
1
<?php
2

3
namespace Ninja\Granite\Exceptions;
4

5
use Exception;
6

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

16
    public function __construct(
×
17
        string $objectType,
18
        string $operation,
19
        string $message = "",
20
        ?string $propertyName = null,
21
        int $code = 0,
22
        ?Exception $previous = null,
23
    ) {
24
        $this->objectType = $objectType;
×
25
        $this->operation = $operation;
×
26
        $this->propertyName = $propertyName;
×
27

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

37
        $context = [
×
38
            'object_type' => $objectType,
×
39
            'operation' => $operation,
×
NEW
40
            'property_name' => $propertyName,
×
41
        ];
×
42

43
        parent::__construct($message, $code, $previous, $context);
×
44
    }
45

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

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

NEW
74
    public function getObjectType(): string
×
75
    {
NEW
76
        return $this->objectType;
×
77
    }
78

NEW
79
    public function getOperation(): string
×
80
    {
NEW
81
        return $this->operation;
×
82
    }
83

NEW
84
    public function getPropertyName(): ?string
×
85
    {
NEW
86
        return $this->propertyName;
×
87
    }
88
}
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