Skip to content

Commit

Permalink
Kontrol edilen kod serviste bulunamadığında Not Found durumunda cevap…
Browse files Browse the repository at this point in the history
… dön
  • Loading branch information
GoktugOzturk committed Nov 12, 2018
1 parent 6ada49e commit 98f92fa
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/Company/ServiceAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,12 @@ public function getShipmentStatusByDeliveryDate(\DateTime $date): array
{
throw new MethodNotSupported();
}

protected function shipmentStatusNotFound(){
$shipmentStatus = new ShipmentStatus();
$shipmentStatus->setStatusCode(ShipmentStatus::STATUS_NOT_FOUND)
->setStatusDetails('Not Found')
->setOriginalStatus(0);
return $shipmentStatus;
}
}
14 changes: 10 additions & 4 deletions src/Company/Ups/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,10 @@ public function getPackageInfoByReferenceNumber(string $referenceNumber): Packag
public function getShipmentStatusByTrackingNumber(string $trackingNumber): ShipmentStatus
{
$response = $this->getShipmentStatusByTrackingNumberList([$trackingNumber]);
return current($response);
if (count($response)) {
return current($response);
}
return $this->shipmentStatusNotFound()->setTrackingNumber($trackingNumber);
}

/**
Expand All @@ -210,7 +213,10 @@ public function getShipmentStatusByTrackingNumber(string $trackingNumber): Shipm
public function getShipmentStatusByReferenceNumber(string $referenceNumber): ShipmentStatus
{
$response = $this->getShipmentStatusByReferenceNumberList([$referenceNumber]);
return current($response);
if (count($response)) {
return current($response);
}
return $this->shipmentStatusNotFound()->setReferenceNumber($referenceNumber);
}

/**
Expand All @@ -237,7 +243,7 @@ public function getShipmentStatusByTrackingNumberList(array $list): array
$trnType)
);
$response = [];
foreach ($resultWebService->getGetTransactionsByList_V1Result() as $item) {
foreach ((array)$resultWebService->getGetTransactionsByList_V1Result()->getPackageTransactionwithDeliveryDetail() as $item) {
if ($item instanceof PackageTransactionwithDeliveryDetail) {
$shipmentStatus = $this->populateShipmentStatusFromItem($item);
$response[$shipmentStatus->getTrackingNumber()] = $shipmentStatus;
Expand Down Expand Up @@ -271,7 +277,7 @@ public function getShipmentStatusByReferenceNumberList(array $list): array
)
);
$response = [];
foreach ($resultWebService->getGetTransactionsByList_V1Result() as $item) {
foreach ((array)$resultWebService->getGetTransactionsByList_V1Result()->getPackageTransactionwithDeliveryDetail() as $item) {
if ($item instanceof PackageTransactionwithDeliveryDetail) {
$shipmentStatus = $this->populateShipmentStatusFromItem($item);
$response[$shipmentStatus->getReferenceNumber()] = $shipmentStatus;
Expand Down
1 change: 1 addition & 0 deletions src/Response/ShipmentStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

class ShipmentStatus
{
const STATUS_NOT_FOUND = 'NotFound';
const STATUS_PACKAGE_SCANNED = 'Scanned';
const STATUS_DELIVERED = 'Delivered';
const STATUS_EXCEPTION = 'Exception';
Expand Down

0 comments on commit 98f92fa

Please sign in to comment.