NonIterableCollection   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
eloc 3
c 1
b 0
f 0
dl 0
loc 14
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A invalid() 0 5 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