|
| 1 | +<?php declare(strict_types = 1); |
| 2 | + |
| 3 | +namespace PHPStan\Rules; |
| 4 | + |
| 5 | +use function array_key_exists; |
| 6 | + |
| 7 | +final class ClassNameUsageLocation |
| 8 | +{ |
| 9 | + |
| 10 | + public const TRAIT_USE = 'traitUse'; |
| 11 | + public const STATIC_PROPERTY_ACCESS = 'staticPropertyAccess'; |
| 12 | + public const PHPDOC_TAG_ASSERT = 'phpDocTagAssert'; |
| 13 | + public const ATTRIBUTE = 'attribute'; |
| 14 | + public const EXCEPTION_CATCH = 'exceptionCatch'; |
| 15 | + public const CLASS_CONSTANT_ACCESS = 'classConstantAccess'; |
| 16 | + public const CLASS_IMPLEMENTS = 'classImplements'; |
| 17 | + public const ENUM_IMPLEMENTS = 'enumImplements'; |
| 18 | + public const INTERFACE_EXTENDS = 'interfaceExtends'; |
| 19 | + public const CLASS_EXTENDS = 'classExtends'; |
| 20 | + public const INSTANCEOF = 'instanceof'; |
| 21 | + public const PROPERTY_TYPE = 'propertyType'; |
| 22 | + public const USE_STATEMENT = 'use'; |
| 23 | + public const PARAMETER_TYPE = 'parameterType'; |
| 24 | + public const RETURN_TYPE = 'returnType'; |
| 25 | + public const PHPDOC_TAG_SELF_OUT = 'phpDocTagSelfOut'; |
| 26 | + public const PHPDOC_TAG_VAR = 'phpDocTagVar'; |
| 27 | + public const INSTANTIATION = 'new'; |
| 28 | + public const TYPE_ALIAS = 'typeAlias'; |
| 29 | + public const PHPDOC_TAG_METHOD = 'phpDocTagMethod'; |
| 30 | + public const PHPDOC_TAG_MIXIN = 'phpDocTagMixin'; |
| 31 | + public const PHPDOC_TAG_PROPERTY = 'phpDocTagProperty'; |
| 32 | + public const PHPDOC_TAG_REQUIRE_EXTENDS = 'phpDocTagRequireExtends'; |
| 33 | + public const PHPDOC_TAG_REQUIRE_IMPLEMENTS = 'phpDocTagRequireImplements'; |
| 34 | + public const STATIC_METHOD_CALL = 'staticMethodCall'; |
| 35 | + public const PHPDOC_TAG_TEMPLATE_BOUND = 'phpDocTemplateBound'; |
| 36 | + public const PHPDOC_TAG_TEMPLATE_DEFAULT = 'phpDocTemplateDefault'; |
| 37 | + |
| 38 | + /** @var array<string, self> */ |
| 39 | + public static array $registry = []; |
| 40 | + |
| 41 | + /** |
| 42 | + * @param self::* $value |
| 43 | + */ |
| 44 | + private function __construct(string $value) // @phpstan-ignore constructor.unusedParameter |
| 45 | + { |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * @param self::* $value |
| 50 | + */ |
| 51 | + public static function from(string $value): self |
| 52 | + { |
| 53 | + if (array_key_exists($value, self::$registry)) { |
| 54 | + return self::$registry[$value]; |
| 55 | + } |
| 56 | + |
| 57 | + return self::$registry[$value] = new self($value); |
| 58 | + } |
| 59 | + |
| 60 | +} |
0 commit comments