Skip to content

Commit

Permalink
Merge pull request #43 from andrew-svirin/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Andrew Svirin authored Jun 17, 2020
2 parents 2e34c36 + 650bf8c commit 5d89270
Show file tree
Hide file tree
Showing 27 changed files with 218 additions and 160 deletions.
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ php:
- '7.3'
- '7.4'

branches:
only:
- master

cache:
directories:
- vendor
- tests/_data

before_script:
- composer update --dev --no-interaction
- composer update --dev --no-interaction

script:
- vendor/bin/phpstan analyse
- vendor/bin/phpunit
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,9 @@ try {
```

### 5. Play with other transactions!

# Involving in development
First of all - thanks for involving on development.
If you have any idea how to improve the library, this will be welcome.
!!! For example library require in Mocker for server responses. That will
locally simulate from responses on client requests by reading static files.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"symfony/http-client": "^4.3||^5.0"
},
"require-dev": {
"phpstan/phpstan": "^0.12.29",
"phpunit/phpunit": "^8.5"
},
"autoload": {
Expand Down
6 changes: 6 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
level: 7
paths:
- src
2 changes: 1 addition & 1 deletion src/Contracts/EbicsResponseExceptionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @author Guillaume Sainthillier
*/
interface EbicsResponseExceptionInterface
interface EbicsResponseExceptionInterface extends \Throwable
{
/**
* Returns the EBICS error code
Expand Down
4 changes: 1 addition & 3 deletions src/Contracts/KeyRingManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ interface KeyRingManagerInterface
{
/**
* Load Keyring from the saved file or create new one.
*
* @return KeyRing
*/
public function loadKeyRing(): KeyRing;

/**
* Save KeyRing to file.
*/
public function saveKeyRing(KeyRing $keyRing);
public function saveKeyRing(KeyRing $keyRing) : void;
}
20 changes: 10 additions & 10 deletions src/EbicsClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function HEV(): Response
public function INI(DateTime $dateTime = null): Response
{
if (null === $dateTime) {
$dateTime = DateTime::createFromFormat('U', time());
$dateTime = new DateTime();
}
$certificateA = CertificateFactory::generateCertificateAFromKeys(CryptService::generateKeys($this->keyRing), $this->bank->isCertified());
$request = $this->requestFactory->buildINI($certificateA, $dateTime);
Expand All @@ -158,7 +158,7 @@ public function INI(DateTime $dateTime = null): Response
public function HIA(DateTime $dateTime = null): Response
{
if (null === $dateTime) {
$dateTime = DateTime::createFromFormat('U', time());
$dateTime = new DateTime();
}
$certificateE = CertificateFactory::generateCertificateEFromKeys(CryptService::generateKeys($this->keyRing), $this->bank->isCertified());
$certificateX = CertificateFactory::generateCertificateXFromKeys(CryptService::generateKeys($this->keyRing), $this->bank->isCertified());
Expand Down Expand Up @@ -187,7 +187,7 @@ public function HIA(DateTime $dateTime = null): Response
public function HPB(DateTime $dateTime = null): Response
{
if (null === $dateTime) {
$dateTime = DateTime::createFromFormat('U', time());
$dateTime = new DateTime();
}
$request = $this->requestFactory->buildHPB($dateTime);
$hostResponse = $this->post($request);
Expand Down Expand Up @@ -220,7 +220,7 @@ public function HPB(DateTime $dateTime = null): Response
public function HPD(DateTime $dateTime = null): Response
{
if (null === $dateTime) {
$dateTime = DateTime::createFromFormat('U', time());
$dateTime = new DateTime();
}
$request = $this->requestFactory->buildHPD($dateTime);
$hostResponse = $this->post($request);
Expand Down Expand Up @@ -252,7 +252,7 @@ public function HPD(DateTime $dateTime = null): Response
public function HKD(DateTime $dateTime = null): Response
{
if (null === $dateTime) {
$dateTime = DateTime::createFromFormat('U', time());
$dateTime = new DateTime();
}
$request = $this->requestFactory->buildHKD($dateTime);
$hostResponse = $this->post($request);
Expand Down Expand Up @@ -284,7 +284,7 @@ public function HKD(DateTime $dateTime = null): Response
public function HTD(DateTime $dateTime = null): Response
{
if (null === $dateTime) {
$dateTime = DateTime::createFromFormat('U', time());
$dateTime = new DateTime();
}

$request = $this->requestFactory->buildHTD($dateTime);
Expand Down Expand Up @@ -319,7 +319,7 @@ public function HTD(DateTime $dateTime = null): Response
public function FDL(string $fileInfo, string $format = 'plain', string $countryCode = 'FR', DateTime $dateTime = null, DateTime $startDateTime = null, DateTime $endDateTime = null): Response
{
if (null === $dateTime) {
$dateTime = DateTime::createFromFormat('U', time());
$dateTime = new DateTime();
}

$request = $this->requestFactory->buildFDL($dateTime, $fileInfo, $countryCode, $startDateTime, $endDateTime);
Expand Down Expand Up @@ -385,7 +385,7 @@ public function transferReceipt(Response $response, bool $acknowledged = true) :
public function HAA(DateTime $dateTime = null): Response
{
if (null === $dateTime) {
$dateTime = DateTime::createFromFormat('U', time());
$dateTime = new DateTime();
}
$request = $this->requestFactory->buildHAA($dateTime);
$hostResponse = $this->post($request);
Expand All @@ -410,7 +410,7 @@ public function HAA(DateTime $dateTime = null): Response
public function VMK(DateTime $dateTime = null, DateTime $startDateTime = null, DateTime $endDateTime = null): Response
{
if (null === $dateTime) {
$dateTime = DateTime::createFromFormat('U', time());
$dateTime = new DateTime();
}
$request = $this->requestFactory->buildVMK($dateTime, $startDateTime, $endDateTime);
$hostResponse = $this->post($request);
Expand All @@ -435,7 +435,7 @@ public function VMK(DateTime $dateTime = null, DateTime $startDateTime = null, D
public function STA(DateTime $dateTime = null, DateTime $startDateTime = null, DateTime $endDateTime = null): Response
{
if (null === $dateTime) {
$dateTime = DateTime::createFromFormat('U', time());
$dateTime = new DateTime();
}
$request = $this->requestFactory->buildSTA($dateTime, $startDateTime, $endDateTime);
$hostResponse = $this->post($request);
Expand Down
3 changes: 3 additions & 0 deletions src/Exceptions/EbicsErrorCodeMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
*/
abstract class EbicsErrorCodeMapping
{
/**
* @var string[]
*/
public static $mapping = [
'011000' => DownloadPostprocessDoneException::class,
'011001' => DownloadPostprocessSkippedException::class,
Expand Down
8 changes: 5 additions & 3 deletions src/Exceptions/EbicsResponseException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,20 @@ class EbicsResponseException extends EbicsException implements EbicsResponseExce
/** @var string */
private $responseCode;

/** @var Request */
/** @var Request|null */
private $request;

/** @var Response */
/** @var Response|null */
private $response;

/** @var string|null */
private $meaning;

public function __construct(string $responseCode, ?string $responseMessage, ?string $meaning = null)
{
parent::__construct($responseMessage ?: $meaning, (int) $responseCode);
$message = $responseMessage ?: $meaning;

parent::__construct((string) $message, (int) $responseCode);

$this->responseCode = $responseCode;
$this->meaning = $meaning;
Expand Down
4 changes: 2 additions & 2 deletions src/Factories/KeyRingFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ public static function buildDataFromKeyRing(KeyRing $keyRing): array
];
}

private static function encodeValue($value)
private static function encodeValue(string $value) : string
{
return base64_encode($value);
}

private static function decodeValue($value)
private static function decodeValue(string $value) : string
{
return base64_decode($value);
}
Expand Down
6 changes: 2 additions & 4 deletions src/Factories/X509/AbstractX509Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function generateX509(RSA $privateKey, RSA $publicKey, array $options = [
return $x509->saveX509($result);
}

protected function generateSubject(RSA $publicKey, $options): X509
protected function generateSubject(RSA $publicKey, array $options): X509
{
$subject = new X509();
$subject->setPublicKey($publicKey); // $pubKey is Crypt_RSA object
Expand Down Expand Up @@ -117,8 +117,6 @@ protected function generateIssuer(RSA $privateKey, RSA $publicKey, X509 $subject

/**
* Generate 74 digits serial number represented in the string.
*
* @return string
*/
protected function generateSerialNumber(): string
{
Expand All @@ -128,7 +126,7 @@ protected function generateSerialNumber(): string
$result .= rand(0, 9);
}

return $result;
return (string) $result;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Factories/X509/X509GeneratorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ class X509GeneratorFactory
/** @var callable|null */
private static $generatorFunction;

public static function setGeneratorFunction(callable $generatorFunction)
public static function setGeneratorFunction(callable $generatorFunction) : void
{
self::$generatorFunction = $generatorFunction;
}

public static function setGeneratorClass(string $generatorClass)
public static function setGeneratorClass(string $generatorClass) : void
{
if (!is_a($generatorClass, X509GeneratorInterface::class, true)) {
throw new \RuntimeException(sprintf('The class "%s" must implements %s', $generatorClass, X509GeneratorInterface::class));
Expand Down
2 changes: 1 addition & 1 deletion src/Handlers/AuthSignatureHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct(KeyRing $keyRing)
*
* @throws EbicsException
*/
public function handle(DOMDocument $xml, DOMNode $xmlRequest)
public function handle(DOMDocument $xml, DOMNode $xmlRequest) : void
{
$canonicalizationPath = '//AuthSignature/*';
$signaturePath = "//*[@authenticate='true']";
Expand Down
16 changes: 9 additions & 7 deletions src/Handlers/BodyHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace AndrewSvirin\Ebics\Handlers;

use AndrewSvirin\Ebics\Exceptions\EbicsException;
use DOMDocument;
use DOMElement;

Expand Down Expand Up @@ -31,10 +32,8 @@ public function __construct()

/**
* Add body and children elements to request.
*
* @param string $orderData
*/
public function handle(DOMDocument $xml, DOMElement $xmlRequest, $orderData)
public function handle(DOMDocument $xml, DOMElement $xmlRequest, string $orderData): void
{
// Add body to request.
$xmlBody = $xml->createElement('body');
Expand All @@ -47,7 +46,10 @@ public function handle(DOMDocument $xml, DOMElement $xmlRequest, $orderData)
// Add OrderData to DataTransfer.
$xmlOrderData = $xml->createElement('OrderData');
if ($this->compress) {
$orderData = gzcompress($orderData);
// Try to compress to gz order data.
if (!($orderData = gzcompress($orderData))) {
throw new EbicsException('Order Data were compressed wrongly.');
}
}
if ($this->encode) {
$orderData = base64_encode($orderData);
Expand All @@ -59,7 +61,7 @@ public function handle(DOMDocument $xml, DOMElement $xmlRequest, $orderData)
/**
* Add body and children elements to transfer request.
*/
public function handleTransferReceipt(DOMDocument $xml, DOMElement $xmlRequest, int $receiptCode)
public function handleTransferReceipt(DOMDocument $xml, DOMElement $xmlRequest, int $receiptCode): void
{
// Add body to request.
$xmlBody = $xml->createElement('body');
Expand All @@ -72,14 +74,14 @@ public function handleTransferReceipt(DOMDocument $xml, DOMElement $xmlRequest,

// Add ReceiptCode to TransferReceipt.
$xmlReceiptCode = $xml->createElement('ReceiptCode');
$xmlReceiptCode->nodeValue = $receiptCode;
$xmlReceiptCode->nodeValue = (string)$receiptCode;
$xmlTransferReceipt->appendChild($xmlReceiptCode);
}

/**
* Add empty body element to request.
*/
public function handleEmpty(DOMDocument $xml, DOMElement $xmlRequest)
public function handleEmpty(DOMDocument $xml, DOMElement $xmlRequest): void
{
// Add body to request.
$xmlBody = $xml->createElement('body');
Expand Down
Loading

0 comments on commit 5d89270

Please sign in to comment.