You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TypePHP supports validating parameters, return types, properties, and `@var` local assignments against wildcard class constant patterns (`Class::PREFIX_*` or `self::PREFIX_*`).
79
+
TypePHP supports validating parameters, return types, properties, and `@var` local assignments against wildcard constant patterns (`Class::PREFIX_*` or `StatusEnum::*`).
80
80
81
-
TypePHP uses Reflection to safely inspect all matching constants—including `public`, `protected`, and `private` class constants—and validates that the incoming value matches one of the declared constant values:
81
+
***Class Constants (`Class::PREFIX_*`):** TypePHP uses Reflection to safely inspect all matching constants—including `public`, `protected`, and `private` class constants—and validates that the incoming value matches one of the declared constant scalar values.
82
+
***Enums (`StatusEnum::*` or `StatusEnum::ACT*`):** Matches incoming **Enum case objects** against the wildcard case pattern.
82
83
83
84
```php
84
85
class MigrationCollectionLoader
@@ -96,16 +97,36 @@ class MigrationCollectionLoader
96
97
}
97
98
}
98
99
100
+
enum StatusEnum: string
101
+
{
102
+
case Active = 'active';
103
+
case Inactive = 'inactive';
104
+
case Pending = 'pending';
105
+
}
106
+
107
+
class EnumProcessor
108
+
{
109
+
/**
110
+
* @param StatusEnum::ACT* $status
111
+
*/
112
+
public static function processActive(StatusEnum $status): StatusEnum
113
+
{
114
+
return $status;
115
+
}
116
+
}
117
+
99
118
$loader = new MigrationCollectionLoader();
100
119
101
-
// Valid Calls (Matches public and private VERSION_SELECTION_* constant values)
120
+
// Valid Class Constant Calls (Matches public and private VERSION_SELECTION_* constant values)
102
121
$loader->collectAllForVersion('all');
103
-
$loader->collectAllForVersion('blue-green');
104
122
$loader->collectAllForVersion('internal-mode');
105
123
106
-
// Invalid Call ('invalid_mode' does not match any VERSION_SELECTION_* constant)
107
-
$loader->collectAllForVersion('invalid_mode');
108
-
// Throws: TypeError: Argument $mode must be a valid constant matching MigrationCollectionLoader::VERSION_SELECTION_*
0 commit comments