File tree Expand file tree Collapse file tree 3 files changed +13
-5
lines changed Expand file tree Collapse file tree 3 files changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -12,32 +12,32 @@ TypeGuard can validate:
12
12
- Scalar types: ` string ` , ` integer ` , etc.:
13
13
14
14
``` php
15
- (new \TypeGuard\Type ('string'))->match('foo'); // => true
15
+ (new \TypeGuard\Guard ('string'))->match('foo'); // => true
16
16
```
17
17
18
18
- Object types: ` ArrayAccess ` , ` stdClass ` , etc.:
19
19
20
20
``` php
21
- (new \TypeGuard\Type ('stdClass'))->match(new stdClass()); // => true
21
+ (new \TypeGuard\Guard ('stdClass'))->match(new stdClass()); // => true
22
22
```
23
23
24
24
- Union types: ` string|integer ` :
25
25
26
26
``` php
27
- $guard = new \TypeGuard\Type ('string|integer');
27
+ $guard = new \TypeGuard\Guard ('string|integer');
28
28
$guard->match('foo'); // => true
29
29
$guard->match(1); // => true
30
30
```
31
31
32
32
- Intersection types: ` ArrayAccess&Countable ` :
33
33
34
34
``` php
35
- (new \TypeGuard\Type ('ArrayAccess&Countable'))->match(new ArrayIterator()); // => true
35
+ (new \TypeGuard\Guard ('ArrayAccess&Countable'))->match(new ArrayIterator()); // => true
36
36
```
37
37
38
38
- Optional types: ` ?string ` :
39
39
40
40
``` php
41
- (new \TypeGuard\Type ('?string'))->match(null); // => true
41
+ (new \TypeGuard\Guard ('?string'))->match(null); // => true
42
42
```
43
43
Original file line number Diff line number Diff line change @@ -18,6 +18,10 @@ public function __construct(string $typeName)
18
18
*/
19
19
public function match ($ parameter ): bool
20
20
{
21
+ if ('mixed ' === $ this ->typeName ) {
22
+ return true ;
23
+ }
24
+
21
25
$ type = \gettype ($ parameter );
22
26
23
27
return $ type === 'object '
Original file line number Diff line number Diff line change @@ -25,6 +25,10 @@ public function matchDataProvider(): array
25
25
['NULL ' , null , true ],
26
26
['ArrayAccess ' , new \ArrayIterator , true ],
27
27
['Countable ' , new \ArrayIterator , true ],
28
+ ['mixed ' , 'foo ' , true ],
29
+ ['mixed ' , 1 , true ],
30
+ ['mixed ' , null , true ],
31
+ ['mixed ' , new \ArrayIterator , true ],
28
32
];
29
33
}
30
34
}
You can’t perform that action at this time.
0 commit comments