-
Notifications
You must be signed in to change notification settings - Fork 12
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
#13 - order status update #35
Conversation
src/Api/Order/OrderResource.php
Outdated
{ | ||
$dateValue = $this->getProperty('updatedAt'); | ||
if (false === $dateValue) { | ||
return 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.
@ddattee null|\DateTimeImmutable, on évite de retourner deux types différents.
ça nous permet également de migrer vers php7 avec le support des types de retour
src/Order/OrderOperation.php
Outdated
public function addOperation($reference, $channelName, $type, $data = []) | ||
{ | ||
if (! in_array($type, $this->allowedOperationTypes)) { | ||
throw new \Exception(sprintf( |
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.
Pas d'exception du scope global, sinon le client ne pourra pas cibler précisément les exceptions du SDK à plus haut niveau dans son code.
} | ||
}, | ||
'group1' | ||
); |
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.
Une règle des tests unitaire est de les garder le plus simple possible, et donc éviter les block.
Essaie aussi d'expliquer tes intentions (dans le nom du test case, et avec des commentaires lors des assertions), car à la lecture, ce n'est pas tout de suite évident de savoir quel comportement est vérifié ici
src/Api/Order/OrderDomain.php
Outdated
{ | ||
$this->orderOperations = $orderOperation; | ||
if (! $this->orderOperations) { | ||
$this->orderOperations = new OrderOperation(); |
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.
Comme discuté, maintenir l'état de orderOperations dans cette classe expose à des effets de bord sur d'éventuels calls consécutifs
…tiple type return
src/Api/Order/OrderDomain.php
Outdated
* | ||
* @return OrderOperation | ||
*/ | ||
public function newOperations() |
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.
Merci de supprimer ce shortcut (et de mettre la documentation à jour pour être conforme avec ce que l'on a fait sur inventory:
<?php
$op = new OrderOperation();
$api->execute($op);
docs/order.md
Outdated
->newOperations() | ||
->ship('ref1', 'amazon') | ||
->ship('ref2', 'amazon', 'ups', '123456789abcdefg', 'http://tracking.url/') | ||
->execute($orderApi->getLink()); |
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.
Quelles est (sont) la (les) valeurs de retour pour chacune des opérations ?
*/ | ||
protected function eachBatch(callable $callback) | ||
protected function eachBatch(callable $callback, $groupedBy = 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.
Ce n'est pas un "regroupement", mais un filtre (ex du GROUP BY sql)
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.
La il s'agit bien d'un regroupement : on regroupe les requetes par operations car les batch ne peuvent être fait que sur une opération à la fois car on a 1 url par operation.
X batchs pour les cancels, Y batchs pour les accepts...
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.
vu ce cette classe, c'est bien un filtre, puisque seulement la clé $groupedBy est exécutée
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.
Ok compris
src/Order/OrderOperation.php
Outdated
$this->getPoolSize() | ||
); | ||
|
||
return new Api\Order\OrderCollection($resources); |
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.
On ne retourne pas une collection de order, mais des "tickets" puisque ces ops sont async
@ddattee Petite question: Quant est-il de acknowlegde / unacknowlegde ? |
src/Order/OrderOperation.php
Outdated
{ | ||
// Create requests per batch | ||
$requests = []; | ||
foreach ($this->allowedOperationTypes as $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.
Ton regroupement est fait ici ;)
|
||
class UnexpectedTypeException extends \Exception | ||
{ | ||
|
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.
space
src/Api/Order/OrderResource.php
Outdated
public function getUpdateddAt() | ||
{ | ||
$dateValue = $this->getProperty('updatedAt'); | ||
if (false === $dateValue) { |
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.
getProperty ne retourne jamais FALSE
, donc se référer à la doc API pour les valeurs non existantes :
php-sdk/src/Hal/HalResource.php
Lines 75 to 82 in 50150d4
public function getProperty($name, $default = null) | |
{ | |
if (isset($this->properties[$name])) { | |
return $this->properties[$name]; | |
} | |
return $default; | |
} |
@ronan-gloo un/acknowledge operation were on another branch I added them to this PR |
docs/order.md
Outdated
```php | ||
<?php | ||
/** @var \ShoppingFeed\Sdk\Api\Order\OrderDomain $orderApi */ | ||
$operations = new \ShoppingFeed\Sdk\Order\OrderOperation(); |
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.
UpdateOperation 😄
docs/order.md
Outdated
->refuse('ref4', 'amazon') | ||
->ship('ref5', 'amazon') | ||
->cancel('ref3', 'amazon') | ||
->execute($orderApi->getLink()); |
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.
cf commentaire sur inventory #36 (comment)
@ddattee Operations should be located at AP namespace level, it makes the sdk organisation more predictable and consistent. |
3ac8339
to
c917770
Compare
@ronan-gloo done and I updated InventoryUpdate too. |
}, | ||
null, | ||
[], | ||
$this->getPoolSize() |
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.
Pour la prochaine implémentation d'opérations sur une resource, faudra réfléchir à factoriser le tout pour éviter la duplication de code ;)
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.
Oui et faciliter le test des closure :)
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.
Cf commentaires.
Faut assurer checker le coverage sur les classes API, on n'est pas à 100% là ;)
docs/order.md
Outdated
/** @var \ShoppingFeed\Sdk\Api\Order\OrderDomain $orderApi */ | ||
$updateOperation = new \ShoppingFeed\Sdk\Api\Order\OrderOperation(); | ||
/** @var \ShoppingFeed\Sdk\Api\Order\OrderTicketCollection $ticketCollection */ | ||
$ticketCollection = $updateOperation |
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.
c'est la méthode execute
qui retourne $ticketCollection non ?
src/Api/Order/OrderOperation.php
Outdated
* @param Request $request | ||
* @param $ticketReferences | ||
*/ | ||
public function associateTicketWithReference( |
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.
Cette méthode ne doit pas faire partir de l'API publique de la classe, faudrait la passer en private
* | ||
* @return OrderTicketCollection | ||
*/ | ||
public function setTicketReferences($ticketReferences) |
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.
Les références devraient être passées à la construction de l'objet, car là on ouvre l'accès aux modifications depuis l'extérieur.
Faudrait aussi caster $ticketReferences en array
* | ||
* @throws Order\Exception\TicketNotFoundException | ||
*/ | ||
public function getShippedTicket($reference) |
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.
Pour toutes les méthodes:
-
Le paramètre $reference devrait être optionnel : dans ce cas, on retourne tous les tickets liés aux opérations "shipped"
-
côté sémantique, le "ticket" est redondant, c'est une collection de tickets ;)
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.
@ronan-gloo donc on retourne 2 types de donnée différent en fonction de ce qu'on trouve (1 resource ou un array de resource) ou alors on retourne un array dans tt les cas mais on ne peut plus faire l'enchainement : $ticketCollection->getAccepted('ref3')->getId()
Ok pour la sémantique.
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.
En effet.
Je propose que l'on remette tout ça à plus tard, le temps de trancher pour une API consistante.
On est un peu hors scope de toute manière pour le moment, donc on peu se contenter de la collection d'instances de ticket, sans accepteurs particuliers, et on blinde la suite dans une prochaine iteration.
ça te vas comme plan ?
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.
J'ai passé le tout en full array
du coup pour que ce soit consistant.
Mais je suis d'accord que la réflexion viendra avec l'API ticket surtout.
@@ -62,13 +62,35 @@ public function getPoolSize() | |||
return $this->poolSize; | |||
} | |||
|
|||
public function countOperation($groupedBy = 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.
J'aurais plutôt implémenté \Countable
ici. Faut aussi penser au docblock
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.
Si je passe par \Countable
je ne peux pas passer de filter (incompatible avec la signature de l'interface) je vais juste la renommer en count()
.
D'autant que l'interface est déjà implémenter au niveau du parent.
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.
Ah oui mal lu, désolé
Descends plutôt ça dans TicketCollection pour le moment, on a rien dans la classe abstraite qui décris une structuration des opérations (ex sur inventory). Quitte à le remonter plus tard si c'est pertinent.
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.
@ronan-gloo le count()
d'operation dans TicketCollection
? pas sur de comprendre la
* | ||
* @return TicketNotFoundException | ||
*/ | ||
public static function withOperation($operation) |
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.
Côté convention, with() sont plutôt méthodes qui clone les instances existantes (PSR http-message par exemple)
Se serait plutôt fromOperation() pour un constructeur nommé
…ce in constructor, setting $reference as optionnal, better count method, renaming exception method, updating ut
Adding accept, refuse, ship, and cancel order operations call and resolve #13 and resolve #16 .