Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
17 / 17
93.33% covered (success)
93.33%
14 / 15
88.89% covered (warning)
88.89%
8 / 9
80.00% covered (warning)
80.00%
4 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
HydrationFailure
100.00% covered (success)
100.00%
17 / 17
93.33% covered (success)
93.33%
14 / 15
88.89% covered (warning)
88.89%
8 / 9
100.00% covered (success)
100.00%
5 / 5
8.09
100.00% covered (success)
100.00%
1 / 1
 fromHydratableFailure
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
 message
100.00% covered (success)
100.00%
1 / 1
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
 source
100.00% covered (success)
100.00%
1 / 1
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
 formatRowKeys
100.00% covered (success)
100.00%
1 / 1
85.71% covered (warning)
85.71%
6 / 7
66.67% covered (warning)
66.67%
2 / 3
100.00% covered (success)
100.00%
1 / 1
2.15
 valueType
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3declare(strict_types=1);
4
5namespace Celemas\Quma\Exception;
6
7use RuntimeException;
8use Throwable;
9
10/** @api */
11class HydrationFailure extends RuntimeException
12{
13    /**
14     * @param class-string $class
15     * @param list<string> $rowKeys
16     */
17    public static function fromHydratableFailure(
18        string $class,
19        ?string $sourcePath,
20        array $rowKeys,
21        Throwable $previous,
22    ): self {
23        return new self(
24            self::message(
25                $class,
26                $sourcePath,
27                'Hydratable::fromRow() failed. Row keys: ' . self::formatRowKeys($rowKeys) . '.',
28            ),
29            0,
30            $previous,
31        );
32    }
33
34    /** @param class-string $class */
35    protected static function message(string $class, ?string $sourcePath, string $detail): string
36    {
37        return "Could not hydrate {$class} from " . self::source($sourcePath) . "{$detail}";
38    }
39
40    protected static function source(?string $sourcePath): string
41    {
42        return $sourcePath ?? 'ad-hoc SQL';
43    }
44
45    /** @param list<string> $rowKeys */
46    protected static function formatRowKeys(array $rowKeys): string
47    {
48        return $rowKeys === [] ? '(none)' : implode(', ', $rowKeys);
49    }
50
51    protected static function valueType(mixed $value): string
52    {
53        if (is_object($value)) {
54            return $value::class;
55        }
56
57        if (is_resource($value)) {
58            return get_resource_type($value) . ' resource';
59        }
60
61        return get_debug_type($value);
62    }
63}

Branches

Below are the source code lines that represent each code branch as identified by Xdebug. Please note a branch is not necessarily coterminous with a line, a line may contain multiple branches and therefore show up more than once. Please also be aware that some branches may be implicit rather than explicit, e.g. an if statement always has an else as part of its logical flow even if you didn't write one.

HydrationFailure->formatRowKeys
46    protected static function formatRowKeys(array $rowKeys): string
47    {
48        return $rowKeys === [] ? '(none)' : implode(', ', $rowKeys);
48        return $rowKeys === [] ? '(none)' : implode(', ', $rowKeys);
48        return $rowKeys === [] ? '(none)' : implode(', ', $rowKeys);
48        return $rowKeys === [] ? '(none)' : implode(', ', $rowKeys);
48        return $rowKeys === [] ? '(none)' : implode(', ', $rowKeys);
48        return $rowKeys === [] ? '(none)' : implode(', ', $rowKeys);
48        return $rowKeys === [] ? '(none)' : implode(', ', $rowKeys);
49    }
HydrationFailure->fromHydratableFailure
18        string $class,
19        ?string $sourcePath,
20        array $rowKeys,
21        Throwable $previous,
22    ): self {
23        return new self(
24            self::message(
25                $class,
26                $sourcePath,
27                'Hydratable::fromRow() failed. Row keys: ' . self::formatRowKeys($rowKeys) . '.',
28            ),
29            0,
30            $previous,
31        );
32    }
HydrationFailure->message
35    protected static function message(string $class, ?string $sourcePath, string $detail): string
36    {
37        return "Could not hydrate {$class} from " . self::source($sourcePath) . "{$detail}";
38    }
HydrationFailure->source
40    protected static function source(?string $sourcePath): string
41    {
42        return $sourcePath ?? 'ad-hoc SQL';
43    }
HydrationFailure->valueType
51    protected static function valueType(mixed $value): string
52    {
53        if (is_object($value)) {
54            return $value::class;
57        if (is_resource($value)) {
58            return get_resource_type($value) . ' resource';
61        return get_debug_type($value);
62    }