Skip to content

Conversation

@VincentLanglet
Copy link
Contributor

}
if ($enumNode->scalarType === null && $stmt->expr !== null) {
$errors[] = RuleErrorBuilder::message(sprintf(
'Enum %s is not backed, but case %s has value.',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message changed from

Enum %s is not backed, but case %s has value %s. 

to

Enum %s is not backed, but case %s has value. 

I'm not sure you're okay with this or if

  • it should be behind bleedingEdge
  • it should be behind some extra condition (and have two differents messages ?)

$exprType = $scope->getType($stmt->expr);
$constantValues = $exprType->getConstantScalarValues();
if (count($constantValues) === 1) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By setting enum cases value here, instead of in the condition

if ($stmt->expr instanceof Node\Scalar\Int_ || $stmt->expr instanceof Node\Scalar\String_) 

I also catch other constant values like the one set with a class Constant.

Cf test

enum Backed: int {	case One = Foo::A;	case Two = Foo::A; } 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants