Swedbank-SPP / swedbank-payment-portal

Swedbank Payment Portal API library for PHP
Other
36 stars 21 forks source link

An exception is thrown in TransactionRepository::__construct() if $dir parameter is NULL #5

Closed maijs closed 7 years ago

maijs commented 7 years ago

This fixes a bug in \SwedbankPaymentPortal\Transaction\TransactionRepository::__construct() where check against the type of $dir parameter will never catch NULL value and will always switch to default case which throws an exception.

switch (true) {
  case is_string($dir):
  case null: // <- This case will never trigger.
    $this->fileCache = new FilesystemCache($dir ? $dir : sys_get_temp_dir() . '/banklink');
    break;
  default:
    throw new \RuntimeException(
      "`dir` parameter must be a string or an object which implements Cache interface"
    );
}

The solution is to check for null type and go from there.

switch (true) {
  case is_string($dir):
  case is_null($dir):
    // ...

This bug breaks backwards compatibility as implementations that don't use custom cache cease to work:

RuntimeException: dir parameter must be a string or an object which implements Cache interface in SwedbankPaymentPortal\Transaction\TransactionRepository->__construct() (line 56 of /var/www/[snip]/vendor/swedbank-spp/swedbank-payment-portal/src/Transaction/TransactionRepository.php).