-
Notifications
You must be signed in to change notification settings - Fork 78
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
Base modifications #144
base: master
Are you sure you want to change the base?
Base modifications #144
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.
Thank you so much @iranl for taking the time to create this PR.
Some generic feedback:
[]
can be the default argument for array typed parameters, this allows you to remove theisset
check- The usage of some method parameters is not clear to me, can you update the relevant phpdocs.
- Please do not treat EUR currency special, always have it be made explicit
- Full class names are superior to shortened classnames: they can be autocompleted by the IDE, type checked and their usages can easily be found
- The
Office
type has been removed in some places, I think this is a merge error?
In my company we use PhpStorm and we rely heavily on type hints to prevent bugs, hence the focus on types. Basically, any method call that you cannot click in the IDE is frowned upon.
Please let me know if you have any questions or would like to discuss.
@@ -47,6 +47,11 @@ public function __construct(AuthenticatedConnection $connection) | |||
$this->connection = $connection; | |||
} | |||
|
|||
public function getConnection() |
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.
Could you add a typehint for the return type? Why is this method needed?
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.
The modified InvoicesDocument addInvoice
function uses the InvoiceTypeApiConnector
and ArticleApiConnector
to request additional information on the selected InvoiceType
and Articles
in the Invoice
, which means it needs access to the current connection. The InvoiceApiConnector sendAll
function calls the parent BaseApiConnector getConnection
function and passes the connection as an argument to addInvoice
.
Typehint added
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 @iranl! We're making good progress.
src/Mappers/BaseMapper.php
Outdated
{ | ||
if ($className == "DimensionGroupDimension" || $className == "UnknownDimension") { | ||
if ($className == "DimensionGroupDimension") { | ||
if ($objectClass == "DimensionGroupDimension" || $objectClass == "UnknownDimension") { |
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.
Should these strings be updated to class references (::class
)?
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.
No, they cannot, as they are non existent stubs that tell this function to determine the real class from an argument contained in the XML element or sibling XML element.
parseObjectAttribute
is usually used when the Twinfield entity contained in the XML is static (such as the <user>
element which will always contain a user (or nothing)). In this case ::class
is used when calling parseObjectAttribute
In DimensionGroupDimension, CustomerFinancials, FixedAssetTransactionLine and SupplierFinancials there are fields that can contain multiple or any of the 7 dimensionTypes. In these cases $className == "DimensionGroupDimension"
or $className == "UnknownDimension"
is used to tell the function to change $objectClass
to the real class name in the following switch
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.
Moved this part of the parseObjectAttribute function to a different function, seems like a cleaner solution
src/Mappers/BaseMapper.php
Outdated
if ($fieldElement->textContent === "") { | ||
return null; | ||
} | ||
|
||
return $fieldElement->textContent; | ||
} | ||
|
||
protected static function checkForMessage($object, \DOMElement $element): void |
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.
Well, this method calls addMessage()
on the object, so it cannot take any object right. It has to take an object that supports messages and the required method call.
So ideally, these objects would have an interface HasMessage
that defines the method addMessage(Message $message): void
so that you can use this typehint in the method parameter list.
You can read a bit about interfaces here: https://www.zentut.com/php-tutorial/php-interface/ Please ignore the crappy naming in the article, interfaces should have names like SupportFoo
, CanBar
or even IsBazable
to indicate the class supports some functionality.
src/Mappers/BaseMapper.php
Outdated
return $fieldElement->getAttribute($attributeName); | ||
} | ||
|
||
protected static function parseBooleanAttribute(?string $value): ?bool |
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'm not entirely convinced - I think that it for new functionality it would be hard to decide which boolean parsing function should be used. The existence of two is confusing if there is no clear guideline to pick one over the other.
Please consolidate into one method, its fine to change the one in Util, that's why we have tests.
@willemstuursma Moving along quite nicely. Thanks for all the reviewing! |
@willemstuursma Do you have any unsolved requests concerning the current PR? If not, I would like to continue with the next part of #142 |
Sorry @iranl, I noticed some changes but it is really super busy in my day job, so I didn't have time to do any further reviewing yet. |
@willemstuursma no problem. Just thought I'd check you weren't waiting on more changes from me. Will continue the conversation when you have the time. |
@willemstuursma I see you're actively reviewing PR's again. Will you be able to help this PR along? I am still willing and able to break up #142 as previously agreed. |
Hi, I'm new to this package, running into the access token issue where it's logging in for each request while I already have a valid token, which results in quite some additional requests. I could help you with the access token part, although it would be breaking for current implementations, we could use AccessTokenInterface to pass the access + refresh token + expires to let this package check if it's valid and requesting a new access token when it's invalid. Or use a setter for it, Or possible add a tokenRefresh callback method to call when token is refreshed so it can be stored externally. Because there's no way to get the access token from the current connection. Don't mean to barge in, but would love have this feature :) and can get some time from my company to help with this. Cheers, Eric |
Comprises part of the changes in #142
BaseApiConnector
BaseDocument
BaseMapper
Read
OpenIdConnectAuthentication
BaseService
Other