refactor: enhance type safety and improve request flexibility#5
refactor: enhance type safety and improve request flexibility#5fordimalanda wants to merge 13 commits into
Conversation
…ptional parameters
…ctor Environment endpoints
…e CardRequest declaration
… string fallbacks
… readonly constraints
… camelCase mapping
|
@fordimalanda can you tell us what issue are you trying to solve exactly ? It will be helpful you can tell us the step to reproduce the bug you had first |
|
@bernard-ng, To give more context, the primary goal of this PR is to resolve a critical class redeclaration error and fix strict type mismatches that appeared when running the SDK in PHP 8.4 environments. 1. The IssueThe core Furthermore, some optional parameters were passing 2. Steps to Reproduce
3. The Solution
All changes have been verified with the existing test suite, which now passes with 11 tests and 35 assertions on PHP 8.4. |
|
@fordimalanda are you using 2.1.0 ? flexpay-php/src/Request/Request.php Line 16 in 11f7128 as you can see I don't have a declaration issue here and pipeline is working fine on the latest version of the package... can I see the full error message and maybe the stack trace please ? |
|
You are right, the The conflict specifically happened because, in my local environment, the Here is the error I encountered: Fatal error: Cannot redeclare class Devscast\Flexpay\Request\CardRequest in E:\#projets_github\#1.FORK\flexpay-php\src\Request\Request.php on line XXWhy this PR still matters:
I suggest we focus on these improvements which stabilize the SDK for the upcoming PHP versions. 47f6a47 |
bernard-ng
left a comment
There was a problem hiding this comment.
The added comments are not very useful; they only make the code more verbose.
I’m also still unable to reproduce the typing error you mentioned. Could you provide a minimal reproducer with clear steps to trigger the error?
Also, are you testing this usage against the real Flexpay API? If yes, which version?
The current implementation follows Flexpay’s actual constraints, even when those constraints are not explicitly stated in the official documentation.
| public readonly string $description = '', | ||
| public readonly string $approveUrl = '', | ||
| public readonly string $cancelUrl = '', | ||
| public readonly string $declineUrl = '', |
There was a problem hiding this comment.
This would be a breaking change. Why should we accept empty strings where null is expected? Also, changing the parameter order will break code for developers who do not rely on positional arguments.
| string $description = '', | ||
| string $approveUrl = '', | ||
| string $cancelUrl = '', | ||
| string $declineUrl = '', | ||
| public string $homeUrl = '', |
There was a problem hiding this comment.
Another breaking change here. Last time I checked the Flexpay API, those URLs were mandatory and they still are.
If the user does not have corresponding handlers in their app, they should provide the app’s default URL on the calling side.
|
@fordimalanda can you rebase, pipeline is still not green. and if possible add a test case to trigger your TypeError or provide a snippet of your usage. Thanks |
|
Thanks for the detailed review @bernard-ng. I understand your concerns regarding backward compatibility and API constraints. Here is my plan to align the PR:
I'll push the updated code shortly with the fix for the pipeline. |
|
@fordimalanda sounds good for me
CardRequest and MobileRequest are instanciated by the user (calling side), let's see if your reproducer give more hints about your error. |
Reproducer for the
|
|
@fordimalanda interesting, but I'm still failing to understand why i've got this issue. flexpay-php/src/Request/Request.php Line 28 in f6b4af2 flexpay-php/src/Request/MobileRequest.php Line 26 in f6b4af2 Can you fix code style and add a test case for this particular issue ? |
Description
This pull request introduces significant improvements to the SDK's type system and request handling to ensure compatibility with PHP 8.4 and improve developer experience. The refactoring focuses on strict typing, immutability, and removing architectural inconsistencies.
Changes
Request.phpby separating core logic from specific implementations.declare(strict_types=1)across all modified files and updated properties to use PHP 8.x features likereadonlywhere appropriate.CardRequestto make redirection URLs (approveUrl,cancelUrl,declineUrl) optional, allowing for simpler integrations when these are not required.TypeErrorinMobileRequestby ensuring optional parameters default to empty strings rather than null, maintaining compatibility with the baseRequestconstructor.Environment.phpto use a centralizedgetBaseUrl()method, reducing code duplication and simplifying future endpoint updates.#[SerializedName]attributes in response classes where the API response keys already match the property names in camelCase.Impact
Verification
11 tests, 35 assertionspassed successfully.