-
Notifications
You must be signed in to change notification settings - Fork 650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enum support #6425
Comments
I found these snippets: https://psalm.dev/r/d153c9d4f0<?php
enum Status: int
{
case FOO = 1;
case BAR = 2;
}
$statusA = Status::FOO;
$statusB = Status::FOO;
$statusC = Status::BAR;
$statusA === $statusB; // true
$statusA === $statusC; // false
$statusC instanceof Status; // true
|
@niconoe- mind elaborating on those two non-linked points? |
About About In the first case, the attribute usage is triggered by Psalm because In the 2nd case, the attribute usage should be triggered by Psalm but not for the given reason, as currently it's the fact that Maybe there are still other cases to discover when mixing attributes with enums, but I'm not familiar enough with both of them to go deeper. |
I found these snippets: https://psalm.dev/r/c31b9b8e81<?php
#[Attribute]
enum Status: int
{
case FOO = 1;
case BAR = 2;
}
#[Status]
class HelloWorld
{}
https://psalm.dev/r/36779dc1b9<?php
#[Attribute(Attribute::TARGET_CLASS)]
enum Status: int
{
case FOO = 1;
case BAR = 2;
}
class HelloWorld
{
#[Status]
public function _() {}
}
|
|
Enums in attributes are not properly detected for their types |
I found these snippets: https://psalm.dev/r/aa57812a88<?php
class CreateController
{
#[Action(usage: '--type={(get-post-put-delete-patch)} --module={module} --noview={true|false} {controller} {action}', description: 'Create a new controller action from the template file.')]
#[Param(type: 'string', name: 'controller', description: 'Name of controller to create action in.' . "\n" . ' Controller file is created if it does not exist.')]
#[Param(type: 'string', name: 'action', description: 'Name of action to create.' . "\n" . ' Creates associated view file unless noview is true')]
#[Param(type: 'string', name: 'type', description: 'HTTP Methods for Controller Action, dash separated. Defaults to get', paramType: ParamType::FLAG)]
#[Param(type: 'string', name: 'module', description: 'Optional - Module to create controller in (CLI for command line)', paramType: ParamType::FLAG)]
#[Param(type: 'bool', name: 'noview', description: 'True to skip creating view file', paramType: ParamType::FLAG)]
public function actionGet(
?string $controller = null,
?string $action = null,
string $type = 'get',
?string $module = null,
bool $noview = false
): void {
}
}
use Attribute;
#[Attribute(Attribute::TARGET_METHOD)]
class Action
{
public function __construct(public string $usage = '', public string $description = '')
{
}
/**
* Get pretty format usage text
*
* @param string $usage
* @param string $name
* @return string
*/
public function getHelpText(string $usage, string $name): string
{
return trim(implode(' ', ['Usage:', $usage, $name, $this->usage]));
}
}
#[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
class Param
{
public function __construct(
public string $type = '',
public string $name = '',
public string $description = '',
public ParamType $paramType = ParamType::PARAM
) {
}
}
enum ParamType
{
case FLAG;
case PARAM;
}
|
|
I found these snippets: https://psalm.dev/r/9df7604507<?php
function value(BackedEnum $e): int|string {
return $e->value;
}
function name(BackedEnum $e): string {
return $e->name;
}
function intValue(IntBackedEnum $e): int {
return $e->value;
}
function stringValue(StringBackedEnum $e): string {
return $e->value;
}
https://psalm.dev/r/461a456ffb<?php
function value(BackedEnum $e): int|string {
return $e->value;
}
function name(BackedEnum $e): string {
return $e->name;
}
|
Do they? https://3v4l.org/3piBE#v8.1.1 |
Hm, my bad, looked into wrong stubs. So only this one should not give any error https://psalm.dev/r/461a456ffb. |
I found these snippets: https://psalm.dev/r/461a456ffb<?php
function value(BackedEnum $e): int|string {
return $e->value;
}
function name(BackedEnum $e): string {
return $e->name;
}
|
As far as I can tell, Enum are now fully supported. Please open new issues if bugs are found |
from @niconoe- (#6395 (comment))
enum_exists
#6431https://wiki.php.net/rfc/enumerations
The text was updated successfully, but these errors were encountered: