-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
Type.php
46 lines (37 loc) · 1.12 KB
/
Type.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\TypeInfo;
use Symfony\Component\TypeInfo\Type\BuiltinType;
use Symfony\Component\TypeInfo\Type\ObjectType;
/**
* @author Mathias Arlaud <mathias.arlaud@gmail.com>
* @author Baptiste Leduc <baptiste.leduc@gmail.com>
*/
abstract class Type implements \Stringable
{
use TypeFactoryTrait;
abstract public function getBaseType(): BuiltinType|ObjectType;
/**
* @param TypeIdentifier|class-string $subject
*/
abstract public function isA(TypeIdentifier|string $subject): bool;
abstract public function asNonNullable(): self;
/**
* @param callable(Type): bool $callable
*/
public function is(callable $callable): bool
{
return $callable($this);
}
public function isNullable(): bool
{
return $this->is(fn (Type $t): bool => $t->isA(TypeIdentifier::NULL) || $t->isA(TypeIdentifier::MIXED));
}
}