Skip to content

Conversation

@potsed
Copy link
Contributor

@potsed potsed commented Aug 29, 2018

Add a way to get constant via a value.

  • Sometimes the value is given, not the constant
  • This adds some methods via a trait to
  • flip() - Flip the mapped values
  • constantOf( $value ) - returns the constant based on the value.

I made this a trait because it only makes sense in some use cases and when the constants and values are both simple types (ints, strings)

Also added some tests for coverage

@potsed potsed requested a review from jodiedunlop August 29, 2018 05:19
Copy link
Contributor

@jodiedunlop jodiedunlop left a comment

Choose a reason for hiding this comment

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

Happy for you to merge this, but perhaps make it part of the main class instead of a trait, but would suggest the following:

  1. Don't know if flip() as part of a public interface is that useful. (i like as little exposed as possible) ... If you disagree and see a good use-case for it then just ignore me :)
  2. Definitely think constantOf() is useful, but maybe fromValue() would show the intent better, up to you

@potsed
Copy link
Contributor Author

potsed commented Aug 29, 2018

Great comments @jodiedunlop

I'm not opinionated with the flip method except to suggest it is the alter-ego of map() and map is public so matching the access makes some sense on that level.

  • [As a side note was thinking of calling it pam() but WTF]

Again not opinionated on the name, I tried to follow existing naming convention similar to valueOf($key) which already existed.

As for being a trait, I originally had it as part of the main Enum class, however the fact that array_flip does not like multidimensional arrays - an available feature of the mapping - I felt that the implementor should not have access to it unless they specifically needed and understood the limitations it could cause.

I'm happy to reverse that if need be too. I'll add docs when it's settled.

@potsed potsed merged commit ad27a93 into master Aug 29, 2018
@potsed potsed deleted the ds/flip branch August 29, 2018 23:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants