Skip to content

Commit

Permalink
feat: WIP drop support of php < 8, update phpunit 5/8 => 9
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris8934 authored and pierredup committed May 4, 2022
1 parent 03906aa commit a71432c
Show file tree
Hide file tree
Showing 132 changed files with 869 additions and 2,287 deletions.
13 changes: 3 additions & 10 deletions src/Payum/Core/Action/ActionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,9 @@
interface ActionInterface
{
/**
* @param mixed $request
*
* @throws \Payum\Core\Exception\RequestNotSupportedException if the action dose not support the request.
* @throws \Payum\Core\Exception\RequestNotSupportedException if the action does not support the request.
*/
public function execute($request);
public function execute(mixed $request): void;

/**
* @param mixed $request
*
* @return boolean
*/
public function supports($request);
public function supports(mixed $request): bool;
}
4 changes: 2 additions & 2 deletions src/Payum/Core/Action/AuthorizePaymentAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AuthorizePaymentAction implements ActionInterface, GatewayAwareInterface
*
* @param Authorize $request
*/
public function execute($request)
public function execute($request): void
{
RequestNotSupportedException::assertSupports($this, $request);

Expand All @@ -46,7 +46,7 @@ public function execute($request)
/**
* {@inheritDoc}
*/
public function supports($request)
public function supports($request): bool
{
return
$request instanceof Authorize &&
Expand Down
5 changes: 2 additions & 3 deletions src/Payum/Core/Action/CapturePaymentAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ class CapturePaymentAction implements ActionInterface, GatewayAwareInterface

/**
* {@inheritDoc}
*
* @param Capture $request
*/
public function execute($request)
public function execute($request): void
{
RequestNotSupportedException::assertSupports($this, $request);

Expand All @@ -46,7 +45,7 @@ public function execute($request)
/**
* {@inheritDoc}
*/
public function supports($request)
public function supports($request): bool
{
return
$request instanceof Capture &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ExecuteSameRequestWithModelDetailsAction implements ActionInterface, Gatew
*
* @param ModelAggregateInterface|ModelAwareInterface $request
*/
public function execute($request)
public function execute($request): void
{
RequestNotSupportedException::assertSupports($this, $request);

Expand All @@ -44,7 +44,7 @@ public function execute($request)
/**
* {@inheritDoc}
*/
public function supports($request)
public function supports($request): bool
{
return
$request instanceof ModelAggregateInterface &&
Expand Down
11 changes: 4 additions & 7 deletions src/Payum/Core/Action/GetCurrencyAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@ class GetCurrencyAction implements ActionInterface
* @var ISO4217
* @deprecated The iso4217 property is deprecated and will be removed in v2
*/
protected $iso4217;
protected mixed $iso4217;

private $usePayumIso4217 = false;
private bool $usePayumIso4217 = false;

/**
* @param ISO4217 $iso4217
*/
public function __construct(ISO4217 $iso4217 = null)
{
if ($iso4217 instanceof ISO4217) {
Expand All @@ -34,7 +31,7 @@ public function __construct(ISO4217 $iso4217 = null)
*
* @param GetCurrency $request
*/
public function execute($request)
public function execute($request): void
{
RequestNotSupportedException::assertSupports($this, $request);

Expand All @@ -61,7 +58,7 @@ public function execute($request)
/**
* {@inheritDoc}
*/
public function supports($request)
public function supports($request): bool
{
return
$request instanceof GetCurrency &&
Expand Down
18 changes: 4 additions & 14 deletions src/Payum/Core/Action/GetTokenAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,15 @@

class GetTokenAction implements ActionInterface
{
/**
* @var StorageInterface
*/
private $tokenStorage;

/**
* @param StorageInterface $tokenStorage
*/
public function __construct(StorageInterface $tokenStorage)
{
$this->tokenStorage = $tokenStorage;
}
public function __construct(private StorageInterface $tokenStorage)
{}

/**
* {@inheritDoc}
*
* @param $request GetToken
*/
public function execute($request)
public function execute($request): void
{
RequestNotSupportedException::assertSupports($this, $request);

Expand All @@ -40,7 +30,7 @@ public function execute($request)
/**
* {@inheritDoc}
*/
public function supports($request)
public function supports($request): bool
{
return $request instanceof GetToken;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Payum/Core/Action/PayoutPayoutAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class PayoutPayoutAction implements ActionInterface, GatewayAwareInterface
*
* @param Payout $request
*/
public function execute($request)
public function execute($request): void
{
RequestNotSupportedException::assertSupports($this, $request);

Expand All @@ -46,7 +46,7 @@ public function execute($request)
/**
* {@inheritDoc}
*/
public function supports($request)
public function supports($request): bool
{
return
$request instanceof Payout &&
Expand Down
4 changes: 1 addition & 3 deletions src/Payum/Core/ApiAwareInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
interface ApiAwareInterface
{
/**
* @param mixed $api
*
* @throws UnsupportedApiException if the given Api is not supported.
*/
public function setApi($api);
public function setApi(mixed $api);
}
12 changes: 3 additions & 9 deletions src/Payum/Core/ApiAwareTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,14 @@

trait ApiAwareTrait
{
/**
* @var mixed
*/
protected $api;
protected mixed $api;

/**
* @var string
*/
protected $apiClass;
protected string $apiClass;

/**
* {@inheritDoc}
*/
public function setApi($api)
public function setApi($api): void
{
if (empty($this->apiClass)) {
throw new LogicException(sprintf('You must configure apiClass in __constructor method of the class the trait is applied to.'));
Expand Down
12 changes: 3 additions & 9 deletions src/Payum/Core/Bridge/Defuse/Security/DefuseCypher.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,8 @@

class DefuseCypher implements CypherInterface
{
/**
* @var string
*/
private $key;
private string|Key $key;

/**
* {@inheritdoc}
*/
public function __construct($secret)
{
$this->key = Key::loadFromAsciiSafeString($secret);
Expand All @@ -23,15 +17,15 @@ public function __construct($secret)
/**
* {@inheritdoc}
*/
public function decrypt($value)
public function decrypt($value): string
{
return Crypto::decrypt($value, $this->key);
}

/**
* {@inheritdoc}
*/
public function encrypt($value)
public function encrypt($value): string
{
return Crypto::encrypt($value, $this->key);
}
Expand Down
22 changes: 6 additions & 16 deletions src/Payum/Core/Bridge/Doctrine/Storage/DoctrineStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,19 @@
use Doctrine\Persistence\ObjectManager;
use Payum\Core\Model\Identity;
use Payum\Core\Storage\AbstractStorage;
use Payum\Core\Storage\IdentityInterface;

class DoctrineStorage extends AbstractStorage
{
/**
* @var \Doctrine\Persistence\ObjectManager
*/
protected $objectManager;

/**
* @param \Doctrine\Persistence\ObjectManager $objectManager
* @param string $modelClass
*/
public function __construct(ObjectManager $objectManager, $modelClass)
public function __construct(protected ObjectManager $objectManager, string $modelClass)
{
parent::__construct($modelClass);

$this->objectManager = $objectManager;
}

/**
* {@inheritDoc}
*/
public function findBy(array $criteria)
public function findBy(array $criteria): array
{
return $this->objectManager->getRepository($this->modelClass)->findBy($criteria);
}
Expand All @@ -42,7 +32,7 @@ protected function doFind($id)
/**
* {@inheritDoc}
*/
protected function doUpdateModel($model)
protected function doUpdateModel($model): void
{
$this->objectManager->persist($model);
$this->objectManager->flush();
Expand All @@ -51,7 +41,7 @@ protected function doUpdateModel($model)
/**
* {@inheritDoc}
*/
protected function doDeleteModel($model)
protected function doDeleteModel($model): void
{
$this->objectManager->remove($model);
$this->objectManager->flush();
Expand All @@ -60,7 +50,7 @@ protected function doDeleteModel($model)
/**
* {@inheritDoc}
*/
protected function doGetIdentity($model)
protected function doGetIdentity($model): IdentityInterface
{
$modelMetadata = $this->objectManager->getClassMetadata(get_class($model));
$id = $modelMetadata->getIdentifierValues($model);
Expand Down
2 changes: 1 addition & 1 deletion src/Payum/Core/Bridge/Doctrine/Types/ObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ObjectType extends Type
/**
* {@inheritDoc}
*/
public function convertToDatabaseValue($value)
public function convertToDatabaseValue($value): string
{
return serialize($value);
}
Expand Down
17 changes: 4 additions & 13 deletions src/Payum/Core/Bridge/Guzzle/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use GuzzleHttp\ClientInterface;
use Payum\Core\HttpClientInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

/**
* This is a HttpClient that is using Guzzle.
Expand All @@ -12,23 +13,13 @@
*/
class HttpClient implements HttpClientInterface
{
/**
* @var ClientInterface
*/
private $client;

/**
* @param ClientInterface $client
*/
public function __construct(ClientInterface $client)
{
$this->client = $client;
}
public function __construct(private ClientInterface $client)
{}

/**
* {@inheritDoc}
*/
public function send(RequestInterface $request)
public function send(RequestInterface $request): ResponseInterface
{
return $this->client->send($request);
}
Expand Down
13 changes: 4 additions & 9 deletions src/Payum/Core/Bridge/Guzzle/HttpClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ class HttpClientFactory
{
/**
* Create a Guzzle client.
*
* @return \GuzzleHttp\Client
*/
public static function createGuzzle()
public static function createGuzzle(): Client
{
$client = null;
if (!class_exists(Client::class)) {
Expand All @@ -25,25 +23,22 @@ public static function createGuzzle()
}

$version = \GuzzleHttp\ClientInterface::VERSION;
if (substr($version, 0, 1) !== '6') {
if ($version[0] !== '6') {
throw new \LogicException('This version of Guzzle is not supported.');
}

$curl = curl_version();

$curlOptions = [
CURLOPT_USERAGENT => sprintf('Payum/1.x curl/%s PHP/%s', $curl['version'], phpversion()),
CURLOPT_USERAGENT => sprintf('Payum/1.x curl/%s PHP/%s', $curl['version'], PHP_VERSION),
];

return new \GuzzleHttp\Client([
'curl' => $curlOptions,
]);
}

/**
* @return HttpClientInterface
*/
public static function create()
public static function create(): HttpClientInterface
{
return new HttpClient(static::createGuzzle());
}
Expand Down

0 comments on commit a71432c

Please sign in to comment.