44
55namespace Psalm \Internal \Analyzer ;
66
7+ use Attribute as GlobalAttribute ;
78use Generator ;
89use PhpParser \Node \Arg ;
910use PhpParser \Node \Attribute ;
@@ -47,16 +48,6 @@ final class AttributesAnalyzer
4748 40 => 'promoted property ' ,
4849 ];
4950
50- // Copied from Attribute class since that class might not exist at runtime
51- public const TARGET_CLASS = 1 ;
52- public const TARGET_FUNCTION = 2 ;
53- public const TARGET_METHOD = 4 ;
54- public const TARGET_PROPERTY = 8 ;
55- public const TARGET_CLASS_CONSTANT = 16 ;
56- public const TARGET_PARAMETER = 32 ;
57- public const TARGET_ALL = 63 ;
58- public const IS_REPEATABLE = 64 ;
59-
6051 /**
6152 * @param array<array-key, AttributeGroup> $attribute_groups
6253 * @param key-of<self::TARGET_DESCRIPTIONS> $target
@@ -104,7 +95,7 @@ public static function analyze(
10495 $ storage instanceof ClassLikeStorage ? $ storage : null ,
10596 );
10697
107- if (($ attribute_class_flags & self ::IS_REPEATABLE ) === 0 ) {
98+ if (($ attribute_class_flags & GlobalAttribute ::IS_REPEATABLE ) === 0 ) {
10899 // Not IS_REPEATABLE
109100 if (isset ($ appearing_non_repeatable_attributes [$ fq_attribute_name ])) {
110101 IssueBuffer::maybeAdd (
@@ -252,17 +243,17 @@ private static function getAttributeClassFlags(
252243 if (strtolower ($ fq_attribute_name ) === "attribute " ) {
253244 // We override this here because we still want to analyze attributes
254245 // for PHP 7.4 when the Attribute class doesn't yet exist.
255- return self ::TARGET_CLASS ;
246+ return GlobalAttribute ::TARGET_CLASS ;
256247 }
257248
258249 if ($ attribute_class_storage === null ) {
259- return self ::TARGET_ALL ; // Defaults to TARGET_ALL
250+ return GlobalAttribute ::TARGET_ALL ; // Defaults to TARGET_ALL
260251 }
261252
262253 foreach ($ attribute_class_storage ->attributes as $ attribute_attribute ) {
263254 if ($ attribute_attribute ->fq_class_name === 'Attribute ' ) {
264255 if (!$ attribute_attribute ->args ) {
265- return self ::TARGET_ALL ; // Defaults to TARGET_ALL
256+ return GlobalAttribute ::TARGET_ALL ; // Defaults to TARGET_ALL
266257 }
267258
268259 $ first_arg = $ attribute_attribute ->args [array_key_first ($ attribute_attribute ->args )];
@@ -280,7 +271,7 @@ private static function getAttributeClassFlags(
280271 }
281272
282273 if (!$ first_arg_type ->isSingleIntLiteral ()) {
283- return self ::TARGET_ALL ; // Fall back to default if it's invalid
274+ return GlobalAttribute ::TARGET_ALL ; // Fall back to default if it's invalid
284275 }
285276
286277 return $ first_arg_type ->getSingleIntLiteral ()->value ;
@@ -295,7 +286,7 @@ private static function getAttributeClassFlags(
295286 $ suppressed_issues ,
296287 );
297288
298- return self ::TARGET_ALL ; // Fall back to default if it's invalid
289+ return GlobalAttribute ::TARGET_ALL ; // Fall back to default if it's invalid
299290 }
300291
301292 /**
@@ -330,22 +321,22 @@ public static function analyzeGetAttributes(
330321
331322 switch ($ method_id ) {
332323 case "ReflectionClass::getattributes " :
333- $ target = self ::TARGET_CLASS ;
324+ $ target = GlobalAttribute ::TARGET_CLASS ;
334325 break ;
335326 case "ReflectionFunction::getattributes " :
336- $ target = self ::TARGET_FUNCTION ;
327+ $ target = GlobalAttribute ::TARGET_FUNCTION ;
337328 break ;
338329 case "ReflectionMethod::getattributes " :
339- $ target = self ::TARGET_METHOD ;
330+ $ target = GlobalAttribute ::TARGET_METHOD ;
340331 break ;
341332 case "ReflectionProperty::getattributes " :
342- $ target = self ::TARGET_PROPERTY ;
333+ $ target = GlobalAttribute ::TARGET_PROPERTY ;
343334 break ;
344335 case "ReflectionClassConstant::getattributes " :
345- $ target = self ::TARGET_CLASS_CONSTANT ;
336+ $ target = GlobalAttribute ::TARGET_CLASS_CONSTANT ;
346337 break ;
347338 case "ReflectionParameter::getattributes " :
348- $ target = self ::TARGET_PARAMETER ;
339+ $ target = GlobalAttribute ::TARGET_PARAMETER ;
349340 break ;
350341 default :
351342 return ;
0 commit comments