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 strictly typed responses; fix GET in extended models [#52] #53

Merged
merged 25 commits into from
Oct 6, 2017

Conversation

dnl-blkv
Copy link
Contributor

@dnl-blkv dnl-blkv commented Sep 25, 2017

Fixes #51
Fixes #52

@dnl-blkv dnl-blkv self-assigned this Sep 25, 2017
Copy link
Contributor

@DennisSnijder DennisSnijder left a comment

Choose a reason for hiding this comment

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

Impressive PR!
image

Added some minor comments / Improvements.

*/
public static function castFromBunqResponse(BunqResponse $bunqResponse): BunqResponse
{
return new static($bunqResponse->getValue(), $bunqResponse->getHeaders(), $bunqResponse->getPagination());
Copy link
Contributor

Choose a reason for hiding this comment

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

According to PSR-2 standard you should make this multiline.
Also makes it a bit more readable in my opinion

 return new static(
            $bunqResponse->getValue(),
            $bunqResponse->getHeaders(),
            $bunqResponse->getPagination()
        );

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@DennisSnijder Thanks, fixed!

Copy link
Contributor

Choose a reason for hiding this comment

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

@dnl-blkv Awesome! 😄

*
* @return BunqResponse
* @throws BunqException When the result is not expected.
*/
protected static function fromJson(BunqResponseRaw $responseRaw)
protected static function fromJson(BunqResponseRaw $responseRaw, string $wrapper = null)
Copy link
Contributor

Choose a reason for hiding this comment

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

Strictly typing the return value will make the PHPDoc unnecessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@DennisSnijder there are some things which, as of PHP 7.0 (and partially 7.1), can be expressed with PHPDoc, but not with the strict typing of PHP. Examples are nullable return statements (PHP 7.1+),throws (not present even in PHP 7.1) or late static binding.

Therefore, for now we would like to keep it to PHPDoc for now, until PHP has full and proper support of the strict typing :).

@@ -270,7 +251,7 @@ private static function determineJsonResponseValue(array $responseArray)
protected static function processForUuid(BunqResponseRaw $responseRaw)
Copy link
Contributor

Choose a reason for hiding this comment

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

Return type? 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is [WIP]; return types are coming :P

use bunq\Http\BunqResponse;

/**
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Unnecessary PHPDoc ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also occurs in a lot of other models within this PR

@dnl-blkv dnl-blkv changed the title [WIP] Add strictly typed responses; fix GET in extended models [#52] Add strictly typed responses; fix GET in extended models [#52] Sep 26, 2017
@@ -32,12 +32,10 @@
$apiContext = ApiContext::restore();

// Retrieve the active user.
Copy link
Contributor

Choose a reason for hiding this comment

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

extend the comment that if you are not a bunq business user, change ...->getUserCompany() to ...->getUserPerson()?

@@ -16,12 +16,10 @@
$apiContext = ApiContext::restore(ApiContext::FILENAME_CONFIG_DEFAULT);

// Retrieve the active user.
Copy link
Contributor

Choose a reason for hiding this comment

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

same as previous comment

Copy link
Contributor

Choose a reason for hiding this comment

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

wel, basically for every example.

@@ -114,10 +114,10 @@ private static function parsePaginationBody(array $paginationResponse)
*/
private static function updatePaginationBodyIdFieldFromResponseField(
array &$paginationBody,
Copy link
Contributor

Choose a reason for hiding this comment

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

why? now the static function, looks like you forgot to return the updated paginationBody

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This piece of logic did not change with this PR, and it is done exactly consistent with our SDKs in all the other languages. This probably should be moved to a class later, but let us keep it for a separate issue and PR! :)

{
$jsonString = FileUtil::getFileContents($fileName);

if ($jsonString === false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

there is already an exception thrown in FileUtil

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing out! I added try/catch around the call to getFileContents, so that we can still throw a context-specific exception :).

@dnl-blkv
Copy link
Contributor Author

dnl-blkv commented Oct 5, 2017

@andrederoos all answered/addressed

@andrederoos andrederoos merged commit 6c670c2 into develop Oct 6, 2017
@andrederoos andrederoos deleted the 52-strict-response branch October 6, 2017 07:33
@DennisSnijder
Copy link
Contributor

Thanks! @dnl-blkv 😄

OGKevin added a commit to bunq/sdk_python that referenced this pull request Feb 1, 2018
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.

None yet

4 participants