AreOfList::isSatisfiedBy()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 2
nc 2
nop 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Stratadox\Deserializer\Condition;
5
6
use function array_values;
7
use function is_array;
8
use Stratadox\Specification\Contract\Specifies;
9
use Stratadox\Specification\Specifying;
10
11
/**
12
 * Condition that accepts list typed input.
13
 *
14
 * Can be used to conditionally act upon list input. An example could be when
15
 * deserializing a json segment that contains either an element x or a list of
16
 * elements x. This specification can be used to make the deserializer aware
17
 * of the possibility of a list input and make it act accordingly.
18
 *
19
 * @author Stratadox
20
 */
21
final class AreOfList implements Specifies
22
{
23
    use Specifying;
24
25
    /**
26
     * Produces a condition that accepts list type input.
27
     *
28
     * @return Specifies The type enforcing condition.
29
     */
30
    public static function type(): Specifies
31
    {
32
        return new self();
33
    }
34
35
    /** @inheritdoc */
36
    public function isSatisfiedBy($input): bool
37
    {
38
        return is_array($input)
39
            && $input === array_values($input);
40
    }
41
}
42