Completed
Push — master ( ab134c...aa7bb6 )
by Marco
24:30 queued 15:40
created

TypeRestriction::array()   A

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
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace RoaveTest\BackwardCompatibility;
6
7
use function assert;
8
use function is_array;
9
10
/**
11
 * This utility is mostly for test purposes only: it takes values and makes sure they match
12
 * an expected type, allowing us to ignore some of the type errors that psalm/phpstan would otherwise
13
 * pick up. It still asserts on the given values.
14
 */
15
final class TypeRestriction
16
{
17
    /**
18
     * @param mixed[]|mixed $value
19
     *
20
     * @return mixed[]
21
     *
22
     * @psalm-template ArrayishParameterType of array
23
     * @psalm-param    ArrayishParameterType|mixed $value
24
     * @psalm-return   ArrayishParameterType
25
     */
26
    public static function array($value) : array
27
    {
28
        assert(is_array($value));
29
30
        return $value;
31
    }
32
33
    /**
34
     * @psalm-template ObjectishParameterType of object
35
     * @psalm-param    ObjectishParameterType|null $value
36
     * @psalm-return   ObjectishParameterType
37
     */
38
    public static function object(?object $value) : object
39
    {
40
        assert($value !== null);
41
42
        return $value;
43
    }
44
}
45