Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Goal
This PR improves our handling of enums when added as metadata
PHP has two types of enums, "pure" and "backed". A pure enum contains only cases with no values, whereas a backed enum has a string or int value for each case. For example:
Currently when a pure enum is added as metadata it falls into our generic object handling, which ends up converting it to
null
as there is no default serialisation for pure enumsThis PR fixes this by converting the enum to a string in the form
EnumName::CaseName
, e.g.PureEnum::One
using the example aboveBacked enums aren't broken as they are converted into their backing values, e.g.
StringBackedEnum::One
is serialised as the stringone
. This could be improved however, given the enum name is usually more important than the raw valueThis PR changes backed enums to be serialised in the form
EnumName::CaseName (value)
, e.g.IntBackedEnum::One (1)
These changes result in the following being shown in the Bugsnag dashboard:
Testing
Two new PHPT tests have been added; one that tests pure enums and one that tests backed enums. PHPT tests are being used because PHP versions without enum support will fail to compile files that declare enums, making it a bit awkward to unit test