Skip to content

Fix Rate RequestOption and type-hinting #349

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@
}
],
"require": {
"php": "^7.3 || ^8.0",
"php": "^7.4 || ^8.0",
"ext-dom": "*",
"ext-simplexml": "*",
"guzzlehttp/guzzle": "^6.0 || ^7.0",
"psr/log": "^1.0"
"psr/log": "^1.0",
"phpstan/phpstan": "^1.6"
},
"require-dev": {
"phpunit/phpunit": "^9.5.4"
Expand Down
5 changes: 5 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
level: 8
paths:
- src

37 changes: 16 additions & 21 deletions src/Entity/RateInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@

class RateInformation implements NodeInterface
{
/** @var bool */
private $negotiatedRatesIndicator;
private string $negotiatedRatesIndicator;

/** @var bool */
private $rateChartIndicator;
private string $rateChartIndicator;

/**
* @param null|object $attributes
Expand All @@ -36,8 +34,9 @@ public function __construct($attributes = null)
* @param null|DOMDocument $document
*
* @return DOMElement
* @throws \DOMException
*/
public function toNode(DOMDocument $document = null)
public function toNode(DOMDocument $document = null): DOMElement
{
if (null === $document) {
$document = new DOMDocument();
Expand All @@ -46,53 +45,49 @@ public function toNode(DOMDocument $document = null)
$node = $document->createElement('RateInformation');

if ($this->getNegotiatedRatesIndicator()) {
$node->appendChild($document->createElement('NegotiatedRatesIndicator'));
$node->appendChild($document->createElement('NegotiatedRatesIndicator', $this->getNegotiatedRatesIndicator()));
}

if ($this->getRateChartIndicator()) {
$node->appendChild($document->createElement('RateChartIndicator'));
$node->appendChild($document->createElement('RateChartIndicator', $this->getRateChartIndicator()));
}

return $node;
}

/**
* @return bool
* @return string
*/
public function getNegotiatedRatesIndicator()
public function getNegotiatedRatesIndicator(): string
{
return $this->negotiatedRatesIndicator;
}

/**
* @param $value
* @param string $value
*
* @return $this
* @return void
*/
public function setNegotiatedRatesIndicator($value)
public function setNegotiatedRatesIndicator(string $value): void
{
$this->negotiatedRatesIndicator = $value;

return $this;
}

/**
* @return bool
* @return string
*/
public function getRateChartIndicator()
public function getRateChartIndicator(): string
{
return $this->rateChartIndicator;
}

/**
* @param $value
* @param string $value
*
* @return $this
* @return void
*/
public function setRateChartIndicator($value)
public function setRateChartIndicator(string $value): void
{
$this->rateChartIndicator = $value;

return $this;
}
}
80 changes: 23 additions & 57 deletions src/Entity/RateRequest.php
Original file line number Diff line number Diff line change
@@ -1,94 +1,60 @@
<?php
<?php declare(strict_types=1);

namespace Ups\Entity;

use Ups\Entity\RatingServiceSelectionRequest\Request;

class RateRequest
{
/** @deprecated */
public $PickupType;
/** @deprecated */
public $Shipment;

/**
* @var PickupType
*/
private $pickupType;

/**
* @var CustomerClassification
*/
private $customerClassification;

/**
* @var Shipment
*/
private $shipment;
private PickupType $pickupType;
private ?CustomerClassification $customerClassification = null;
private Shipment $shipment;
private Request $request;

public function __construct()
{
$this->setRequest(new Request());
$this->setShipment(new Shipment());
$this->setPickupType(new PickupType());
}

/**
* @return PickupType
*/
public function getPickupType()
public function getPickupType(): PickupType
{
return $this->pickupType;
}

/**
* @param PickupType $pickupType
*
* @return $this
*/
public function setPickupType(PickupType $pickupType)
public function setPickupType(PickupType $pickupType): void
{
$this->PickupType = $pickupType;
$this->pickupType = $pickupType;

return $this;
}

/**
* @return CustomerClassification
*/
public function getCustomerClassification()
public function getCustomerClassification(): ?CustomerClassification
{
return $this->customerClassification;
}

/**
* @param CustomerClassification $customerClassification
*
* @return $this
*/
public function setCustomerClassification(CustomerClassification $customerClassification)
public function setCustomerClassification(CustomerClassification $customerClassification): void
{
$this->customerClassification = $customerClassification;

return $this;
}

/**
* @return Shipment
*/
public function getShipment()
public function getShipment(): Shipment
{
return $this->shipment;
}

/**
* @param Shipment $shipment
*
* @return $this
*/
public function setShipment(Shipment $shipment)
public function setShipment(Shipment $shipment): void
{
$this->Shipment = $shipment;
$this->shipment = $shipment;
}

return $this;
public function getRequest(): Request
{
return $this->request;
}

public function setRequest(Request $request): void
{
$this->request = $request;
}
}
93 changes: 93 additions & 0 deletions src/Entity/RatingServiceSelectionRequest/Request.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php declare(strict_types=1);

namespace Ups\Entity\RatingServiceSelectionRequest;

/**
* Class Request
* For RequestOption Rate is the only valid request option for UPS Ground Freight Pricing requests. But it all depends on the purpose of use.
*
* @param string $requestOption The request option: Rate, Shop, or Ratetimeintransit
* Rate = The server rates (The default Request option is Rate if a Request Option is not provided).
* Shop = The server validates the shipment, and returns rates for all UPS products from the ShipFrom to the ShipTo addresses.
* Ratetimeintransit = The server rates with transit time information
* Shoptimeintransit = The server validates the shipment, and returns rates and transit times for all UPS products from the ShipFrom to the ShipTo addresses.
*
*/
class Request
{
public const REQUEST_OPTION_RATE = 'Rate';
public const REQUEST_OPTION_SHOP = 'Shop';
public const REQUEST_OPTION_RATETIMEINTRANSIT = 'Ratetimeintransit';
public const REQUEST_OPTION_SHOPTIMEINTRANSIT = 'Shoptimeintransit';

private string $transactionReference;
private string $requestAction;
private string $requestOption;

public function __construct(
string $transactionReference = '',
string $requestAction = self::REQUEST_OPTION_RATE,
string $requestOption = self::REQUEST_OPTION_RATE
) {
$this->transactionReference = $transactionReference;
$this->requestAction = $requestAction;
$this->requestOption = $requestOption;
}


/**
* @throws \DOMException
*/
public function toNode(\DOMDocument $document = null): \DOMElement
{
if (null === $document) {
$document = new \DOMDocument();
}

$node = $document->createElement('Request');

if ($this->getTransactionReference()) {
$node->appendChild($document->createElement('TransactionReference', $this->getTransactionReference()));
}

if ($this->getRequestAction()) {
$node->appendChild($document->createElement('RequestAction', $this->getRequestAction()));
}

if ($this->getRequestOption()) {
$node->appendChild($document->createElement('RequestOption', $this->getRequestOption()));
}

return $node;
}

public function getRequestOption(): string
{
return $this->requestOption;
}

public function setRequestOption(string $requestOption): void
{
$this->requestOption = $requestOption;
}

public function getRequestAction(): string
{
return $this->requestAction;
}

public function setRequestAction(string $requestAction): void
{
$this->requestAction = $requestAction;
}

public function getTransactionReference(): string
{
return $this->transactionReference;
}

public function setTransactionReference(string $transactionReference): void
{
$this->transactionReference = $transactionReference;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php declare(strict_types=1);

namespace Ups\Entity\RateRequest\Shipment;

use DOMDocument;
use DOMElement;
use Ups\NodeInterface;

class RateInformation implements NodeInterface
{
private bool $negotiatedRatesIndicator;

private bool $rateChartIndicator;

public function __construct(?object $attributes = null)
{
$this->setNegotiatedRatesIndicator(false);
$this->setRateChartIndicator(false);

if (null !== $attributes) {
if (isset($attributes->NegotiatedRatesIndicator)) {
$this->setNegotiatedRatesIndicator(true);
}
if (isset($attributes->RateChartIndicator)) {
$this->setRateChartIndicator(true);
}
}
}

/**
* @param null|DOMDocument $document
*
* @return DOMElement
* @throws \DOMException
*/
public function toNode(DOMDocument $document = null): DOMElement
{
if (null === $document) {
$document = new DOMDocument();
}

$node = $document->createElement('RateInformation');

if ($this->getNegotiatedRatesIndicator()) {
$node->appendChild($document->createElement('NegotiatedRatesIndicator', 'true'));
}

if ($this->getRateChartIndicator()) {
$node->appendChild($document->createElement('RateChartIndicator'));
}

return $node;
}

public function getNegotiatedRatesIndicator(): bool
{
return $this->negotiatedRatesIndicator;
}

public function setNegotiatedRatesIndicator(bool $value): void
{
$this->negotiatedRatesIndicator = $value;
}

public function getRateChartIndicator(): bool
{
return $this->rateChartIndicator;
}

public function setRateChartIndicator(bool $value): void
{
$this->rateChartIndicator = $value;
}
}
Loading