From 0d76b986d94f4725bad76b022255c0a470d6b2e7 Mon Sep 17 00:00:00 2001 From: Petr Soukup Date: Tue, 22 Nov 2016 13:50:59 +0100 Subject: [PATCH 01/22] official composer CA bundle support --- composer.json | 3 ++- src/FioApi/Downloader.php | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 13a9abd..e8ea016 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,8 @@ "satooshi/php-coveralls": "^1.0" }, "suggest": { - "kdyby/curl-ca-bundle": "Provides regularly updated root certificates list" + "kdyby/curl-ca-bundle": "Provides regularly updated root certificates list", + "composer/ca-bundle": "Provides regularly updated root certificates list" }, "autoload": { "psr-4": { diff --git a/src/FioApi/Downloader.php b/src/FioApi/Downloader.php index 98aa931..42a5d20 100644 --- a/src/FioApi/Downloader.php +++ b/src/FioApi/Downloader.php @@ -39,7 +39,9 @@ public function getCertificatePath() return $this->certificatePath; } - if (class_exists('\Kdyby\CurlCaBundle\CertificateHelper')) { + if (class_exists('\Composer\CaBundle\CaBundle')) { + return \Composer\CaBundle\CaBundle::getSystemCaRootBundlePath(); + } elseif (class_exists('\Kdyby\CurlCaBundle\CertificateHelper')) { return \Kdyby\CurlCaBundle\CertificateHelper::getCaInfoFile(); } From f7e5b35ad16aa9508d7d55c169f0bd5b2acff231 Mon Sep 17 00:00:00 2001 From: Petr Soukup Date: Tue, 22 Nov 2016 15:13:56 +0100 Subject: [PATCH 02/22] remove suggestion for abandoned package --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index e8ea016..a392830 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,6 @@ "satooshi/php-coveralls": "^1.0" }, "suggest": { - "kdyby/curl-ca-bundle": "Provides regularly updated root certificates list", "composer/ca-bundle": "Provides regularly updated root certificates list" }, "autoload": { From 45d7d0ebd6dd1c81b1318594bc710bf27461155d Mon Sep 17 00:00:00 2001 From: Martin Hujer Date: Thu, 24 Nov 2016 14:43:27 +0100 Subject: [PATCH 03/22] appveyor PHP binary --- appveyor.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index d664949..7a5ac69 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -17,8 +17,8 @@ init: install: - IF EXIST c:\php (SET PHP=0) ELSE (mkdir c:\php) - IF %PHP%==1 cd c:\php - - IF %PHP%==1 appveyor DownloadFile http://windows.php.net/downloads/releases/php-5.6.16-Win32-VC11-x86.zip - - IF %PHP%==1 7z x php-5.6.16-Win32-VC11-x86.zip -y >nul + - IF %PHP%==1 appveyor DownloadFile http://windows.php.net/downloads/releases/php-7.0.13-Win32-VC14-x86.zip + - IF %PHP%==1 7z x php-7.0.13-Win32-VC14-x86.zip -y >nul - IF %PHP%==1 copy /Y php.ini-development php.ini - IF %PHP%==1 echo max_execution_time=1200 >> php.ini - IF %PHP%==1 echo date.timezone="UTC" >> php.ini From 42812ec6a9d4ec87a820c092328bb18216f0cfd2 Mon Sep 17 00:00:00 2001 From: Martin Hujer Date: Thu, 24 Nov 2016 14:45:55 +0100 Subject: [PATCH 04/22] Travis build on PHP 7.0 and 7.1 --- .travis.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index f761f2d..d9fb212 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,8 @@ language: php php: - 5.5 - 5.6 - - 7 + - 7.0 + - 7.1 - hhvm env: @@ -19,7 +20,7 @@ script: - composer test # phpcs only on latest PHP - - if [[ $TRAVIS_PHP_VERSION = '5.6' ]]; then composer phpcs; fi + - if [[ $TRAVIS_PHP_VERSION = '7.0' ]]; then composer phpcs; fi after_script: - php vendor/bin/coveralls -v From 297b5ac6fc2c4dd19a41a70b5d0cff81f644dabf Mon Sep 17 00:00:00 2001 From: Martin Hujer Date: Thu, 24 Nov 2016 14:55:24 +0100 Subject: [PATCH 05/22] release 2.3.0 --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 8afb209..adebca2 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,9 @@ Martin Hujer - - Changelog ---------- +## 2.3.0 (2016-11-24) +- [#7](https://github.com/mhujer/fio-api-php/pull/7): added official composer CA bundle support (@soukicz) + ## 2.2.0 (2016-03-13) - [#2](https://github.com/mhujer/fio-api-php/pull/2): added [Kdyby/CurlCaBundle](https://github.com/Kdyby/CurlCaBundle) as an optional dependency (@mhujer) From 55a790304b0425560619b61543aa8c1169c920aa Mon Sep 17 00:00:00 2001 From: Martin Hujer Date: Thu, 24 Nov 2016 15:30:22 +0100 Subject: [PATCH 06/22] update dependencies --- composer.json | 4 ++-- phpunit.xml.dist | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index a392830..43b99b6 100644 --- a/composer.json +++ b/composer.json @@ -23,8 +23,8 @@ "guzzlehttp/guzzle": "~6.1" }, "require-dev": { - "phpunit/phpunit": "~4.7|~5.0", - "squizlabs/php_codesniffer": "~2.3", + "phpunit/phpunit": "~5.5", + "squizlabs/php_codesniffer": "~2.7", "satooshi/php-coveralls": "^1.0" }, "suggest": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index c29a516..ca3da8a 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -2,14 +2,13 @@ From 6920ba9afe1473306fd2c5ca47a7a9a008ee0d47 Mon Sep 17 00:00:00 2001 From: Martin Hujer Date: Thu, 24 Nov 2016 15:30:38 +0100 Subject: [PATCH 07/22] Drop PHP <7 support --- .travis.yml | 3 --- README.md | 5 ++++- composer.json | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index d9fb212..73c3238 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,8 @@ language: php php: - - 5.5 - - 5.6 - 7.0 - 7.1 - - hhvm env: matrix: diff --git a/README.md b/README.md index adebca2..606089d 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ foreach ($transactionList->getTransactions() as $transaction) { Requirements ------------ -Fio API PHP works with PHP 5.5, PHP 5.6 or PHP 7. +Fio API PHP works with PHP 7 or higher. Submitting bugs and feature requests ------------------------------------ @@ -39,6 +39,9 @@ Martin Hujer - - Changelog ---------- +## 3.0.0 (2016-11-24) +- dropped support for PHP <7 + ## 2.3.0 (2016-11-24) - [#7](https://github.com/mhujer/fio-api-php/pull/7): added official composer CA bundle support (@soukicz) diff --git a/composer.json b/composer.json index 43b99b6..45f244c 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ } ], "require": { - "php": ">=5.5", + "php": ">=7.0", "ext-curl": "*", "guzzlehttp/guzzle": "~6.1" }, From c2bd061532c5e3d63447cf9b88b808bb511f7ea1 Mon Sep 17 00:00:00 2001 From: Martin Hujer Date: Fri, 9 Dec 2016 23:14:16 +0100 Subject: [PATCH 08/22] tests use current best-practices --- phpunit.xml.dist | 2 +- tests/FioApi/AccountTest.php | 10 +++++----- tests/FioApi/DownloaderTest.php | 26 ++++++++++++++------------ tests/FioApi/TransactionListTest.php | 4 ++-- tests/FioApi/UrlBuilderTest.php | 11 +++++------ 5 files changed, 27 insertions(+), 26 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index ca3da8a..4791e7b 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -2,7 +2,7 @@ assertEquals('214498596', $account->getAccountNumber()); - $this->assertEquals('2010', $account->getBankCode()); - $this->assertEquals('CZK', $account->getCurrency()); - $this->assertEquals('CZ9820100000000214498596', $account->getIban()); - $this->assertEquals('FIOBCZPPXXX', $account->getBic()); + $this->assertSame('214498596', $account->getAccountNumber()); + $this->assertSame('2010', $account->getBankCode()); + $this->assertSame('CZK', $account->getCurrency()); + $this->assertSame('CZ9820100000000214498596', $account->getIban()); + $this->assertSame('FIOBCZPPXXX', $account->getBic()); } } diff --git a/tests/FioApi/DownloaderTest.php b/tests/FioApi/DownloaderTest.php index 5985d1b..50d5eaf 100644 --- a/tests/FioApi/DownloaderTest.php +++ b/tests/FioApi/DownloaderTest.php @@ -10,40 +10,40 @@ class DownloaderTest extends \PHPUnit_Framework_TestCase { - /** - * @expectedException \FioApi\Exceptions\TooGreedyException - */ public function testNotRespectingTheTimeoutResultsInTooGreedyException() { $handler = HandlerStack::create(new MockHandler([ new Response(409), ])); $downloader = new Downloader('testToken', new Client(['handler' => $handler])); + + $this->expectException(\FioApi\Exceptions\TooGreedyException::class); + $downloader->downloadSince(new \DateTime('-1 week')); } - /** - * @expectedException \FioApi\Exceptions\InternalErrorException - */ public function testInvalidTokenResultsInInternalErrorException() { $handler = HandlerStack::create(new MockHandler([ new Response(500), ])); $downloader = new Downloader('invalidToken', new Client(['handler' => $handler])); + + $this->expectException(\FioApi\Exceptions\InternalErrorException::class); + $downloader->downloadSince(new \DateTime('-1 week')); } - /** - * @expectedException \GuzzleHttp\Exception\BadResponseException - * @expectedExceptionCode 418 - */ public function testUnknownResponseCodePassesOriginalException() { $handler = HandlerStack::create(new MockHandler([ new Response(418), ])); $downloader = new Downloader('validToken', new Client(['handler' => $handler])); + + $this->expectException(\GuzzleHttp\Exception\BadResponseException::class); + $this->expectExceptionCode(418); + $downloader->downloadSince(new \DateTime('-1 week')); } @@ -53,14 +53,16 @@ public function testDownloaderDownloadsData() new Response(200, [], file_get_contents(__DIR__ . '/data/example-response.json')), ])); $downloader = new Downloader('validToken', new Client(['handler' => $handler])); + $transactionList = $downloader->downloadSince(new \DateTime('-1 week')); - $this->assertInstanceOf('\FioApi\TransactionList', $transactionList); + + $this->assertInstanceOf(TransactionList::class, $transactionList); } public function testDownloaderSetCertificatePath() { $downloader = new Downloader('validToken'); $downloader->setCertificatePath('foo.pem'); - $this->assertEquals('foo.pem', $downloader->getCertificatePath()); + $this->assertSame('foo.pem', $downloader->getCertificatePath()); } } diff --git a/tests/FioApi/TransactionListTest.php b/tests/FioApi/TransactionListTest.php index dbf0128..96c579b 100644 --- a/tests/FioApi/TransactionListTest.php +++ b/tests/FioApi/TransactionListTest.php @@ -17,7 +17,7 @@ public function testTransactionListValuesAreProperlySet() $this->assertSame(1111111111, $transactionList->getIdFrom()); $this->assertSame(1111111999, $transactionList->getIdTo()); $this->assertSame(null, $transactionList->getIdLastDownload()); - $this->assertInstanceOf('FioApi\Account', $transactionList->getAccount()); - $this->assertInstanceOf('FioApi\Transaction', $transactionList->getTransactions()[0]); + $this->assertInstanceOf(Account::class, $transactionList->getAccount()); + $this->assertInstanceOf(Transaction::class, $transactionList->getTransactions()[0]); } } diff --git a/tests/FioApi/UrlBuilderTest.php b/tests/FioApi/UrlBuilderTest.php index 4e6ddd9..9516415 100644 --- a/tests/FioApi/UrlBuilderTest.php +++ b/tests/FioApi/UrlBuilderTest.php @@ -4,31 +4,30 @@ class UrlBuilderTest extends \PHPUnit_Framework_TestCase { - /** - * @expectedException \FioApi\Exceptions\MissingTokenException - */ public function testMissingTokenExceptionIsThrownForEmptyToken() { + $this->expectException(\FioApi\Exceptions\MissingTokenException::class); + new UrlBuilder(''); } public function testTokenCanBeSetThroughConstructor() { $urlBuilder = new UrlBuilder('token1'); - $this->assertEquals('token1', $urlBuilder->getToken()); + $this->assertSame('token1', $urlBuilder->getToken()); } public function testTokenCanBeChangedThroughSetter() { $urlBuilder = new UrlBuilder('token1'); $urlBuilder->setToken('token2'); - $this->assertEquals('token2', $urlBuilder->getToken()); + $this->assertSame('token2', $urlBuilder->getToken()); } public function testBuildPeriodsUrlReturnValidUrl() { $urlBuilder = new UrlBuilder('token1'); - $this->assertEquals( + $this->assertSame( 'https://www.fio.cz/ib_api/rest/periods/token1/2015-03-25/2015-03-31/transactions.json', $urlBuilder->buildPeriodsUrl(new \DateTime('2015-03-25'), new \DateTime('2015-03-31')) ); From ca7f895eac37f471437049f974a3ea216e35fbfc Mon Sep 17 00:00:00 2001 From: Martin Hujer Date: Fri, 9 Dec 2016 22:49:26 +0100 Subject: [PATCH 09/22] DateTimeImmutable (or DateTimeInterface) is used everywhere --- README.md | 6 +++++- src/FioApi/Downloader.php | 12 ++++++------ src/FioApi/Transaction.php | 8 ++++---- src/FioApi/TransactionList.php | 20 ++++++++++---------- src/FioApi/UrlBuilder.php | 6 +++--- tests/FioApi/DownloaderTest.php | 8 ++++---- tests/FioApi/TransactionListTest.php | 4 ++-- tests/FioApi/TransactionTest.php | 2 +- tests/FioApi/UrlBuilderTest.php | 5 ++++- 9 files changed, 39 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 606089d..3e482f6 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Usage require_once 'vendor/autoload.php'; $downloader = new FioApi\Downloader('TOKEN@todo'); -$transactionList = $downloader->downloadSince(new \DateTime('-1 week')); +$transactionList = $downloader->downloadSince(new \DateTimeImmutable('-1 week')); foreach ($transactionList->getTransactions() as $transaction) { var_dump($transaction); //object with getters @@ -39,6 +39,10 @@ Martin Hujer - - Changelog ---------- + +## X.X.X (201X-XX-XX) +- `DateTime` replaced with `DateTimeImmutable` (or `DateTimeInterface`) + ## 3.0.0 (2016-11-24) - dropped support for PHP <7 diff --git a/src/FioApi/Downloader.php b/src/FioApi/Downloader.php index 42a5d20..cd6d3ea 100644 --- a/src/FioApi/Downloader.php +++ b/src/FioApi/Downloader.php @@ -61,11 +61,11 @@ public function getClient() } /** - * @param \DateTime $from - * @param \DateTime $to + * @param \DateTimeInterface $from + * @param \DateTimeInterface $to * @return TransactionList */ - public function downloadFromTo(\DateTime $from, \DateTime $to) + public function downloadFromTo(\DateTimeInterface $from, \DateTimeInterface $to) { $client = $this->getClient(); $url = $this->urlBuilder->buildPeriodsUrl($from, $to); @@ -91,11 +91,11 @@ public function downloadFromTo(\DateTime $from, \DateTime $to) } /** - * @param \DateTime $since + * @param \DateTimeInterface $since * @return TransactionList */ - public function downloadSince(\DateTime $since) + public function downloadSince(\DateTimeInterface $since) { - return $this->downloadFromTo($since, new \DateTime()); + return $this->downloadFromTo($since, new \DateTimeImmutable()); } } diff --git a/src/FioApi/Transaction.php b/src/FioApi/Transaction.php index 7abe1e1..d6d0a6f 100644 --- a/src/FioApi/Transaction.php +++ b/src/FioApi/Transaction.php @@ -6,7 +6,7 @@ class Transaction /** @var int */ protected $id; - /** @var \DateTime */ + /** @var \DateTimeImmutable */ protected $date; /** @var float */ @@ -56,7 +56,7 @@ class Transaction protected function __construct( $id, - $date, + \DateTimeImmutable $date, $amount, $currency, $senderAccountNumber, @@ -100,7 +100,7 @@ public static function create(\stdClass $data) { return new self( $data->column22->value, //ID pohybu - new \DateTime($data->column0->value), //Datum + new \DateTimeImmutable($data->column0->value), //Datum $data->column1->value, //Objem $data->column14->value, //Měna !empty($data->column2) ? $data->column2->value : null, //Protiúčet @@ -128,7 +128,7 @@ public function getId() } /** - * @return \DateTime + * @return \DateTimeImmutable */ public function getDate() { diff --git a/src/FioApi/TransactionList.php b/src/FioApi/TransactionList.php index 54dede1..6359674 100644 --- a/src/FioApi/TransactionList.php +++ b/src/FioApi/TransactionList.php @@ -9,10 +9,10 @@ class TransactionList /** @var float */ protected $closingBalance; - /** @var \DateTime */ + /** @var \DateTimeImmutable */ protected $dateStart; - /** @var \DateTime */ + /** @var \DateTimeImmutable */ protected $dateEnd; /** @var int */ @@ -33,8 +33,8 @@ class TransactionList /** * @param float $openingBalance * @param float $closingBalance - * @param \DateTime $dateStart - * @param \DateTime $dateEnd + * @param \DateTimeImmutable $dateStart + * @param \DateTimeImmutable $dateEnd * @param int $idFrom * @param int $idTo * @param int $idLastDownload @@ -43,8 +43,8 @@ class TransactionList protected function __construct( $openingBalance, $closingBalance, - \DateTime $dateStart, - \DateTime $dateEnd, + \DateTimeImmutable $dateStart, + \DateTimeImmutable $dateEnd, $idFrom, $idTo, $idLastDownload, @@ -85,8 +85,8 @@ public static function create(\stdClass $data) $transactionList = new self( $data->info->openingBalance, $data->info->closingBalance, - new \DateTime($data->info->dateStart), - new \DateTime($data->info->dateEnd), + new \DateTimeImmutable($data->info->dateStart), + new \DateTimeImmutable($data->info->dateEnd), $data->info->idFrom, $data->info->idTo, $data->info->idLastDownload, @@ -117,7 +117,7 @@ public function getClosingBalance() } /** - * @return \DateTime + * @return \DateTimeImmutable */ public function getDateStart() { @@ -125,7 +125,7 @@ public function getDateStart() } /** - * @return \DateTime + * @return \DateTimeImmutable */ public function getDateEnd() { diff --git a/src/FioApi/UrlBuilder.php b/src/FioApi/UrlBuilder.php index 8a065f1..3a27686 100644 --- a/src/FioApi/UrlBuilder.php +++ b/src/FioApi/UrlBuilder.php @@ -42,11 +42,11 @@ public function setToken($token) } /** - * @param \DateTime $from - * @param \DateTime $to + * @param \DateTimeInterface $from + * @param \DateTimeInterface $to * @return string */ - public function buildPeriodsUrl(\DateTime $from, \DateTime $to) + public function buildPeriodsUrl(\DateTimeInterface $from, \DateTimeInterface $to) { return sprintf( self::BASE_URL . 'periods/%s/%s/%s/transactions.json', diff --git a/tests/FioApi/DownloaderTest.php b/tests/FioApi/DownloaderTest.php index 50d5eaf..41daa89 100644 --- a/tests/FioApi/DownloaderTest.php +++ b/tests/FioApi/DownloaderTest.php @@ -19,7 +19,7 @@ public function testNotRespectingTheTimeoutResultsInTooGreedyException() $this->expectException(\FioApi\Exceptions\TooGreedyException::class); - $downloader->downloadSince(new \DateTime('-1 week')); + $downloader->downloadSince(new \DateTimeImmutable('-1 week')); } public function testInvalidTokenResultsInInternalErrorException() @@ -31,7 +31,7 @@ public function testInvalidTokenResultsInInternalErrorException() $this->expectException(\FioApi\Exceptions\InternalErrorException::class); - $downloader->downloadSince(new \DateTime('-1 week')); + $downloader->downloadSince(new \DateTimeImmutable('-1 week')); } public function testUnknownResponseCodePassesOriginalException() @@ -44,7 +44,7 @@ public function testUnknownResponseCodePassesOriginalException() $this->expectException(\GuzzleHttp\Exception\BadResponseException::class); $this->expectExceptionCode(418); - $downloader->downloadSince(new \DateTime('-1 week')); + $downloader->downloadSince(new \DateTimeImmutable('-1 week')); } public function testDownloaderDownloadsData() @@ -54,7 +54,7 @@ public function testDownloaderDownloadsData() ])); $downloader = new Downloader('validToken', new Client(['handler' => $handler])); - $transactionList = $downloader->downloadSince(new \DateTime('-1 week')); + $transactionList = $downloader->downloadSince(new \DateTimeImmutable('-1 week')); $this->assertInstanceOf(TransactionList::class, $transactionList); } diff --git a/tests/FioApi/TransactionListTest.php b/tests/FioApi/TransactionListTest.php index 96c579b..4c69a19 100644 --- a/tests/FioApi/TransactionListTest.php +++ b/tests/FioApi/TransactionListTest.php @@ -12,8 +12,8 @@ public function testTransactionListValuesAreProperlySet() $this->assertSame(500, $transactionList->getOpeningBalance()); $this->assertSame(1000, $transactionList->getClosingBalance()); - $this->assertEquals(new \DateTime('2015-03-30+0200'), $transactionList->getDateStart()); - $this->assertEquals(new \DateTime('2015-03-31+0200'), $transactionList->getDateEnd()); + $this->assertEquals(new \DateTimeImmutable('2015-03-30+0200'), $transactionList->getDateStart()); + $this->assertEquals(new \DateTimeImmutable('2015-03-31+0200'), $transactionList->getDateEnd()); $this->assertSame(1111111111, $transactionList->getIdFrom()); $this->assertSame(1111111999, $transactionList->getIdTo()); $this->assertSame(null, $transactionList->getIdLastDownload()); diff --git a/tests/FioApi/TransactionTest.php b/tests/FioApi/TransactionTest.php index c4c5b46..11387ba 100644 --- a/tests/FioApi/TransactionTest.php +++ b/tests/FioApi/TransactionTest.php @@ -11,7 +11,7 @@ public function testAccountValuesAreProperlySet() $transaction = Transaction::create($transaction); $this->assertSame(1111111111, $transaction->getId()); - $this->assertEquals(new \DateTime('2015-03-30+0200'), $transaction->getDate()); + $this->assertEquals(new \DateTimeImmutable('2015-03-30+0200'), $transaction->getDate()); $this->assertSame(127.0, $transaction->getAmount()); $this->assertSame('CZK', $transaction->getCurrency()); $this->assertSame('214498596', $transaction->getSenderAccountNumber()); diff --git a/tests/FioApi/UrlBuilderTest.php b/tests/FioApi/UrlBuilderTest.php index 9516415..be8df43 100644 --- a/tests/FioApi/UrlBuilderTest.php +++ b/tests/FioApi/UrlBuilderTest.php @@ -29,7 +29,10 @@ public function testBuildPeriodsUrlReturnValidUrl() $urlBuilder = new UrlBuilder('token1'); $this->assertSame( 'https://www.fio.cz/ib_api/rest/periods/token1/2015-03-25/2015-03-31/transactions.json', - $urlBuilder->buildPeriodsUrl(new \DateTime('2015-03-25'), new \DateTime('2015-03-31')) + $urlBuilder->buildPeriodsUrl( + new \DateTimeImmutable('2015-03-25'), + new \DateTimeImmutable('2015-03-31') + ) ); } } From 78e0dcdd7b3f1337172b93c31beb0acf884cf035 Mon Sep 17 00:00:00 2001 From: Martin Hujer Date: Fri, 9 Dec 2016 23:19:19 +0100 Subject: [PATCH 10/22] minimal supported version is PHP 7.1 --- .travis.yml | 3 +-- README.md | 3 ++- appveyor.yml | 5 +++-- composer.json | 4 ++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 73c3238..7b894ea 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: php php: - - 7.0 - 7.1 env: @@ -17,7 +16,7 @@ script: - composer test # phpcs only on latest PHP - - if [[ $TRAVIS_PHP_VERSION = '7.0' ]]; then composer phpcs; fi + - if [[ $TRAVIS_PHP_VERSION = '7.1' ]]; then composer phpcs; fi after_script: - php vendor/bin/coveralls -v diff --git a/README.md b/README.md index 3e482f6..bbb4295 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,8 @@ Martin Hujer - - Changelog ---------- -## X.X.X (201X-XX-XX) +## 4.0.0 (201X-XX-XX) +- minimal supported version is PHP 7.1 - `DateTime` replaced with `DateTimeImmutable` (or `DateTimeInterface`) ## 3.0.0 (2016-11-24) diff --git a/appveyor.yml b/appveyor.yml index 7a5ac69..09cf7c8 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -17,13 +17,14 @@ init: install: - IF EXIST c:\php (SET PHP=0) ELSE (mkdir c:\php) - IF %PHP%==1 cd c:\php - - IF %PHP%==1 appveyor DownloadFile http://windows.php.net/downloads/releases/php-7.0.13-Win32-VC14-x86.zip - - IF %PHP%==1 7z x php-7.0.13-Win32-VC14-x86.zip -y >nul + - IF %PHP%==1 appveyor DownloadFile http://windows.php.net/downloads/releases/php-7.1.0-Win32-VC14-x86.zip + - IF %PHP%==1 7z x php-7.1.0-Win32-VC14-x86.zip -y >nul - IF %PHP%==1 copy /Y php.ini-development php.ini - IF %PHP%==1 echo max_execution_time=1200 >> php.ini - IF %PHP%==1 echo date.timezone="UTC" >> php.ini - IF %PHP%==1 echo extension_dir=ext >> php.ini - IF %PHP%==1 echo extension=php_curl.dll >> php.ini + - IF %PHP%==1 echo extension=php_mbstring.dll >> php.ini - IF %PHP%==1 echo extension=php_openssl.dll >> php.ini - IF %PHP%==1 del /Q *.zip - IF %PHP%==1 cd .. diff --git a/composer.json b/composer.json index 45f244c..6ea6a86 100644 --- a/composer.json +++ b/composer.json @@ -18,12 +18,12 @@ } ], "require": { - "php": ">=7.0", + "php": ">=7.1", "ext-curl": "*", "guzzlehttp/guzzle": "~6.1" }, "require-dev": { - "phpunit/phpunit": "~5.5", + "phpunit/phpunit": "~5.7", "squizlabs/php_codesniffer": "~2.7", "satooshi/php-coveralls": "^1.0" }, From 13a3f389600e0cc1bae9ffe1d79a2d794fe810be Mon Sep 17 00:00:00 2001 From: Martin Hujer Date: Fri, 9 Dec 2016 22:39:08 +0100 Subject: [PATCH 11/22] declare(strict_types = 1); --- src/FioApi/Account.php | 2 ++ src/FioApi/Downloader.php | 4 +++- src/FioApi/Exceptions/InternalErrorException.php | 2 ++ src/FioApi/Exceptions/MissingTokenException.php | 2 ++ src/FioApi/Exceptions/TooGreedyException.php | 2 ++ src/FioApi/Transaction.php | 2 ++ src/FioApi/TransactionList.php | 2 ++ src/FioApi/UrlBuilder.php | 2 ++ tests/FioApi/AccountTest.php | 1 + tests/FioApi/DownloaderTest.php | 1 + tests/FioApi/TransactionListTest.php | 1 + tests/FioApi/TransactionTest.php | 1 + tests/FioApi/UrlBuilderTest.php | 1 + tests/bootstrap.php | 2 ++ 14 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/FioApi/Account.php b/src/FioApi/Account.php index 17dbab3..52dc244 100644 --- a/src/FioApi/Account.php +++ b/src/FioApi/Account.php @@ -1,4 +1,6 @@ getBody())->accountStatement); + return TransactionList::create(json_decode($response->getBody()->getContents())->accountStatement); } /** diff --git a/src/FioApi/Exceptions/InternalErrorException.php b/src/FioApi/Exceptions/InternalErrorException.php index b4ead6f..d82f862 100644 --- a/src/FioApi/Exceptions/InternalErrorException.php +++ b/src/FioApi/Exceptions/InternalErrorException.php @@ -1,4 +1,6 @@ addPsr4('FioApi\\', __DIR__ . '/FioApi'); From 0b6e76b651f14308ce21b7531805bb81b1ebeedd Mon Sep 17 00:00:00 2001 From: Martin Hujer Date: Fri, 9 Dec 2016 23:10:31 +0100 Subject: [PATCH 12/22] typehints --- README.md | 1 + src/FioApi/Account.php | 41 +++----- src/FioApi/Downloader.php | 35 ++----- src/FioApi/Transaction.php | 141 +++++++++------------------ src/FioApi/TransactionList.php | 64 +++--------- src/FioApi/UrlBuilder.php | 26 +---- tests/FioApi/TransactionListTest.php | 4 +- 7 files changed, 90 insertions(+), 222 deletions(-) diff --git a/README.md b/README.md index bbb4295..8a47138 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ Changelog ## 4.0.0 (201X-XX-XX) - minimal supported version is PHP 7.1 - `DateTime` replaced with `DateTimeImmutable` (or `DateTimeInterface`) +- strict types and primitive typehints are used everywhere ## 3.0.0 (2016-11-24) - dropped support for PHP <7 diff --git a/src/FioApi/Account.php b/src/FioApi/Account.php index 52dc244..5c8db35 100644 --- a/src/FioApi/Account.php +++ b/src/FioApi/Account.php @@ -20,15 +20,13 @@ class Account /** @var string */ protected $bic; - /** - * @param string $accountNumber - * @param string $bankCode - * @param string $currency - * @param string $iban - * @param string $bic - */ - public function __construct($accountNumber, $bankCode, $currency, $iban, $bic) - { + public function __construct( + string $accountNumber, + string $bankCode, + string $currency, + string $iban, + string $bic + ) { $this->accountNumber = $accountNumber; $this->bankCode = $bankCode; $this->currency = $currency; @@ -36,42 +34,27 @@ public function __construct($accountNumber, $bankCode, $currency, $iban, $bic) $this->bic = $bic; } - /** - * @return string - */ - public function getAccountNumber() + public function getAccountNumber(): string { return $this->accountNumber; } - /** - * @return string - */ - public function getBankCode() + public function getBankCode(): string { return $this->bankCode; } - /** - * @return string - */ - public function getCurrency() + public function getCurrency(): string { return $this->currency; } - /** - * @return string - */ - public function getIban() + public function getIban(): string { return $this->iban; } - /** - * @return string - */ - public function getBic() + public function getBic(): string { return $this->bic; } diff --git a/src/FioApi/Downloader.php b/src/FioApi/Downloader.php index 7b65312..458150a 100644 --- a/src/FioApi/Downloader.php +++ b/src/FioApi/Downloader.php @@ -5,6 +5,7 @@ use FioApi\Exceptions\InternalErrorException; use FioApi\Exceptions\TooGreedyException; +use GuzzleHttp\ClientInterface; use Psr\Http\Message\ResponseInterface; class Downloader @@ -18,24 +19,20 @@ class Downloader /** @var string */ protected $certificatePath; - /** - * @param string $token - */ - public function __construct($token, \GuzzleHttp\ClientInterface $client = null) - { + public function __construct( + string $token, + \GuzzleHttp\ClientInterface $client = null + ) { $this->urlBuilder = new UrlBuilder($token); $this->client = $client; } - /** - * @param string $path - */ - public function setCertificatePath($path) + public function setCertificatePath(string $path) { $this->certificatePath = $path; } - public function getCertificatePath() + public function getCertificatePath(): string { if ($this->certificatePath) { return $this->certificatePath; @@ -51,10 +48,7 @@ public function getCertificatePath() return __DIR__ . '/keys/Geotrust_PCA_G3_Root.pem'; } - /** - * @return \GuzzleHttp\ClientInterface - */ - public function getClient() + public function getClient(): ClientInterface { if (!$this->client) { $this->client = new \GuzzleHttp\Client(); @@ -62,12 +56,7 @@ public function getClient() return $this->client; } - /** - * @param \DateTimeInterface $from - * @param \DateTimeInterface $to - * @return TransactionList - */ - public function downloadFromTo(\DateTimeInterface $from, \DateTimeInterface $to) + public function downloadFromTo(\DateTimeInterface $from, \DateTimeInterface $to): TransactionList { $client = $this->getClient(); $url = $this->urlBuilder->buildPeriodsUrl($from, $to); @@ -92,11 +81,7 @@ public function downloadFromTo(\DateTimeInterface $from, \DateTimeInterface $to) return TransactionList::create(json_decode($response->getBody()->getContents())->accountStatement); } - /** - * @param \DateTimeInterface $since - * @return TransactionList - */ - public function downloadSince(\DateTimeInterface $since) + public function downloadSince(\DateTimeInterface $since): TransactionList { return $this->downloadFromTo($since, new \DateTimeImmutable()); } diff --git a/src/FioApi/Transaction.php b/src/FioApi/Transaction.php index 820aad5..78011a3 100644 --- a/src/FioApi/Transaction.php +++ b/src/FioApi/Transaction.php @@ -17,63 +17,63 @@ class Transaction /** @var string */ protected $currency; - /** @var string */ + /** @var string|null */ protected $senderAccountNumber; - /** @var string */ + /** @var string|null */ protected $senderBankCode; - /** @var string */ + /** @var string|null */ protected $senderBankName; - /** @var int */ + /** @var int|null */ protected $constantSymbol; - /** @var string */ + /** @var string|null */ protected $variableSymbol; - /** @var int */ + /** @var int|null */ protected $specificSymbol; - /** @var string */ + /** @var string|null */ protected $userIdentity; - /** @var string */ + /** @var string|null */ protected $userMessage; /** @var string */ protected $transactionType; - /** @var string */ + /** @var string|null */ protected $performedBy; - /** @var string */ + /** @var string|null */ protected $comment; - /** @var string */ + /** @var int|null */ protected $paymentOrderId; - /** @var string */ + /** @var string|null */ protected $specification; protected function __construct( $id, \DateTimeImmutable $date, - $amount, - $currency, - $senderAccountNumber, - $senderBankCode, - $senderBankName, - $constantSymbol, - $variableSymbol, - $specificSymbol, - $userIdentity, - $userMessage, - $transactionType, - $performedBy, - $comment, - $paymentOrderId, - $specification + float $amount, + string $currency, + ?string $senderAccountNumber, + ?string $senderBankCode, + ?string $senderBankName, + ?int $constantSymbol, + ?string $variableSymbol, + ?int $specificSymbol, + ?string $userIdentity, + ?string $userMessage, + string $transactionType, + ?string $performedBy, + ?string $comment, + ?int $paymentOrderId, + ?string $specification ) { $this->id = $id; $this->date = $date; @@ -98,7 +98,7 @@ protected function __construct( * @param \stdClass $data Transaction data from JSON API response * @return Transaction */ - public static function create(\stdClass $data) + public static function create(\stdClass $data): Transaction { return new self( $data->column22->value, //ID pohybu @@ -121,138 +121,87 @@ public static function create(\stdClass $data) ); } - /** - * @return int - */ - public function getId() + public function getId(): int { return $this->id; } - /** - * @return \DateTimeImmutable - */ - public function getDate() + public function getDate(): \DateTimeImmutable { return $this->date; } - /** - * @return float - */ - public function getAmount() + public function getAmount(): float { return $this->amount; } - /** - * @return string - */ - public function getCurrency() + public function getCurrency(): string { return $this->currency; } - /** - * @return string - */ - public function getSenderAccountNumber() + public function getSenderAccountNumber(): ?string { return $this->senderAccountNumber; } - /** - * @return string - */ - public function getSenderBankCode() + public function getSenderBankCode(): ?string { return $this->senderBankCode; } - /** - * @return string - */ - public function getSenderBankName() + public function getSenderBankName(): ?string { return $this->senderBankName; } - /** - * @return int - */ - public function getConstantSymbol() + public function getConstantSymbol(): ?int { return $this->constantSymbol; } - /** - * @return string - */ - public function getVariableSymbol() + public function getVariableSymbol(): ?string { return $this->variableSymbol; } - /** - * @return int - */ - public function getSpecificSymbol() + public function getSpecificSymbol(): ?int { return $this->specificSymbol; } - /** - * @return string - */ - public function getUserIdentity() + public function getUserIdentity(): ?string { return $this->userIdentity; } - /** - * @return string - */ - public function getUserMessage() + public function getUserMessage(): ?string { return $this->userMessage; } - /** - * @return string - */ - public function getTransactionType() + public function getTransactionType(): string { return $this->transactionType; } - /** - * @return string - */ - public function getPerformedBy() + public function getPerformedBy(): ?string { return $this->performedBy; } - /** - * @return string - */ - public function getComment() + public function getComment(): ?string { return $this->comment; } - /** - * @return string - */ - public function getPaymentOrderId() + public function getPaymentOrderId(): ?int { return $this->paymentOrderId; } - /** - * @return string - */ - public function getSpecification() + public function getSpecification(): ?string { return $this->specification; } diff --git a/src/FioApi/TransactionList.php b/src/FioApi/TransactionList.php index 84d281d..9fb6321 100644 --- a/src/FioApi/TransactionList.php +++ b/src/FioApi/TransactionList.php @@ -32,24 +32,14 @@ class TransactionList /** @var Transaction[] */ protected $transactions = []; - /** - * @param float $openingBalance - * @param float $closingBalance - * @param \DateTimeImmutable $dateStart - * @param \DateTimeImmutable $dateEnd - * @param int $idFrom - * @param int $idTo - * @param int $idLastDownload - * @param Account $account - */ protected function __construct( - $openingBalance, - $closingBalance, + float $openingBalance, + float $closingBalance, \DateTimeImmutable $dateStart, \DateTimeImmutable $dateEnd, - $idFrom, - $idTo, - $idLastDownload, + int $idFrom, + int $idTo, + ?int $idLastDownload, Account $account ) { $this->openingBalance = $openingBalance; @@ -74,7 +64,7 @@ protected function addTransaction(Transaction $transaction) * @param \stdClass $data Data from JSON API response * @return TransactionList */ - public static function create(\stdClass $data) + public static function create(\stdClass $data): TransactionList { $account = new Account( $data->info->accountId, @@ -102,66 +92,42 @@ public static function create(\stdClass $data) return $transactionList; } - /** - * @return float - */ - public function getOpeningBalance() + public function getOpeningBalance(): float { return $this->openingBalance; } - /** - * @return float - */ - public function getClosingBalance() + public function getClosingBalance(): float { return $this->closingBalance; } - /** - * @return \DateTimeImmutable - */ - public function getDateStart() + public function getDateStart(): \DateTimeImmutable { return $this->dateStart; } - /** - * @return \DateTimeImmutable - */ - public function getDateEnd() + public function getDateEnd(): \DateTimeImmutable { return $this->dateEnd; } - /** - * @return int - */ - public function getIdFrom() + public function getIdFrom(): int { return $this->idFrom; } - /** - * @return int - */ - public function getIdTo() + public function getIdTo(): int { return $this->idTo; } - /** - * @return int - */ - public function getIdLastDownload() + public function getIdLastDownload(): ?int { return $this->idLastDownload; } - /** - * @return Account - */ - public function getAccount() + public function getAccount(): Account { return $this->account; } @@ -169,7 +135,7 @@ public function getAccount() /** * @return Transaction[] */ - public function getTransactions() + public function getTransactions(): array { return $this->transactions; } diff --git a/src/FioApi/UrlBuilder.php b/src/FioApi/UrlBuilder.php index f5fee38..cf1a731 100644 --- a/src/FioApi/UrlBuilder.php +++ b/src/FioApi/UrlBuilder.php @@ -9,31 +9,20 @@ class UrlBuilder { const BASE_URL = 'https://www.fio.cz/ib_api/rest/'; - /** - * @var string - */ + /** @var string */ protected $token; - /** - * @param string $token - */ - public function __construct($token) + public function __construct(string $token) { $this->setToken($token); } - /** - * @return string - */ - public function getToken() + public function getToken(): string { return $this->token; } - /** - * @param string $token - */ - public function setToken($token) + public function setToken(string $token) { if (!$token) { throw new MissingTokenException( @@ -43,12 +32,7 @@ public function setToken($token) $this->token = $token; } - /** - * @param \DateTimeInterface $from - * @param \DateTimeInterface $to - * @return string - */ - public function buildPeriodsUrl(\DateTimeInterface $from, \DateTimeInterface $to) + public function buildPeriodsUrl(\DateTimeInterface $from, \DateTimeInterface $to): string { return sprintf( self::BASE_URL . 'periods/%s/%s/%s/transactions.json', diff --git a/tests/FioApi/TransactionListTest.php b/tests/FioApi/TransactionListTest.php index ce9b239..8a7ec4f 100644 --- a/tests/FioApi/TransactionListTest.php +++ b/tests/FioApi/TransactionListTest.php @@ -11,8 +11,8 @@ public function testTransactionListValuesAreProperlySet() $transactionList = TransactionList::create($transactionList->accountStatement); - $this->assertSame(500, $transactionList->getOpeningBalance()); - $this->assertSame(1000, $transactionList->getClosingBalance()); + $this->assertSame(500.0, $transactionList->getOpeningBalance()); + $this->assertSame(1000.0, $transactionList->getClosingBalance()); $this->assertEquals(new \DateTimeImmutable('2015-03-30+0200'), $transactionList->getDateStart()); $this->assertEquals(new \DateTimeImmutable('2015-03-31+0200'), $transactionList->getDateEnd()); $this->assertSame(1111111111, $transactionList->getIdFrom()); From da8f9a92c504b94039c1a6e27a017fd82d9172e3 Mon Sep 17 00:00:00 2001 From: Martin Hujer Date: Fri, 9 Dec 2016 23:56:54 +0100 Subject: [PATCH 13/22] typehints - fixes after testing on my banking history --- src/FioApi/Transaction.php | 18 +++++++++--------- src/FioApi/TransactionList.php | 12 ++++++------ tests/FioApi/TransactionListTest.php | 4 ++-- tests/FioApi/TransactionTest.php | 2 +- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/FioApi/Transaction.php b/src/FioApi/Transaction.php index 78011a3..38b4ea7 100644 --- a/src/FioApi/Transaction.php +++ b/src/FioApi/Transaction.php @@ -26,13 +26,13 @@ class Transaction /** @var string|null */ protected $senderBankName; - /** @var int|null */ + /** @var string|null */ protected $constantSymbol; /** @var string|null */ protected $variableSymbol; - /** @var int|null */ + /** @var string|null */ protected $specificSymbol; /** @var string|null */ @@ -50,7 +50,7 @@ class Transaction /** @var string|null */ protected $comment; - /** @var int|null */ + /** @var float|null */ protected $paymentOrderId; /** @var string|null */ @@ -64,15 +64,15 @@ protected function __construct( ?string $senderAccountNumber, ?string $senderBankCode, ?string $senderBankName, - ?int $constantSymbol, + ?string $constantSymbol, ?string $variableSymbol, - ?int $specificSymbol, + ?string $specificSymbol, ?string $userIdentity, ?string $userMessage, string $transactionType, ?string $performedBy, ?string $comment, - ?int $paymentOrderId, + ?float $paymentOrderId, ?string $specification ) { $this->id = $id; @@ -156,7 +156,7 @@ public function getSenderBankName(): ?string return $this->senderBankName; } - public function getConstantSymbol(): ?int + public function getConstantSymbol(): ?string { return $this->constantSymbol; } @@ -166,7 +166,7 @@ public function getVariableSymbol(): ?string return $this->variableSymbol; } - public function getSpecificSymbol(): ?int + public function getSpecificSymbol(): ?string { return $this->specificSymbol; } @@ -196,7 +196,7 @@ public function getComment(): ?string return $this->comment; } - public function getPaymentOrderId(): ?int + public function getPaymentOrderId(): ?float { return $this->paymentOrderId; } diff --git a/src/FioApi/TransactionList.php b/src/FioApi/TransactionList.php index 9fb6321..4bbb9c6 100644 --- a/src/FioApi/TransactionList.php +++ b/src/FioApi/TransactionList.php @@ -17,10 +17,10 @@ class TransactionList /** @var \DateTimeImmutable */ protected $dateEnd; - /** @var int */ + /** @var float */ protected $idFrom; - /** @var int */ + /** @var float */ protected $idTo; /** @var int */ @@ -37,8 +37,8 @@ protected function __construct( float $closingBalance, \DateTimeImmutable $dateStart, \DateTimeImmutable $dateEnd, - int $idFrom, - int $idTo, + float $idFrom, + float $idTo, ?int $idLastDownload, Account $account ) { @@ -112,12 +112,12 @@ public function getDateEnd(): \DateTimeImmutable return $this->dateEnd; } - public function getIdFrom(): int + public function getIdFrom(): float { return $this->idFrom; } - public function getIdTo(): int + public function getIdTo(): float { return $this->idTo; } diff --git a/tests/FioApi/TransactionListTest.php b/tests/FioApi/TransactionListTest.php index 8a7ec4f..e40923a 100644 --- a/tests/FioApi/TransactionListTest.php +++ b/tests/FioApi/TransactionListTest.php @@ -15,8 +15,8 @@ public function testTransactionListValuesAreProperlySet() $this->assertSame(1000.0, $transactionList->getClosingBalance()); $this->assertEquals(new \DateTimeImmutable('2015-03-30+0200'), $transactionList->getDateStart()); $this->assertEquals(new \DateTimeImmutable('2015-03-31+0200'), $transactionList->getDateEnd()); - $this->assertSame(1111111111, $transactionList->getIdFrom()); - $this->assertSame(1111111999, $transactionList->getIdTo()); + $this->assertSame((float) 1111111111, $transactionList->getIdFrom()); + $this->assertSame((float) 1111111999, $transactionList->getIdTo()); $this->assertSame(null, $transactionList->getIdLastDownload()); $this->assertInstanceOf(Account::class, $transactionList->getAccount()); $this->assertInstanceOf(Transaction::class, $transactionList->getTransactions()[0]); diff --git a/tests/FioApi/TransactionTest.php b/tests/FioApi/TransactionTest.php index 2dbaae0..100b71c 100644 --- a/tests/FioApi/TransactionTest.php +++ b/tests/FioApi/TransactionTest.php @@ -26,7 +26,7 @@ public function testAccountValuesAreProperlySet() $this->assertSame('Bezhotovostní příjem', $transaction->getTransactionType()); $this->assertSame(null, $transaction->getPerformedBy()); $this->assertSame('Comment? Comment!', $transaction->getComment()); - $this->assertSame(1111122222, $transaction->getPaymentOrderId()); + $this->assertSame((float) 1111122222, $transaction->getPaymentOrderId()); $this->assertSame('1500.00 EUR', $transaction->getSpecification()); } } From 5696b6d27e28d6f2f37844ab1849929ce6cc1750 Mon Sep 17 00:00:00 2001 From: Martin Hujer Date: Fri, 9 Dec 2016 23:59:02 +0100 Subject: [PATCH 14/22] transaction id is float --- src/FioApi/Transaction.php | 6 +++--- tests/FioApi/TransactionTest.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/FioApi/Transaction.php b/src/FioApi/Transaction.php index 38b4ea7..ac39b77 100644 --- a/src/FioApi/Transaction.php +++ b/src/FioApi/Transaction.php @@ -5,7 +5,7 @@ class Transaction { - /** @var int */ + /** @var float */ protected $id; /** @var \DateTimeImmutable */ @@ -57,7 +57,7 @@ class Transaction protected $specification; protected function __construct( - $id, + float $id, \DateTimeImmutable $date, float $amount, string $currency, @@ -121,7 +121,7 @@ public static function create(\stdClass $data): Transaction ); } - public function getId(): int + public function getId(): float { return $this->id; } diff --git a/tests/FioApi/TransactionTest.php b/tests/FioApi/TransactionTest.php index 100b71c..ea76a3e 100644 --- a/tests/FioApi/TransactionTest.php +++ b/tests/FioApi/TransactionTest.php @@ -11,7 +11,7 @@ public function testAccountValuesAreProperlySet() $transaction = Transaction::create($transaction); - $this->assertSame(1111111111, $transaction->getId()); + $this->assertSame((float) 1111111111, $transaction->getId()); $this->assertEquals(new \DateTimeImmutable('2015-03-30+0200'), $transaction->getDate()); $this->assertSame(127.0, $transaction->getAmount()); $this->assertSame('CZK', $transaction->getCurrency()); From 7d9c594ffe90698387eae26c74701a1283d42e80 Mon Sep 17 00:00:00 2001 From: Martin Hujer Date: Fri, 4 Aug 2017 17:40:43 +0200 Subject: [PATCH 15/22] transaction id is string --- src/FioApi/Transaction.php | 8 ++++---- tests/FioApi/TransactionTest.php | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/FioApi/Transaction.php b/src/FioApi/Transaction.php index ac39b77..da429a3 100644 --- a/src/FioApi/Transaction.php +++ b/src/FioApi/Transaction.php @@ -5,7 +5,7 @@ class Transaction { - /** @var float */ + /** @var string */ protected $id; /** @var \DateTimeImmutable */ @@ -57,7 +57,7 @@ class Transaction protected $specification; protected function __construct( - float $id, + string $id, \DateTimeImmutable $date, float $amount, string $currency, @@ -101,7 +101,7 @@ protected function __construct( public static function create(\stdClass $data): Transaction { return new self( - $data->column22->value, //ID pohybu + (string) $data->column22->value, //ID pohybu new \DateTimeImmutable($data->column0->value), //Datum $data->column1->value, //Objem $data->column14->value, //Měna @@ -121,7 +121,7 @@ public static function create(\stdClass $data): Transaction ); } - public function getId(): float + public function getId(): string { return $this->id; } diff --git a/tests/FioApi/TransactionTest.php b/tests/FioApi/TransactionTest.php index ea76a3e..c678fd2 100644 --- a/tests/FioApi/TransactionTest.php +++ b/tests/FioApi/TransactionTest.php @@ -11,7 +11,7 @@ public function testAccountValuesAreProperlySet() $transaction = Transaction::create($transaction); - $this->assertSame((float) 1111111111, $transaction->getId()); + $this->assertSame('1111111111', $transaction->getId()); $this->assertEquals(new \DateTimeImmutable('2015-03-30+0200'), $transaction->getDate()); $this->assertSame(127.0, $transaction->getAmount()); $this->assertSame('CZK', $transaction->getCurrency()); From bec073f105b12b6a84b51f09a3eddb24d5c9cccc Mon Sep 17 00:00:00 2001 From: Martin Hujer Date: Fri, 4 Aug 2017 17:47:58 +0200 Subject: [PATCH 16/22] build setup --- .travis.yml | 5 +---- composer.json | 4 ++++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7b894ea..6a7d4cd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,10 +13,7 @@ before_script: script: - mkdir -p build/logs - - composer test - - # phpcs only on latest PHP - - if [[ $TRAVIS_PHP_VERSION = '7.1' ]]; then composer phpcs; fi + - composer ci after_script: - php vendor/bin/coveralls -v diff --git a/composer.json b/composer.json index 6ea6a86..adba53f 100644 --- a/composer.json +++ b/composer.json @@ -36,6 +36,10 @@ } }, "scripts": { + "ci": [ + "@phpcs", + "@test" + ], "test": "phpunit", "phpcs": "phpcs --standard=PSR2 src && phpcs --standard=PSR2 tests" } From fe440487bc5c3623fc87effa68d9d8dbb941e693 Mon Sep 17 00:00:00 2001 From: Martin Hujer Date: Fri, 4 Aug 2017 17:52:51 +0200 Subject: [PATCH 17/22] PHPUnit 6.3 --- composer.json | 2 +- phpunit.xml.dist | 3 +-- tests/FioApi/AccountTest.php | 2 +- tests/FioApi/DownloaderTest.php | 2 +- tests/FioApi/TransactionListTest.php | 2 +- tests/FioApi/TransactionTest.php | 2 +- tests/FioApi/UrlBuilderTest.php | 2 +- 7 files changed, 7 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index adba53f..b44cbdc 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "guzzlehttp/guzzle": "~6.1" }, "require-dev": { - "phpunit/phpunit": "~5.7", + "phpunit/phpunit": "~6.3", "squizlabs/php_codesniffer": "~2.7", "satooshi/php-coveralls": "^1.0" }, diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 4791e7b..700340d 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -2,10 +2,9 @@ Date: Fri, 4 Aug 2017 17:54:03 +0200 Subject: [PATCH 18/22] PHP_CodeSniffer 3.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b44cbdc..c0fd32c 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ }, "require-dev": { "phpunit/phpunit": "~6.3", - "squizlabs/php_codesniffer": "~2.7", + "squizlabs/php_codesniffer": "~3.0", "satooshi/php-coveralls": "^1.0" }, "suggest": { From 50f8d0906fd717c53ac4079155a582d7dbaf3f3c Mon Sep 17 00:00:00 2001 From: Martin Hujer Date: Fri, 4 Aug 2017 17:48:01 +0200 Subject: [PATCH 19/22] [travis] PHP 7.2 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 6a7d4cd..e6a836b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: php php: - 7.1 + - 7.2 env: matrix: From 0cd4b7907e7101cd4317a92aaf891394d095bc79 Mon Sep 17 00:00:00 2001 From: Martin Hujer Date: Fri, 4 Aug 2017 18:39:47 +0200 Subject: [PATCH 20/22] Release 4.0.0 --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8a47138..e068ee9 100644 --- a/README.md +++ b/README.md @@ -40,10 +40,10 @@ Martin Hujer - - Changelog ---------- -## 4.0.0 (201X-XX-XX) -- minimal supported version is PHP 7.1 -- `DateTime` replaced with `DateTimeImmutable` (or `DateTimeInterface`) -- strict types and primitive typehints are used everywhere +## 4.0.0 (2017-08-04) +- [#9](https://github.com/mhujer/fio-api-php/pull/9) minimal supported version is PHP 7.1 +- [#9](https://github.com/mhujer/fio-api-php/pull/9)`DateTime` replaced with `DateTimeImmutable` (or `DateTimeInterface`) +- [#9](https://github.com/mhujer/fio-api-php/pull/9) strict types and primitive typehints are used everywhere ## 3.0.0 (2016-11-24) - dropped support for PHP <7 From 4cfa500a7afe11c8b6d806992f59ed02d9a0be99 Mon Sep 17 00:00:00 2001 From: Petr Soukup Date: Tue, 8 Aug 2017 14:22:25 +0200 Subject: [PATCH 21/22] handle empty transaction list --- src/FioApi/TransactionList.php | 8 +++---- tests/FioApi/TransactionListTest.php | 17 ++++++++++++++ tests/FioApi/data/example-empty-response.json | 23 +++++++++++++++++++ 3 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 tests/FioApi/data/example-empty-response.json diff --git a/src/FioApi/TransactionList.php b/src/FioApi/TransactionList.php index 4bbb9c6..5ed1e94 100644 --- a/src/FioApi/TransactionList.php +++ b/src/FioApi/TransactionList.php @@ -37,8 +37,8 @@ protected function __construct( float $closingBalance, \DateTimeImmutable $dateStart, \DateTimeImmutable $dateEnd, - float $idFrom, - float $idTo, + ?float $idFrom, + ?float $idTo, ?int $idLastDownload, Account $account ) { @@ -112,12 +112,12 @@ public function getDateEnd(): \DateTimeImmutable return $this->dateEnd; } - public function getIdFrom(): float + public function getIdFrom(): ?float { return $this->idFrom; } - public function getIdTo(): float + public function getIdTo(): ?float { return $this->idTo; } diff --git a/tests/FioApi/TransactionListTest.php b/tests/FioApi/TransactionListTest.php index 90c7447..39b817b 100644 --- a/tests/FioApi/TransactionListTest.php +++ b/tests/FioApi/TransactionListTest.php @@ -21,4 +21,21 @@ public function testTransactionListValuesAreProperlySet() $this->assertInstanceOf(Account::class, $transactionList->getAccount()); $this->assertInstanceOf(Transaction::class, $transactionList->getTransactions()[0]); } + + public function testEmptyTransactionList() + { + $transactionList = json_decode(file_get_contents(__DIR__ . '/data/example-empty-response.json')); + + $transactionList = TransactionList::create($transactionList->accountStatement); + + $this->assertSame(0.0, $transactionList->getOpeningBalance()); + $this->assertSame(0.0, $transactionList->getClosingBalance()); + $this->assertEquals(new \DateTimeImmutable('2017-08-06+0200'), $transactionList->getDateStart()); + $this->assertEquals(new \DateTimeImmutable('2017-08-08+0200'), $transactionList->getDateEnd()); + $this->assertNull($transactionList->getIdFrom()); + $this->assertNull($transactionList->getIdTo()); + $this->assertNull($transactionList->getIdLastDownload()); + $this->assertInstanceOf(Account::class, $transactionList->getAccount()); + $this->assertCount(0, $transactionList->getTransactions()); + } } diff --git a/tests/FioApi/data/example-empty-response.json b/tests/FioApi/data/example-empty-response.json new file mode 100644 index 0000000..fccd0d8 --- /dev/null +++ b/tests/FioApi/data/example-empty-response.json @@ -0,0 +1,23 @@ +{ + "accountStatement": { + "info": { + "accountId": "260000000", + "bankId": "2010", + "currency": "EUR", + "iban": "CZ652010000000000", + "bic": "FIOBCZPPXXX", + "openingBalance": 0.00, + "closingBalance": 0.00, + "dateStart": "2017-08-06+0200", + "dateEnd": "2017-08-08+0200", + "yearList": null, + "idList": null, + "idFrom": null, + "idTo": null, + "idLastDownload": null + }, + "transactionList": { + "transaction": [] + } + } +} From 0aae50b7f022b8d99ad3573d7532e7fe010ec080 Mon Sep 17 00:00:00 2001 From: Martin Hujer Date: Wed, 9 Aug 2017 09:04:10 +0200 Subject: [PATCH 22/22] Release 4.0.1 --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index e068ee9..0f0eee1 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,9 @@ Martin Hujer - - Changelog ---------- +## 4.0.1 (2017-08-09) +- [#12](https://github.com/mhujer/fio-api-php/pull/12) handle empty transaction list (thx @soukicz!) + ## 4.0.0 (2017-08-04) - [#9](https://github.com/mhujer/fio-api-php/pull/9) minimal supported version is PHP 7.1 - [#9](https://github.com/mhujer/fio-api-php/pull/9)`DateTime` replaced with `DateTimeImmutable` (or `DateTimeInterface`)