Skip to content

Commit

Permalink
Fio: php7.1+, type hint, nette 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
h4kuna committed Feb 21, 2019
1 parent 589fec4 commit 5390288
Show file tree
Hide file tree
Showing 82 changed files with 2,154 additions and 1,263 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.gitattributes export-ignore
.gitignore export-ignore
.travis.yml export-ignore
changelog.md export-ignore
tests export-ignore
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/.idea/
/nbproject/
/vendor/
composer.lock
*~
/tests/**/output/
/tests/origin/account.ini
/tests/origin/account.ini
/coverage.html
13 changes: 8 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
language: php
php:
- 5.5
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3
- 7.4

matrix:
allow_failures:
- php: 7.4

before_script:
- composer self-update
- if [ "$TRAVIS_PHP_VERSION" == "7.1" ]; then NTESTER_FLAGS="phpdbg --coverage ./coverage.xml --coverage-src ./src"; else TESTER_FLAGS=""; fi
- if [ "$TRAVIS_PHP_VERSION" == "7.3" ]; then NTESTER_FLAGS="phpdbg --coverage ./coverage.xml --coverage-src ./src"; else TESTER_FLAGS=""; fi


after_script:
- if [ "$TRAVIS_PHP_VERSION" == "7.1" ]; then
- if [ "$TRAVIS_PHP_VERSION" == "7.3" ]; then
wget https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar
&& php coveralls.phar --verbose --config tests/.coveralls.yml
|| true;
Expand Down
50 changes: 27 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
Fio
=====
# Fio

[![Build Status](https://travis-ci.org/h4kuna/fio.svg?branch=master)](https://travis-ci.org/h4kuna/fio)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/h4kuna/fio/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/h4kuna/fio/?branch=master)
[![Downloads this Month](https://img.shields.io/packagist/dm/h4kuna/fio.svg)](https://packagist.org/packages/h4kuna/fio)
[![Latest stable](https://img.shields.io/packagist/v/h4kuna/fio.svg)](https://packagist.org/packages/h4kuna/fio)
[![Coverage Status](https://coveralls.io/repos/github/h4kuna/fio/badge.svg?branch=master)](https://coveralls.io/github/h4kuna/fio?branch=master)

Support [Fio API](http://www.fio.sk/docs/cz/API_Bankovnictvi.pdf). Default read via json file.
Support [Fio API](http://www.fio.sk/docs/cz/API_Bankovnictvi.pdf). Read is provided via json file.

### Versions

Require PHP 5.5+. For older PHP 5.3+ let's use stable [version 1.2.1](https://github.com/h4kuna/fio/releases/tag/v1.2.1).
Here is [changlog](changelog.md)

- PHP 7.1+ let's use version 2.0+
- PHP 5.5 - 7.0 let's use stable [version 1.3.5](https://github.com/h4kuna/fio/releases/tag/v1.3.5).
- PHP 5.3 - 5.4 let's use stable [version 1.2.1](https://github.com/h4kuna/fio/releases/tag/v1.2.1).

> Note: php 7.1 [has bug](https://bugs.php.net/bug.php?id=72567) with float number and json_encode, therefore all float numbers are retyping to sting.
Nette framework
---------------
### Nette framework
Follow this [extension](//github.com/h4kuna/fio-nette).


Installation to project
-----------------------
### Installation to project

The best way to install h4kuna/fio is using Composer:
```sh
$ composer require h4kuna/fio
```

How to use
---------------
### How to use
Here is [example](tests/origin/FioTest.php) and run via cli. This script require account.ini in same directory, whose looks like.

```ini
[my-account]
account = 123456789
Expand All @@ -37,8 +42,7 @@ account = 987654321
token = zyxuvtsrfd
```

### FioFactory
This object help you create instances of FioPay and FioRead.
FioFactory class help you create instances of classes FioPay and FioRead.

```php
use h4kuna\Fio;
Expand All @@ -53,13 +57,13 @@ $fioFactory = new Fio\Utils\FioFactory([
]
]);

$fioRead = $fioFactory->createFioRead('my-alias');
$fioPay = $fioFactory->createFioPay('next-alias');
$fioRead = $fioFactory->createFioRead('my-account');
$fioPay = $fioFactory->createFioPay('wife-account');
```

Reading
=======
### Read range between date.
## Reading

#### Read range between date.

```php
use h4kuna\Fio;
Expand All @@ -78,15 +82,15 @@ foreach ($list as $transaction) {
var_dump($list->getInfo());
```

### You can download transaction by id of year.
#### You can download transaction by id of year.
```php
use h4kuna\Fio;
/* @var $fioRead Fio\FioRead */
/* @var $list Fio\Response\Read\TransactionList */
$list = $fioRead->movementId(2, 2015); // second transaction of year 2015
```

### Very useful method where download last transactions.
#### Very useful method where download last transactions.
After download it automaticaly set new break point.
```php
use h4kuna\Fio;
Expand All @@ -97,7 +101,7 @@ $list = $fioRead->lastDownload();
var_dump($list->getInfo()->idLastDownload);
```

### Change your break point.
#### Change your break point.
By date.
```php
$fioRead->setLastDate('1986-12-30');
Expand All @@ -112,7 +116,7 @@ $list = $fioRead->lastDownload();
var_dump($list->getInfo()->idLastDownload); // 123456789
```

### Custom Transaction class
#### Custom Transaction class
By default is h4kuna\Fio\Response\Read\Transaction if you want other names for properties. Let's define as second parameter to FioFactory.


Expand Down Expand Up @@ -140,8 +144,8 @@ $fioFactory = new Utils\FioFactory([/* ... */], 'MyTransaction');
```


Payment (writing)
=============
## Payment (writing)

Api has three response languages, default is set **cs**. For change:
```php
/* @var $fioPay h4kuna\Fio\FioPay */
Expand Down
9 changes: 9 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Fio

### v 2.0
- support only php 7.1+
- exceptions move and rename from `h4kuna\Fio\<name>Exception` to `h4kuna\Fio\Exceptions\<name>`
- add type hint for methods and parameters
- add to files declare(strict_types=1)
- change interface API `h4kuna\Fio\Response\Pay\IResponse` remove prefix `get`
- add `Log` for request pay xml
57 changes: 31 additions & 26 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
{
"name": "h4kuna/fio",
"type": "library",
"description": "Read JSON file from Fio bank and can send request.",
"homepage": "https://github.com/h4kuna/fio",
"license": "MIT",
"authors": [
{
"name": "Milan Matějček",
"email": "[email protected]",
"role": "Developer"
}
],
"require": {
"guzzlehttp/guzzle": "^6.0",
"nette/safe-stream": "^2.0",
"nette/utils": "^2.2"
},
"autoload": {
"psr-4": {
"h4kuna\\Fio\\": "src/"
},
"files": ["src/exceptions.php"]
},
"require-dev": {
"salamium/testinium": "^0.1"
}
"name": "h4kuna/fio",
"type": "library",
"description": "Read JSON file from Fio bank and can send request.",
"homepage": "https://github.com/h4kuna/fio",
"license": "MIT",
"authors": [
{
"name": "Milan Matějček",
"email": "[email protected]",
"role": "Developer"
}
],
"require": {
"php-64bit": ">=7.1",
"ext-mbstring": "*",
"ext-xmlwriter": "*",
"ext-simplexml": "*",
"guzzlehttp/guzzle": "^6.0",
"nette/safe-stream": "^2.4",
"nette/utils": "^2.0 || ^3.0"
},
"autoload": {
"psr-4": {
"h4kuna\\Fio\\": ["src/", "tests/src/"],
"h4kuna\\Fio\\Test\\": ["tests/data/"]
}
},
"require-dev": {
"salamium/testinium": "^0.1",
"phpstan/phpstan": "^0.11.1"
}
}
55 changes: 26 additions & 29 deletions src/Account/AccountCollection.php
Original file line number Diff line number Diff line change
@@ -1,67 +1,64 @@
<?php
<?php declare(strict_types=1);

namespace h4kuna\Fio\Account;

use h4kuna\Fio\AccountException;
use h4kuna\Fio\Exceptions;

/**
* @author Tomáš Jacík
* @author Milan Matějček
*/
class AccountCollection implements \Countable, \IteratorAggregate
{

/** @var FioAccount[] */
private $accounts = [];

/**
* @param string
* @return FioAccount
* @throws AccountException
*/
public function get($alias)

public function account(string $alias = ''): FioAccount
{
if ($alias === '') {
return $this->getDefault();
}
return $this->get($alias);
}


private function get(string $alias): FioAccount
{
if (isset($this->accounts[$alias])) {
return $this->accounts[$alias];
}
throw new AccountException('This account alias does not exists: ' . $alias);
throw new Exceptions\InvalidArgument('This account alias does not exists: ' . $alias);
}

/** @return FioAccount|FALSE */
public function getDefault()

private function getDefault(): FioAccount
{
if ($this->accounts === []) {
throw new Exceptions\InvalidState('Missing account, let\'s fill in configuration.');
}
return reset($this->accounts);
}

/**
* @param string $alias
* @param FioAccount $account
* @return self
*/
public function addAccount($alias, FioAccount $account)

public function addAccount(string $alias, FioAccount $account): AccountCollection
{
if (isset($this->accounts[$alias])) {
throw new AccountException('This alias already exists: ' . $alias);
throw new Exceptions\InvalidArgument('This alias already exists: ' . $alias);
}

$this->accounts[$alias] = $account;
return $this;
}

/**
* Returns items count.
* @return int
*/
public function count()

public function count(): int
{
return count($this->accounts);
}

/**
* Returns an iterator over all items.
* @return \ArrayIterator
*/
public function getIterator()

public function getIterator(): \ArrayIterator
{
return new \ArrayIterator($this->accounts);
}
Expand Down
18 changes: 5 additions & 13 deletions src/Account/AccountCollectionFactory.php
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
<?php
<?php declare(strict_types=1);

namespace h4kuna\Fio\Account;

use h4kuna\Fio\AccountException;
use h4kuna\Fio\Exceptions;

/**
* @author Milan Matějček
*/
class AccountCollectionFactory
{

/**
* @param array $accounts
* @return AccountCollection
* @throws AccountException
*/
public static function create(array $accounts)
public static function create(array $accounts): AccountCollection
{
$accountCollection = new AccountCollection;
foreach ($accounts as $alias => $info) {
if (!isset($info['token'])) {
throw new AccountException("Key 'token' is required for $alias.");
throw new Exceptions\InvalidArgument(sprintf('Key "token" is required for alias "%s".', $alias));
} elseif (!isset($info['account'])) {
throw new AccountException("Key 'account' is required for $alias.");
throw new Exceptions\InvalidArgument(sprintf('Key "account" is required for alias "%s".', $alias));
}
$accountCollection->addAccount($alias, new FioAccount($info['account'], $info['token']));
}
Expand Down
Loading

0 comments on commit 5390288

Please sign in to comment.