1: <?php
2:
3: declare(strict_types=1);
4:
5: namespace PHPStan\BetterReflection\Identifier;
6:
7: use InvalidArgumentException;
8: use PHPStan\BetterReflection\Reflection\ReflectionClass;
9: use PHPStan\BetterReflection\Reflection\ReflectionConstant;
10: use PHPStan\BetterReflection\Reflection\ReflectionFunction;
11:
12: use function array_key_exists;
13: use function sprintf;
14:
15: class IdentifierType
16: {
17: /**
18: * @var string
19: */
20: public const IDENTIFIER_CLASS = ReflectionClass::class;
21: /**
22: * @var string
23: */
24: public const IDENTIFIER_FUNCTION = ReflectionFunction::class;
25: /**
26: * @var string
27: */
28: public const IDENTIFIER_CONSTANT = ReflectionConstant::class;
29:
30: /**
31: * @var mixed[]
32: */
33: private const VALID_TYPES = [
34: self::IDENTIFIER_CLASS => null,
35: self::IDENTIFIER_FUNCTION => null,
36: self::IDENTIFIER_CONSTANT => null,
37: ];
38:
39: private string $name;
40:
41: public function __construct(string $type = self::IDENTIFIER_CLASS)
42: {
43: if (! array_key_exists($type, self::VALID_TYPES)) {
44: throw new InvalidArgumentException(sprintf(
45: '%s is not a valid identifier type',
46: $type,
47: ));
48: }
49:
50: $this->name = $type;
51: }
52:
53: public function getName(): string
54: {
55: return $this->name;
56: }
57:
58: public function isClass(): bool
59: {
60: return $this->name === self::IDENTIFIER_CLASS;
61: }
62:
63: public function isFunction(): bool
64: {
65: return $this->name === self::IDENTIFIER_FUNCTION;
66: }
67:
68: public function isConstant(): bool
69: {
70: return $this->name === self::IDENTIFIER_CONSTANT;
71: }
72: }
73: