-
Notifications
You must be signed in to change notification settings - Fork 54
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
Conversation
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.
src/Http/BunqResponse.php
Outdated
*/ | ||
public static function castFromBunqResponse(BunqResponse $bunqResponse): BunqResponse | ||
{ | ||
return new static($bunqResponse->getValue(), $bunqResponse->getHeaders(), $bunqResponse->getPagination()); |
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.
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()
);
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.
@DennisSnijder Thanks, fixed!
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.
@dnl-blkv Awesome! 😄
src/Model/BunqModel.php
Outdated
* | ||
* @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) |
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.
Strictly typing the return value will make the PHPDoc unnecessary.
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.
@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 :).
src/Model/BunqModel.php
Outdated
@@ -270,7 +251,7 @@ private static function determineJsonResponseValue(array $responseArray) | |||
protected static function processForUuid(BunqResponseRaw $responseRaw) |
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.
Return type? 😄
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.
This is [WIP]; return types are coming :P
use bunq\Http\BunqResponse; | ||
|
||
/** | ||
*/ |
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.
Unnecessary PHPDoc ?
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.
Also occurs in a lot of other models within this PR
…d missing strict type for listings [#52]
@@ -32,12 +32,10 @@ | |||
$apiContext = ApiContext::restore(); | |||
|
|||
// Retrieve the active user. |
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.
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. |
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.
same as previous comment
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.
wel, basically for every example.
@@ -114,10 +114,10 @@ private static function parsePaginationBody(array $paginationResponse) | |||
*/ | |||
private static function updatePaginationBodyIdFieldFromResponseField( | |||
array &$paginationBody, |
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.
why? now the static function, looks like you forgot to return the updated paginationBody
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.
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! :)
src/Context/ApiContext.php
Outdated
{ | ||
$jsonString = FileUtil::getFileContents($fileName); | ||
|
||
if ($jsonString === false) { |
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.
there is already an exception thrown in FileUtil
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.
Thanks for pointing out! I added try/catch around the call to getFileContents
, so that we can still throw a context-specific exception :).
@andrederoos all answered/addressed |
Thanks! @dnl-blkv 😄 |
Fixes #51
Fixes #52