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 (
@@ -251,17 +242,17 @@ private static function getAttributeClassFlags(
251242 if (strtolower ($ fq_attribute_name ) === "attribute " ) {
252243 // We override this here because we still want to analyze attributes
253244 // for PHP 7.4 when the Attribute class doesn't yet exist.
254- return self ::TARGET_CLASS ;
245+ return GlobalAttribute ::TARGET_CLASS ;
255246 }
256247
257248 if ($ attribute_class_storage === null ) {
258- return self ::TARGET_ALL ; // Defaults to TARGET_ALL
249+ return GlobalAttribute ::TARGET_ALL ; // Defaults to TARGET_ALL
259250 }
260251
261252 foreach ($ attribute_class_storage ->attributes as $ attribute_attribute ) {
262253 if ($ attribute_attribute ->fq_class_name === 'Attribute ' ) {
263254 if (!$ attribute_attribute ->args ) {
264- return self ::TARGET_ALL ; // Defaults to TARGET_ALL
255+ return GlobalAttribute ::TARGET_ALL ; // Defaults to TARGET_ALL
265256 }
266257
267258 $ first_arg = $ attribute_attribute ->args [array_key_first ($ attribute_attribute ->args )];
@@ -279,7 +270,7 @@ private static function getAttributeClassFlags(
279270 }
280271
281272 if (!$ first_arg_type ->isSingleIntLiteral ()) {
282- return self ::TARGET_ALL ; // Fall back to default if it's invalid
273+ return GlobalAttribute ::TARGET_ALL ; // Fall back to default if it's invalid
283274 }
284275
285276 return $ first_arg_type ->getSingleIntLiteral ()->value ;
@@ -294,7 +285,7 @@ private static function getAttributeClassFlags(
294285 $ suppressed_issues ,
295286 );
296287
297- return self ::TARGET_ALL ; // Fall back to default if it's invalid
288+ return GlobalAttribute ::TARGET_ALL ; // Fall back to default if it's invalid
298289 }
299290
300291 /**
@@ -329,22 +320,22 @@ public static function analyzeGetAttributes(
329320
330321 switch ($ method_id ) {
331322 case "ReflectionClass::getattributes " :
332- $ target = self ::TARGET_CLASS ;
323+ $ target = GlobalAttribute ::TARGET_CLASS ;
333324 break ;
334325 case "ReflectionFunction::getattributes " :
335- $ target = self ::TARGET_FUNCTION ;
326+ $ target = GlobalAttribute ::TARGET_FUNCTION ;
336327 break ;
337328 case "ReflectionMethod::getattributes " :
338- $ target = self ::TARGET_METHOD ;
329+ $ target = GlobalAttribute ::TARGET_METHOD ;
339330 break ;
340331 case "ReflectionProperty::getattributes " :
341- $ target = self ::TARGET_PROPERTY ;
332+ $ target = GlobalAttribute ::TARGET_PROPERTY ;
342333 break ;
343334 case "ReflectionClassConstant::getattributes " :
344- $ target = self ::TARGET_CLASS_CONSTANT ;
335+ $ target = GlobalAttribute ::TARGET_CLASS_CONSTANT ;
345336 break ;
346337 case "ReflectionParameter::getattributes " :
347- $ target = self ::TARGET_PARAMETER ;
338+ $ target = GlobalAttribute ::TARGET_PARAMETER ;
348339 break ;
349340 default :
350341 return ;
0 commit comments