Skip to content

Commit

Permalink
Merge pull request #69 from sandwave-io/order-summary-bugfixes
Browse files Browse the repository at this point in the history
Fixed date format and nullable properties
  • Loading branch information
willemdaems authored May 4, 2022
2 parents 9aad533 + 09dd548 commit 9f488e6
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 23 deletions.
7 changes: 4 additions & 3 deletions src/Helper/EntityHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ public static function deserializeXml(string $class, string $xml)

$simpleXml = new \SimpleXMLElement($xml);

if (property_exists($simpleXml, 'Header')) {
$simpleXml->Header->DateCreated = self::formatDateCreated((string) $simpleXml->Header->DateCreated);
}
$simpleXml = XmlHelper::DateConvert(
$simpleXml,
['DateCreated', 'DateModified', 'DateActive', 'DateTerminate', 'DateTerminated']
);

return $serializer->deserialize((string) $simpleXml->saveXML(), $class, 'xml');
}
Expand Down
20 changes: 20 additions & 0 deletions src/Helper/XmlHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace SandwaveIo\Office365\Helper;

use SimpleXMLElement;

final class XmlHelper
{
/**
Expand Down Expand Up @@ -106,4 +108,22 @@ public static function fetchChildNodes(string $node, \SimpleXMLElement $xml): ar

return $data;
}

/**
* @param array<string> $propertyNames
*/
public static function DateConvert(\SimpleXMLElement $simpleXml, array $propertyNames): \SimpleXMLElement
{
foreach ($propertyNames as $propertyName) {
$nodes = $simpleXml->xpath('//' . $propertyName);

/** @var array<SimpleXMLElement> $nodes */
foreach ($nodes as $node) {
/** @phpstan-ignore-next-line */
$node[0] = EntityHelper::formatDateCreated((string) $node);
}
}

return $simpleXml;
}
}
1 change: 1 addition & 0 deletions src/Library/Logger/LoggerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php declare(strict_types = 1);
20 changes: 10 additions & 10 deletions src/Response/OrderSummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ final class OrderSummary
{
private int $orderId;

private int $referenceOrderId;
private ?int $referenceOrderId;

private int $parentId;
private ?int $parentId;

private ?int $customerId;

Expand All @@ -24,13 +24,13 @@ final class OrderSummary

private DateTime $dateCreated;

private DateTime $dateActive;
private ?DateTime $dateActive;

private DateTime $dateModified;
private ?DateTime $dateModified;

private ?DateTime $dateTerminate;

private DateTime $dateTerminated;
private ?DateTime $dateTerminated;

private ?string $label;

Expand All @@ -47,12 +47,12 @@ public function getOrderId(): int
return $this->orderId;
}

public function getReferenceOrderId(): int
public function getReferenceOrderId(): ?int
{
return $this->referenceOrderId;
}

public function getParentId(): int
public function getParentId(): ?int
{
return $this->parentId;
}
Expand Down Expand Up @@ -87,12 +87,12 @@ public function getDateCreated(): DateTime
return $this->dateCreated;
}

public function getDateActive(): DateTime
public function getDateActive(): ?DateTime
{
return $this->dateActive;
}

public function getDateModified(): DateTime
public function getDateModified(): ?DateTime
{
return $this->dateModified;
}
Expand All @@ -102,7 +102,7 @@ public function getDateTerminate(): ?DateTime
return $this->dateTerminate;
}

public function getDateTerminated(): DateTime
public function getDateTerminated(): ?DateTime
{
return $this->dateTerminated;
}
Expand Down
20 changes: 10 additions & 10 deletions tests/Integration/Data/Response/OrderSummaryResponse_V1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
<ProductName>product</ProductName>
<ProductGroup>Security</ProductGroup>
<ProductCommercialTypeName>product</ProductCommercialTypeName>
<DateCreated>2014-06-20T14:37:00</DateCreated>
<DateActive>2014-06-20T14:37:00</DateActive>
<DateModified>2014-06-20T14:37:00</DateModified>
<DateTerminate>2014-06-20T14:37:00</DateTerminate>
<DateTerminated>2014-06-20T14:37:00</DateTerminated>
<DateCreated>2014-06-20T14:37:00.000</DateCreated>
<DateActive>2014-06-20T14:37:00.000</DateActive>
<DateModified>2014-06-20T14:37:00.000</DateModified>
<DateTerminate>2014-06-20T14:37:00.000</DateTerminate>
<DateTerminated>2014-06-20T14:37:00.000</DateTerminated>
<Label>label</Label>
<Attribute>attribute</Attribute>
<OrderState>Activate</OrderState>
Expand All @@ -40,11 +40,11 @@
<ProductName>product</ProductName>
<ProductGroup>Security</ProductGroup>
<ProductCommercialTypeName>product</ProductCommercialTypeName>
<DateCreated>2015-06-20T14:37:00</DateCreated>
<DateActive>2015-06-20T14:37:00</DateActive>
<DateModified>2015-06-20T14:37:00</DateModified>
<DateTerminate>2015-06-20T14:37:00</DateTerminate>
<DateTerminated>2015-06-20T14:37:00</DateTerminated>
<DateCreated>2015-06-20T14:37:00.000</DateCreated>
<DateActive>2015-06-20T14:37:00.000</DateActive>
<DateModified>2015-06-20T14:37:00.000</DateModified>
<DateTerminate>2015-06-20T14:37:00.000</DateTerminate>
<DateTerminated>2015-06-20T14:37:00.000</DateTerminated>
<Label>label</Label>
<Attribute>attribute</Attribute>
<OrderState>Activate</OrderState>
Expand Down

0 comments on commit 9f488e6

Please sign in to comment.