Ingenico-ePayments / connect-sdk-php

Ingenico Connect PHP Server SDK
https://docs.connect.worldline-solutions.com/documentation/sdk/server/php/
MIT License
39 stars 16 forks source link

Solve unequal declaration of interface and class #5

Closed unreal4u closed 6 years ago

unreal4u commented 7 years ago

When testing in strict mode in PHP 7.1.10 and enabling logging as per the documentation, a fatal error occurs when injecting a Logger.

Given the following code:

$communicatorConfiguration = new CommunicatorConfiguration(
    'xxxxxxx',
    'xxxxxxx=',
    'xxxxxxx',
    'xxxxxxx'
);
$connection = new DefaultConnection();
$communicator = new Communicator($connection, $communicatorConfiguration);

$client = new Client($communicator);
$client->enableLogging($logger);

$hostedCheckoutSpecificInput = new HostedCheckoutSpecificInput();
$hostedCheckoutSpecificInput->locale = "en_GB";
$hostedCheckoutSpecificInput->variant = "testVariant";

$amountOfMoney = new AmountOfMoney();
$amountOfMoney->amount = 2345;
$amountOfMoney->currencyCode = "USD";

$billingAddress = new Address();
$billingAddress->countryCode = "US";

$customer = new Customer();
$customer->billingAddress = $billingAddress;

$order = new Order();
$order->amountOfMoney = $amountOfMoney;
$order->customer = $customer;

$body = new CreateHostedCheckoutRequest();
$body->hostedCheckoutSpecificInput = $hostedCheckoutSpecificInput;
$body->order = $order;

$response = $client->merchant('xxxxxxx')->hostedcheckouts()->create($body);

It will throw the following error:

PHP Fatal error:  Declaration of Ingenico\Connect\Sdk\ResourceLogger::logException($message, Ingenico\Connect\Sdk\Exception $exception) must be compatible with Ingenico\Connect\Sdk\CommunicatorLogger::logException($message, Exception $exception) in /var/www/html/vendor/ingenico-epayments/connect-sdk-php/lib/Ingenico/Connect/Sdk/ResourceLogger.php on line 11
PHP Stack trace:
PHP   1. {main}() /var/www/html/examples/GenerateIngenicoPayment.php:0
PHP   2. spl_autoload_call() /var/www/html/examples/GenerateIngenicoPayment.php:19
PHP   3. Composer\Autoload\ClassLoader->loadClass() /var/www/html/examples/GenerateIngenicoPayment.php:19
PHP   4. Composer\Autoload\includeFile() /var/www/html/vendor/composer/ClassLoader.php:322
PHP   5. include() /var/www/html/vendor/composer/ClassLoader.php:444

This commit fixes the issue.

rob-spoor commented 7 years ago

SplFileObjectLogger has the same error. We will get this fixed in the next release. We will use a slightly different solution though, by putting a use Exception; at the top.

unreal4u commented 7 years ago

Great catch, I didn't look at other places 👍

rob-spoor commented 7 years ago

I've found another missing use clause in SplFileObjectLogger. That too will be fixed, with unit tests in place to ensure it actually works.

rob-spoor commented 6 years ago

Version 5.11.1 has just been released which fixes this issue in both logger implementations.

ebomcke-ingenico commented 6 years ago

Closing this request as the issue has been fixed in a different way in the latest release.