NonIterableCollection::invalid()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Stratadox\Deserializer;
5
6
use RuntimeException;
7
use function get_class;
8
use function sprintf;
9
10
/**
11
 * Notifies the client that the result of the collection deserialization process
12
 * resulted in output that is not iterable.
13
 *
14
 * @author Stratadox
15
 */
16
final class NonIterableCollection extends RuntimeException implements DeserializationFailure
17
{
18
    /**
19
     * Produces a deserialization exception to throw when a collection turns out
20
     * not to be iterable.
21
     *
22
     * @param object $collection      The object that turns out not to be iterable.
23
     * @return DeserializationFailure The deserialization exception to throw.
24
     */
25
    public static function invalid(object $collection): DeserializationFailure
26
    {
27
        return new NonIterableCollection(sprintf(
28
            'Invalid collection deserialization output: The `%s` class is not a collection.',
29
            get_class($collection)
30
        ));
31
    }
32
}
33