floor12 /
dalli-api
| 1 | <?php |
||
| 2 | |||
| 3 | |||
| 4 | namespace floor12\DalliApi; |
||
| 5 | |||
| 6 | |||
| 7 | use Exception; |
||
| 8 | use floor12\DalliApi\Enum\DalliOrderStatus; |
||
| 9 | use floor12\DalliApi\Models\Item; |
||
| 10 | use floor12\DalliApi\Models\Response\DalliOrderStatusEvent; |
||
| 11 | |||
| 12 | class OrderStatusDispatcher |
||
| 13 | { |
||
| 14 | /** @var Item[] */ |
||
| 15 | protected $items = []; |
||
| 16 | /** @var string */ |
||
| 17 | private $xmlBody; |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 18 | /** @var int|null */ |
||
| 19 | private $statusTimestamp; |
||
|
0 ignored issues
–
show
|
|||
| 20 | /** @var string|null */ |
||
| 21 | private $statusName; |
||
|
0 ignored issues
–
show
|
|||
| 22 | /** @var string|null */ |
||
| 23 | private $statusId; |
||
|
0 ignored issues
–
show
|
|||
| 24 | /** @var string */ |
||
| 25 | 2 | private $paymentType; |
|
|
0 ignored issues
–
show
|
|||
| 26 | /** @var string */ |
||
| 27 | 2 | private $deliveredTo; |
|
|
0 ignored issues
–
show
|
|||
| 28 | 2 | /** @var string */ |
|
| 29 | 2 | private $externalBarCode; |
|
| 30 | 2 | /** |
|
| 31 | * @var \$1|false|\SimpleXMLElement |
||
|
0 ignored issues
–
show
The type
$1 was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 32 | 2 | */ |
|
| 33 | private $xml; |
||
| 34 | 2 | /** |
|
| 35 | 2 | * @var DalliOrderStatusEvent[] |
|
| 36 | 2 | */ |
|
| 37 | 2 | private $statuses; |
|
| 38 | 2 | ||
| 39 | /** |
||
| 40 | 2 | * @param string $xmlBody |
|
| 41 | * @throws Exception |
||
| 42 | 2 | */ |
|
| 43 | public function __construct(string $xmlBody) |
||
| 44 | 2 | { |
|
| 45 | 2 | $this->xml = simplexml_load_string($xmlBody); |
|
| 46 | 2 | if ($this->xml === false) |
|
| 47 | 2 | throw new Exception('XML body is not valid.'); |
|
| 48 | 2 | if ($this->xml->order) { |
|
| 49 | 2 | ||
| 50 | 2 | foreach ($this->xml->order->statushistory->status as $statusItem) { |
|
| 51 | 2 | $this->statuses[] = new DalliOrderStatusEvent( |
|
| 52 | 2 | trim($statusItem[0]), |
|
| 53 | 2 | $statusItem['eventstore'], |
|
| 54 | 2 | strtotime($statusItem['eventtime'])); |
|
| 55 | } |
||
| 56 | |||
| 57 | 2 | foreach ($this->xml->order->items->item as $item) { |
|
| 58 | $orderItem = new Item(); |
||
| 59 | $orderItem->setBarcode((string)$item['barcode']) |
||
| 60 | ->setQuantity((int)$item['quantity']) |
||
| 61 | ->setReturn(boolval($item['returns'])) |
||
| 62 | ->setRetprice((float)$item['retprice']); |
||
| 63 | 1 | $this->items[$orderItem->_barcode] = $orderItem; |
|
| 64 | } |
||
| 65 | 1 | } |
|
| 66 | 1 | } |
|
| 67 | 1 | ||
| 68 | /** |
||
| 69 | * @param string|int $barcode |
||
| 70 | 1 | * @return bool|null |
|
| 71 | */ |
||
| 72 | 1 | public function isItemReturned($barcode): ?bool |
|
| 73 | { |
||
| 74 | if (isset($this->items[$barcode])) |
||
| 75 | 1 | return $this->items[$barcode]->isReturned(); |
|
| 76 | return null; |
||
| 77 | 1 | } |
|
| 78 | |||
| 79 | public function getStatusId(): ?string |
||
| 80 | 1 | { |
|
| 81 | if ($this->statuses) { |
||
|
0 ignored issues
–
show
The expression
$this->statuses of type floor12\DalliApi\Models\...DalliOrderStatusEvent[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using Loading history...
|
|||
| 82 | 1 | return $this->statuses[0]->getStatusId(); |
|
| 83 | } |
||
| 84 | return null; |
||
| 85 | } |
||
| 86 | |||
| 87 | public function getStatusName(): ?string |
||
| 88 | 1 | { |
|
| 89 | if ($this->getStatusId()) |
||
| 90 | 1 | DalliOrderStatus::getLabel($this->getStatusId()); |
|
| 91 | return null; |
||
| 92 | } |
||
| 93 | |||
| 94 | public function getStatusTimestamp(): ?int |
||
| 95 | { |
||
| 96 | if ($this->statuses) { |
||
|
0 ignored issues
–
show
The expression
$this->statuses of type floor12\DalliApi\Models\...DalliOrderStatusEvent[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using Loading history...
|
|||
| 97 | return $this->statuses[0]->getTimestamp(); |
||
| 98 | } |
||
| 99 | return null; |
||
| 100 | } |
||
| 101 | |||
| 102 | public function getItems(): array |
||
| 103 | { |
||
| 104 | return $this->items; |
||
| 105 | } |
||
| 106 | |||
| 107 | /** |
||
| 108 | * @return Item[] |
||
| 109 | */ |
||
| 110 | public function getReturnedItems(): array |
||
| 111 | { |
||
| 112 | $returned = []; |
||
| 113 | foreach ($this->items as $item) { |
||
| 114 | if ($item->isReturned()) |
||
| 115 | $returned[] = $item; |
||
| 116 | } |
||
| 117 | return $returned; |
||
| 118 | } |
||
| 119 | |||
| 120 | public function getOrderHistory(): ?array |
||
| 121 | { |
||
| 122 | return $this->statuses; |
||
| 123 | } |
||
| 124 | |||
| 125 | public function getStatuses(): array |
||
| 126 | { |
||
| 127 | return $this->statuses; |
||
| 128 | } |
||
| 129 | |||
| 130 | public function getExternalBarCode() |
||
| 131 | { |
||
| 132 | return $this->externalBarCode; |
||
| 133 | } |
||
| 134 | } |
||
| 135 |