Skip to content

Commit

Permalink
Merge pull request #67 from academe/misc-fixes
Browse files Browse the repository at this point in the history
Misc fixes
  • Loading branch information
judgej authored Sep 20, 2023
2 parents 6027cfb + 5e4083f commit 7d2720f
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 19 deletions.
7 changes: 4 additions & 3 deletions src/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
* Contains base methods that all messages will use.
*/

use Closure;
use DateTime;
use Exception;
use DateTimeZone;

use UnexpectedValueException;
use Psr\Http\Message\MessageInterface;
use Psr\Http\Message\ServerRequestInterface;

use DateTime;
use DateTimeZone;

abstract class Helper
{
// SagePay date format, ISO 8601 with microseconds.
Expand Down
3 changes: 2 additions & 1 deletion src/Request/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Academe\SagePay\Psr7\Factory\FactoryInterface;
use Academe\SagePay\Psr7\Factory\DiactorosFactory;
use Academe\SagePay\Psr7\Factory\GuzzleFactory;
use Academe\SagePay\Psr7\Factory\RequestFactoryInterface;
use UnexpectedValueException;
use JsonSerializable;
use Exception;
Expand Down Expand Up @@ -179,7 +180,7 @@ protected function setFactory(RequestFactoryInterface $factory)
protected function withFactory(RequestFactoryInterface $factory)
{
$clone = clone $this;
return $clone->setAuth($factory);
return $clone->setFactory($factory);
}

/**
Expand Down
12 changes: 6 additions & 6 deletions src/Request/CreatePayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use Academe\SagePay\Psr7\Model\Auth;
use Academe\SagePay\Psr7\PaymentMethod\PaymentMethodInterface;
use Academe\SagePay\Psr7\Money\AmountInterface;
use Academe\SagePay\Psr7\Request\Model\AddressInterface;
use Academe\SagePay\Psr7\Request\Model\PersonInterface;

class CreatePayment extends AbstractRequest
{
Expand Down Expand Up @@ -263,21 +265,19 @@ public static function getApply3DSecures()
}

/**
* @param ShippingAddress $shippingAddress
* @return Transaction
* @return self clone
*/
public function withShippingAddress(ShippingAddress $shippingAddress)
public function withShippingAddress(AddressInterface $shippingAddress)
{
$copy = clone $this;
$copy->shippingAddress = $shippingAddress;
return $copy;
}

/**
* @param ShippingRecipient $shippingRecipient
* @return Transaction
* @return self clone
*/
public function withShippingRecipient(ShippingRecipient $shippingRecipient)
public function withShippingRecipient(PersonInterface $shippingRecipient)
{
$copy = clone $this;
$copy->shippingRecipient = $shippingRecipient;
Expand Down
8 changes: 5 additions & 3 deletions src/Request/CreateRepeatPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
use Academe\SagePay\Psr7\Model\Endpoint;
use Academe\SagePay\Psr7\Model\Auth;
use Academe\SagePay\Psr7\Money\AmountInterface;
use Academe\SagePay\Psr7\Model\AddressInterface;
use Academe\SagePay\Psr7\Model\PersonInterface;
use Academe\SagePay\Psr7\Request\Model\AddressInterface;
use Academe\SagePay\Psr7\Request\Model\PersonInterface as ModelPersonInterface;

class CreateRepeatPayment extends AbstractRequest
{
Expand All @@ -29,6 +30,7 @@ class CreateRepeatPayment extends AbstractRequest
// Optional or overridable data.
protected $shippingAddress;
protected $shippingRecipient;
protected $giftAid;

/**
* @var string The prefix is added to the name fields when sending to Sage Pay
Expand Down Expand Up @@ -87,7 +89,7 @@ public function __construct(
* @param ShippingAddress $shippingAddress
* @return Transaction
*/
public function withShippingAddress(ShippingAddress $shippingAddress)
public function withShippingAddress(AddressInterface $shippingAddress)
{
$copy = clone $this;
$copy->shippingAddress = $shippingAddress;
Expand All @@ -98,7 +100,7 @@ public function withShippingAddress(ShippingAddress $shippingAddress)
* @param ShippingRecipient $shippingRecipient
* @return Repeat
*/
public function withShippingRecipient(ShippingRecipient $shippingRecipient)
public function withShippingRecipient(ModelPersonInterface $shippingRecipient)
{
$copy = clone $this;
$copy->shippingRecipient = $shippingRecipient;
Expand Down
1 change: 1 addition & 0 deletions src/Request/FetchInstructions.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ class FetchInstructions extends AbstractInstruction
#[\ReturnTypeWillChange]
public function jsonSerialize()
{
return [];
}
}
6 changes: 5 additions & 1 deletion src/Response/AbstractCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace Academe\SagePay\Psr7\Response;

use ArrayIterator;
use IteratorAggregate;

/**
* A a collection of instructions.
*/

abstract class AbstractCollection extends AbstractResponse implements \IteratorAggregate
abstract class AbstractCollection extends AbstractResponse implements IteratorAggregate
{
/**
* The list of items.
Expand All @@ -22,6 +25,7 @@ abstract class AbstractCollection extends AbstractResponse implements \IteratorA
/**
* @return ArrayIterator
*/
#[\ReturnTypeWillChange]
public function getIterator()
{
return new ArrayIterator($this->items);
Expand Down
2 changes: 2 additions & 0 deletions src/Response/AbstractResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ abstract class AbstractResponse extends AbstractMessage implements Http, RFC4918
*/
protected $httpCode;

protected $status;

/**
* Can initialise with a PSR7 message, an array, a value object or a JSON string.
*
Expand Down
5 changes: 2 additions & 3 deletions src/Response/InstructionCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ class InstructionCollection extends AbstractCollection
*/
protected $permittedClass = AbstractInstruction::class;

/**
*
*/
public function setData($data, $httpCode = null)
{
if ($httpCode) {
Expand All @@ -37,6 +34,8 @@ public function setData($data, $httpCode = null)
$this->add(ResponseFactory::fromData($instruction, $httpCode));
}
}

return $this;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/Response/NoContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
class NoContent extends AbstractResponse
{
/**
* No data to set (this is an empty messgae body).
* No data to set (this is an empty message body).
* @inheritDoc
*/
public function setData($data)
{
return $this;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Response/SessionKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function isValid()
}

// Do we have a 404 HTTP response code recorded?
if ($this->getHttpCode() !== null && $this->getHttpCode() === $this::NOT_FOUND) {
if ($this->getHttpCode() !== null && $this->getHttpCode() === static::NOT_FOUND) {
return false;
}

Expand Down

0 comments on commit 7d2720f

Please sign in to comment.