Skip to content
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

Add support for array of enums #9497

Merged
merged 16 commits into from
Apr 4, 2022
Merged

Conversation

sanderdlm
Copy link
Contributor

@sanderdlm sanderdlm commented Feb 9, 2022

Allow the use of 'array' and 'simple_array' types in combination with the enumType attribute parameter.

This is my first PR to the project, any feedback or instructions are welcome.

I had to duplicate the try/catch which introduces a bit of redundancy. Should I make a new method for this?

This allows the use of 'array' and 'simple_array' in combination
with the enumType parameter.
@derrabus
Copy link
Member

derrabus commented Feb 9, 2022

Thank you for your PR. As this is a new feature, please target the 2.12.x branch. Also, we need tests that cover your change.

@derrabus derrabus changed the base branch from 2.11.x to 2.12.x February 9, 2022 10:57
@derrabus derrabus changed the base branch from 2.12.x to 2.11.x February 9, 2022 10:57
@sanderdlm sanderdlm changed the base branch from 2.11.x to 2.12.x February 9, 2022 11:01
@beberlei
Copy link
Member

beberlei commented Feb 9, 2022

This is a great idea, i will comment on some code improvements later

@derrabus derrabus changed the base branch from 2.12.x to 2.11.x February 9, 2022 13:59
@derrabus derrabus changed the base branch from 2.11.x to 2.12.x February 9, 2022 13:59
@derrabus
Copy link
Member

derrabus commented Feb 9, 2022

By the way, you can run all those complaining tools locally and get faster feedback. You don't have to push your changes through our CI everytime.

Once you've installed the dependencies with composer update, the following tools should be available:

  • ./vendor/bin/phpcs: PHP CodeSniffer, the tool that performs our code-style check.
  • ./vendor/bin/phpcbf: PHP Code Beautifier, a tool that can fix most PHPCS errors automatically
  • ./vendor/bin/phpstan: PHPStan (static code analysis)
  • ./vendor/bin/psalm: Psalm (the other static code analyzer)

@sanderdlm
Copy link
Contributor Author

Cheers, think I've cleared them all now 🙂

Copy link
Member

@beberlei beberlei left a comment

Choose a reason for hiding this comment

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

Initially I was wondering if the generic is_array or else handling isn't a big "dangerous", because there is no connection to the Type instance, where we know if value is an array or not, essentially allowing to "use this wrong".

But since getValue/setValue only happen to be used on data coming from the database, not from user input, I haven't found a simple example where this is not programmers error.

I am inclined to ignore that for now and see what is coming out of this change.

Very happy about the change, its simple addition allowing arrays of enums makes sense.

$e
);

if (is_array($value)) {
Copy link
Member

Choose a reason for hiding this comment

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

What do you think of refactoring it to have less duplication?

Yo could introduce a private helper method initializeEnumValue that extracts what is currently in line 81-94 and 96-108. I believe its exactly the same code or did I miss something?

Copy link
Contributor Author

@sanderdlm sanderdlm Feb 20, 2022

Choose a reason for hiding this comment

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

The code is exactly the same yeah. I've added the helper in 01a1b75.

The only thing I'm not sure about is the wording of '$item', but I couldn't come up with anything better.

@derrabus
Copy link
Member

derrabus commented Apr 4, 2022

How can we move forward here? The PR needs a rebase at least.

@sanderdlm
Copy link
Contributor Author

I can't replicate the phpcs failure locally.

@derrabus
Copy link
Member

derrabus commented Apr 4, 2022

I can't replicate the phpcs failure locally.

I've pushed a commit that should fix it.

@derrabus derrabus added this to the 2.12.0 milestone Apr 4, 2022
derrabus
derrabus previously approved these changes Apr 4, 2022
@derrabus derrabus enabled auto-merge (squash) April 4, 2022 23:21
@derrabus
Copy link
Member

derrabus commented Apr 4, 2022

Thank you @dreadnip!

@derrabus derrabus disabled auto-merge April 4, 2022 23:29
@derrabus derrabus merged commit cffe31f into doctrine:2.12.x Apr 4, 2022
derrabus added a commit to derrabus/orm that referenced this pull request Apr 5, 2022
* 2.12.x:
  Add support for array of enums (doctrine#9497)
  explicitly use the non-deprecated ORMException
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants