-
Notifications
You must be signed in to change notification settings - Fork 1
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
Fix inconsistency issues #37
Conversation
Code Climate has analyzed commit 277fbd3 and detected 0 issues on this pull request. The test coverage on the diff in this pull request is 100.0% (50% is the threshold). This pull request will bring the total coverage in the repository to 83.2% (0.0% change). View more on Code Climate. |
@@ -121,14 +121,13 @@ function new_credentials(): APNSCredentials { | |||
return new APNSCredentials( $this->random_string( 10 ), $this->random_string( 10 ), '' ); | |||
} | |||
|
|||
function encode( $object ) { | |||
function to_stdclass( $object ): object { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've renamed this method to make things clearer at the call site.
$object = $this->encode_to_array( $push ); | ||
unset( $object['aps'] ); | ||
$this->assertEquals( $custom_data, $object ); | ||
$object = $this->to_stdclass( $push ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
encode_to_array
was only used in one place, so I got rid of it and am using objects instead for consistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks consistent.
I looked up the docs for JsonSerializable
,
Objects implementing
JsonSerializable
can customize their JSON representation when encoded withjson_encode()
.
From here, it seems that the preferred method to encode to JSON from the library is now to call toJSON()
. Am I correct? What's the advantage over a the standard (is it standard?) json_encode()
approach? One good thing that stands out to me is that with toJSON()
we get better looking ->
chaining.
Yeah, I don't mind re-adding |
APNSConfiguration.getEndpoint
method have consistent casingtoJSON
method onAPNSPayload
that provides consistency with other encodable objects and consistency when encoding.