• 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

37.78
/src/Mapping/Exceptions/MappingException.php
1
<?php
2

3
namespace Ninja\Granite\Mapping\Exceptions;
4

5
use Exception;
6
use Ninja\Granite\Exceptions\GraniteException;
7

8
/**
9
 * Exception thrown when ObjectMapper operations fail.
10
 */
11
class MappingException extends GraniteException
12
{
13
    private string $sourceType;
14
    private string $destinationType;
15
    private ?string $propertyName;
16

17
    public function __construct(
2✔
18
        string $sourceType,
19
        string $destinationType,
20
        string $message = "",
21
        ?string $propertyName = null,
22
        int $code = 0,
23
        ?Exception $previous = null,
24
    ) {
25
        $this->sourceType = $sourceType;
2✔
26
        $this->destinationType = $destinationType;
2✔
27
        $this->propertyName = $propertyName;
2✔
28

29
        if (empty($message)) {
2✔
30
            $message = sprintf(
×
31
                'Mapping failed from %s to %s%s',
×
32
                $sourceType,
×
33
                $destinationType,
×
NEW
34
                $propertyName ? " (property: {$propertyName})" : '',
×
35
            );
×
36
        }
37

38
        $context = [
2✔
39
            'source_type' => $sourceType,
2✔
40
            'destination_type' => $destinationType,
2✔
41
            'property_name' => $propertyName,
2✔
42
        ];
2✔
43

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

47
    /**
48
     * Create exception for missing destination type.
49
     */
50
    public static function destinationTypeNotFound(string $destinationType): self
1✔
51
    {
52
        return new self(
1✔
53
            'unknown',
1✔
54
            $destinationType,
1✔
55
            sprintf('Destination type "%s" does not exist', $destinationType),
1✔
56
        );
1✔
57
    }
58

59
    /**
60
     * Create exception for transformation errors.
61
     */
62
    public static function transformationFailed(
×
63
        string $sourceType,
64
        string $destinationType,
65
        string $propertyName,
66
        string $reason,
67
        ?Exception $previous = null,
68
    ): self {
NEW
69
        return new self(
×
70
            $sourceType,
×
71
            $destinationType,
×
72
            sprintf('Failed to transform property "%s": %s', $propertyName, $reason),
×
73
            $propertyName,
×
74
            0,
×
NEW
75
            $previous,
×
76
        );
×
77
    }
78

79
    /**
80
     * Create exception for unsupported source type.
81
     */
NEW
82
    public static function unsupportedSourceType(mixed $source): self
×
83
    {
84
        $sourceType = is_object($source) ? get_class($source) : gettype($source);
×
85

NEW
86
        return new self(
×
87
            $sourceType,
×
88
            'unknown',
×
NEW
89
            sprintf('Unsupported source type: %s', $sourceType),
×
90
        );
×
91
    }
92

NEW
93
    public function getSourceType(): string
×
94
    {
NEW
95
        return $this->sourceType;
×
96
    }
97

NEW
98
    public function getDestinationType(): string
×
99
    {
NEW
100
        return $this->destinationType;
×
101
    }
102

NEW
103
    public function getPropertyName(): ?string
×
104
    {
NEW
105
        return $this->propertyName;
×
106
    }
107
}
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