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

TypeRestriction   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 5
c 2
b 0
f 0
dl 0
loc 28
rs 10
wmc 2

2 Methods

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