Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
7 / 7
83.33% covered (warning)
83.33%
5 / 6
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
InvalidHydrationTarget
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
7 / 7
83.33% covered (warning)
83.33%
5 / 6
100.00% covered (success)
100.00%
3 / 3
5.12
100.00% covered (success)
100.00%
1 / 1
 forTarget
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
5 / 5
75.00% covered (warning)
75.00%
3 / 4
100.00% covered (success)
100.00%
1 / 1
3.14
 forParameter
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 forClosureResult
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Celema\Quma\Exception;
6
7use Throwable;
8
9/** @api */
10final class InvalidHydrationTarget extends HydrationFailure
11{
12    /** @param list<string> $rowKeys */
13    public static function forTarget(
14        string $target,
15        ?string $sourcePath = null,
16        array $rowKeys = [],
17        string $reason = '',
18        ?Throwable $previous = null,
19    ): self {
20        $message = "Invalid hydration target '{$target}' from " . self::source($sourcePath);
21
22        if ($reason !== '') {
23            $message .= ": {$reason}";
24        }
25
26        if ($rowKeys !== []) {
27            $message .= '. Row keys: ' . self::formatRowKeys($rowKeys);
28        }
29
30        return new self($message . '.', 0, $previous)->withReason($reason);
31    }
32
33    /**
34     * @param class-string $class
35     * @param non-empty-string $parameter
36     */
37    public static function forParameter(
38        string $class,
39        string $parameter,
40        string $reason,
41    ): self {
42        $reason = "parameter '\${$parameter}' {$reason}";
43
44        return new self("Invalid hydration target '{$class}': {$reason}.")->withReason($reason);
45    }
46
47    /** @param list<string> $rowKeys */
48    public static function forClosureResult(
49        mixed $result,
50        ?string $sourcePath,
51        array $rowKeys,
52    ): self {
53        return new self(
54            'Invalid hydration target returned by resolver from '
55                . self::source($sourcePath)
56                . ': expected class-string, got '
57                . self::valueType($result)
58                . '. Row keys: '
59                . self::formatRowKeys($rowKeys)
60                . '.',
61        );
62    }
63}