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: public const IDENTIFIER_CLASS = ReflectionClass::class;
18: public const IDENTIFIER_FUNCTION = ReflectionFunction::class;
19: public const IDENTIFIER_CONSTANT = ReflectionConstant::class;
20:
21: private const VALID_TYPES = [
22: self::IDENTIFIER_CLASS => null,
23: self::IDENTIFIER_FUNCTION => null,
24: self::IDENTIFIER_CONSTANT => null,
25: ];
26:
27: /**
28: * @var string
29: */
30: private $name;
31:
32: public function __construct(string $type = self::IDENTIFIER_CLASS)
33: {
34: if (! array_key_exists($type, self::VALID_TYPES)) {
35: throw new InvalidArgumentException(sprintf('%s is not a valid identifier type', $type));
36: }
37:
38: $this->name = $type;
39: }
40:
41: public function getName(): string
42: {
43: return $this->name;
44: }
45:
46: public function isClass(): bool
47: {
48: return $this->name === self::IDENTIFIER_CLASS;
49: }
50:
51: public function isFunction(): bool
52: {
53: return $this->name === self::IDENTIFIER_FUNCTION;
54: }
55:
56: public function isConstant(): bool
57: {
58: return $this->name === self::IDENTIFIER_CONSTANT;
59: }
60: }
61: