Skip to content

Commit

Permalink
PDTWO-216: upgrade dependencies; add analyse scripts and config
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian80 committed May 2, 2024
1 parent 0027f52 commit 5f4bcee
Show file tree
Hide file tree
Showing 27 changed files with 106 additions and 242 deletions.
20 changes: 16 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@
}
],
"require": {
"php": "^7.2.0 || ^8.0.0",
"php": "^8.1.0",
"ext-soap": "*",
"psr/log": "^1.1"
"psr/log": "^1.1.0 || ^2.0.0 || ^3.0.0"
},
"require-dev": {
"phpunit/phpunit": "^8.0.0 || ^9.0.0",
"fig/log-test": "^1.1.0",
"phpunit/phpunit": "^9.5.0",
"phpstan/phpstan": "^1.5.0",
"squizlabs/php_codesniffer": "^3.4"
"squizlabs/php_codesniffer": "^3.4",
"rector/rector": "*"
},
"autoload": {
"psr-4": {
Expand All @@ -37,5 +39,15 @@
"psr-4": {
"DeutschePost\\Sdk\\OneClickForRefund\\Test\\": "test/"
}
},
"scripts": {
"test": "phpunit -c test/phpunit.xml",
"phpstan": "phpstan --xdebug analyze src",
"lint": "phpcs --exclude=PSR2.Classes.PropertyDeclaration,Generic.Files.LineLength --standard=PSR12 src test"
},
"extra": {
"branch-alias": {
"dev-PDTWO-216": "1.2.x-dev"
}
}
}
4 changes: 4 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
includes:
parameters:
level: 7
paths:
- src
treatPhpDocTypesAsCertain: false
ignoreErrors:
- '#is never written, only read\.$#'
- '#is never read, only written\.$#'
41 changes: 41 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/**
* See LICENSE file for license details.
*/

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector;
use Rector\DeadCode\Rector\Property\RemoveUselessVarTagRector;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Php81\Rector\Property\ReadOnlyPropertyRector;
use Rector\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedStrictParamTypeRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/src',
__DIR__ . '/test',
]);

$rectorConfig->sets([
LevelSetList::UP_TO_PHP_81,
SetList::CODE_QUALITY,
SetList::EARLY_RETURN,
SetList::TYPE_DECLARATION,
PHPUnitSetList::PHPUNIT_100,
]);
$rectorConfig->rules([
RemoveUselessParamTagRector::class,
RemoveUselessReturnTagRector::class,
RemoveUselessVarTagRector::class,
]);
$rectorConfig->skip([
ReadOnlyPropertyRector::class,
AddMethodCallBasedStrictParamTypeRector::class
]);
};
12 changes: 0 additions & 12 deletions src/Api/Data/CredentialsInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,31 @@ interface CredentialsInterface
{
/**
* Obtain the email address with which the user is registered.
*
* @return string
*/
public function getUsername(): string;

/**
* Obtain the password for the user account.
*
* @return string
*/
public function getPassword(): string;

/**
* Obtain the partner's application ID provided by Deutsche Post.
*
* @return string
*/
public function getPartnerId(): string;

/**
* Obtain the partner's application key (`SCHLUESSEL_DPWN_MEINMARKTPLATZ`) provided by Deutsche Post.
*
* @return string
*/
public function getPartnerKey(): string;

/**
* Obtain the agreed version of the secret.
*
* @return int
*/
public function getKeyPhase(): int;

/**
* Obtain the authorization token provider.
*
* @return TokenStorageInterface
*/
public function getTokenStorage(): TokenStorageInterface;
}
3 changes: 0 additions & 3 deletions src/Api/ServiceFactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ interface ServiceFactoryInterface
/**
* Create the service instance to process voucher cancellation.
*
* @param CredentialsInterface $credentials
* @param LoggerInterface $logger
* @return RefundServiceInterface
* @throws \RuntimeException
*/
public function createRefundService(
Expand Down
2 changes: 0 additions & 2 deletions src/Api/TokenStorageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@
interface TokenStorageInterface
{
/**
* @return string
* @throws AuthenticationStorageException
*/
public function readToken(): string;

/**
* @param string $token Authorization token
* @param int $lifetime Expiry time in seconds
* @return void
* @throws AuthenticationStorageException
*/
public function saveToken(string $token, int $lifetime): void;
Expand Down
56 changes: 6 additions & 50 deletions src/Auth/Credentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,58 +13,14 @@

class Credentials implements CredentialsInterface
{
/**
* @var string
*/
private $username;

/**
* @var string
*/
private $password;

/**
* @var string
*/
private $partnerId;

/**
* @var string
*/
private $partnerKey;

/**
* @var int
*/
private $keyPhase;

/**
* @var TokenStorageInterface
*/
private $tokenStorage;

/**
* @param string $username
* @param string $password
* @param string $partnerId
* @param string $partnerKey
* @param int $keyPhase
* @param TokenStorageInterface $tokenStorage
*/
public function __construct(
string $username,
string $password,
string $partnerId,
string $partnerKey,
int $keyPhase,
TokenStorageInterface $tokenStorage
private string $username,
private string $password,
private string $partnerId,
private string $partnerKey,
private int $keyPhase,
private TokenStorageInterface $tokenStorage
) {
$this->username = $username;
$this->password = $password;
$this->partnerId = $partnerId;
$this->partnerKey = $partnerKey;
$this->keyPhase = $keyPhase;
$this->tokenStorage = $tokenStorage;
}

public function getUsername(): string
Expand Down
21 changes: 5 additions & 16 deletions src/Auth/TokenProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,22 @@

class TokenProvider
{
/**
* @var CredentialsInterface
*/
private $credentials;

/**
* @var AuthenticationService
*/
private $authService;

public function __construct(CredentialsInterface $credentials, AuthenticationService $authService)
{
$this->credentials = $credentials;
$this->authService = $authService;
public function __construct(
private CredentialsInterface $credentials,
private AuthenticationService $authService
) {
}

/**
* Load token from storage if available, from authentication endpoint otherwise.
*
* @return string
* @throws ServiceException
*/
public function getToken(): string
{
try {
$token = $this->credentials->getTokenStorage()->readToken();
} catch (AuthenticationStorageException $exception) {
} catch (AuthenticationStorageException) {
$token = '';
}

Expand Down
7 changes: 2 additions & 5 deletions src/Auth/TokenStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@
*/
class TokenStorage implements TokenStorageInterface
{
/**
* @var string
*/
private $token = '';
private string $token = '';

/**
* @var int Expiry unix timestamp (e.g. now + 3600)
*/
private $expiry = 0;
private int $expiry = 0;

public function readToken(): string
{
Expand Down
3 changes: 0 additions & 3 deletions src/Exception/ServiceExceptionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ class ServiceExceptionFactory
{
/**
* Create a service exception.
*
* @param \Throwable $exception
* @return ServiceException
*/
public static function createServiceException(\Throwable $exception): ServiceException
{
Expand Down
14 changes: 1 addition & 13 deletions src/Model/AuthenticateUserRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,7 @@

class AuthenticateUserRequest
{
/**
* @var string $username
*/
private $username;

/**
* @var string $password
*/
private $password;

public function __construct(string $username, string $password)
public function __construct(private string $username, private string $password)
{
$this->username = $username;
$this->password = $password;
}
}
25 changes: 5 additions & 20 deletions src/Model/CancelVouchersRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,10 @@

class CancelVouchersRequest
{
/**
* @var string $userToken
*/
private $userToken;

/**
* @var string $shopRetoureId
*/
private $shopRetoureId;

/**
* @var ShoppingCart $shoppingCart
*/
private $shoppingCart;

public function __construct(string $userToken, string $shopRetoureId, ShoppingCart $shoppingCart)
{
$this->userToken = $userToken;
$this->shopRetoureId = $shopRetoureId;
$this->shoppingCart = $shoppingCart;
public function __construct(
private string $userToken,
private string $shopRetoureId,
private ShoppingCart $shoppingCart
) {
}
}
3 changes: 0 additions & 3 deletions src/Model/CreateRetoureIdResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ class CreateRetoureIdResponse
*/
private $shopRetoureId;

/**
* @return string
*/
public function getShopRetoureId(): string
{
return $this->shopRetoureId;
Expand Down
13 changes: 2 additions & 11 deletions src/Model/RequestType/ShoppingCart.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,10 @@

class ShoppingCart
{
/**
* @var string $shopOrderId
*/
private $shopOrderId;
private ?VoucherSet $voucherSet = null;

/**
* @var VoucherSet $voucherSet
*/
private $voucherSet;

public function __construct(string $shopOrderId)
public function __construct(private string $shopOrderId)
{
$this->shopOrderId = $shopOrderId;
}

public function setVoucherSet(VoucherSet $voucherSet): void
Expand Down
8 changes: 1 addition & 7 deletions src/Model/RequestType/VoucherSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,10 @@

class VoucherSet
{
/**
* @var string[] $voucherNo
*/
private $voucherNo;

/**
* @param string[] $voucherNo
*/
public function __construct(array $voucherNo)
public function __construct(private array $voucherNo)
{
$this->voucherNo = $voucherNo;
}
}
Loading

0 comments on commit 5f4bcee

Please sign in to comment.