-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3a78884
Showing
17 changed files
with
402 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
service_name: travis-ci | ||
coverage_clover: build/clover.xml | ||
json_path: build/coveralls.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Path-based git attributes | ||
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html | ||
|
||
# Ignore all test and documentation with "export-ignore". | ||
/.gitattributes export-ignore | ||
/.gitignore export-ignore | ||
/.travis.yml export-ignore | ||
/phpunit.xml.dist export-ignore | ||
/.scrutinizer.yml export-ignore | ||
/tests export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: tests | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: true | ||
matrix: | ||
php: [7.4,] | ||
laravel: [7.*] | ||
dependency-version: [prefer-lowest, prefer-stable] | ||
include: | ||
- laravel: 7.* | ||
testbench: 5.* | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v1 | ||
|
||
- name: Cache dependencies | ||
uses: actions/cache@v1 | ||
with: | ||
path: ~/.composer/cache/files | ||
key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v1 | ||
with: | ||
php-version: ${{ matrix.php }} | ||
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick | ||
coverage: none | ||
|
||
- name: Install dependencies | ||
run: | | ||
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update | ||
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest | ||
- name: Execute tests | ||
run: vendor/bin/phpunit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
build | ||
composer.lock | ||
vendor | ||
html | ||
build | ||
coverage.clover |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
$finder = Symfony\Component\Finder\Finder::create() | ||
->notPath('bootstrap/*') | ||
->notPath('storage/*') | ||
->notPath('vendor') | ||
->in([ | ||
__DIR__ . '/src', | ||
__DIR__ . '/tests' | ||
]) | ||
->name('*.php') | ||
->notName('*.blade.php') | ||
->ignoreDotFiles(true) | ||
->ignoreVCS(true); | ||
|
||
return PhpCsFixer\Config::create() | ||
->setRules([ | ||
'@PSR2' => true, | ||
'array_syntax' => ['syntax' => 'short'], | ||
'ordered_imports' => ['sortAlgorithm' => 'alpha'], | ||
'no_unused_imports' => true, | ||
'not_operator_with_successor_space' => true, | ||
'trailing_comma_in_multiline_array' => true, | ||
'phpdoc_scalar' => true, | ||
'unary_operator_spaces' => true, | ||
'binary_operator_spaces' => true, | ||
'blank_line_before_statement' => [ | ||
'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'], | ||
], | ||
'phpdoc_single_line_var_spacing' => true, | ||
'phpdoc_var_without_name' => true, | ||
'class_attributes_separation' => [ | ||
'elements' => [ | ||
'method', 'property', | ||
], | ||
], | ||
'method_argument_space' => [ | ||
'on_multiline' => 'ensure_fully_multiline', | ||
'keep_multiple_spaces_after_comma' => true, | ||
] | ||
]) | ||
->setFinder($finder); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
preset: laravel | ||
|
||
disabled: | ||
- single_class_element_per_statement | ||
- self_accessor | ||
|
||
finder: | ||
exclude: | ||
- "tests/stubs" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Changelog | ||
|
||
|
||
## Version 0.0.1 | ||
|
||
### Added | ||
- ``` BNR::exchange('currency','date')``` - return exchange rate for selected currency and date at NBR (National Bank of Romania) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"name": "andalisolutions/laravel-bnr", | ||
"description": "Web service for verifying taxpayers who are registered according to art. 316 of the Romanian Fiscal Code", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Andrei Ciungulete", | ||
"email": "andrei.ciungulete@andali.ro", | ||
"homepage": "http://www.andali.ro", | ||
"role" : "developer" | ||
} | ||
], | ||
"homepage": "https://github.com/andalisolutions/laravel-bnr", | ||
"keywords": ["Laravel", "Laravel BNR", "BNR"], | ||
"require": { | ||
"illuminate/support": "^7.0", | ||
"ext-json" : "*", | ||
"guzzlehttp/guzzle": "^6.5", | ||
"orchestra/parser": "^5.0", | ||
"friendsofphp/php-cs-fixer": "^2.16" | ||
}, | ||
"require-dev": { | ||
"mockery/mockery": "^1.0", | ||
"orchestra/testbench": "^5.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Andali\\Bnr\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Andali\\Bnr\\Tests\\": "tests" | ||
} | ||
}, | ||
"extra": { | ||
"laravel": { | ||
"providers": [ | ||
"Andali\\Bnr\\BnrServiceProvider" | ||
], | ||
"aliases": { | ||
"Bnr": "Andali\\Bnr\\Facades\\Bnr" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Contributing | ||
|
||
Contributions are welcome and will be fully credited. | ||
|
||
Contributions are accepted via Pull Requests on [Github](https://github.com/andalisolutions/laravel-anaf). | ||
|
||
## Pull Requests | ||
|
||
- **Add tests!** - Your patch won't be accepted if it doesn't have tests. | ||
|
||
- **Document any change in behaviour** - Make sure the `readme.md` and any other relevant documentation are kept up-to-date. | ||
|
||
- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option. | ||
|
||
- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. | ||
|
||
- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. | ||
|
||
|
||
**Happy coding**! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# MIT License | ||
|
||
Copyright (c) Andali Solutions <office@andali.ro> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit bootstrap="vendor/autoload.php" | ||
backupGlobals="false" | ||
backupStaticAttributes="false" | ||
colors="true" | ||
verbose="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false"> | ||
<testsuites> | ||
<testsuite name="Test Suite"> | ||
<directory suffix=".php">tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist> | ||
<directory suffix=".php">src/</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# Laravel BNR exchange rate | ||
Web Service to retrieve the exchange rate NBR | ||
|
||
[![Latest Version on Packagist][ico-version]][link-packagist] | ||
[![Build Status][ico-build]][link-build] | ||
[![StyleCI][ico-styleci]][link-styleci] | ||
[![Quality Score][ico-scrutinizer]][link-scrutinizer] | ||
[![Total Downloads][ico-downloads]][link-downloads] | ||
## Installation | ||
|
||
Via Composer | ||
|
||
``` bash | ||
$ composer require andalisolutions/laravel-bnr | ||
``` | ||
|
||
## Usage | ||
```php | ||
use Andali\Bnr\Facades\Bnr; | ||
|
||
$nbrEUR = Bnr::exchange('EUR', '2020-03-04'); | ||
or | ||
$nbrEUR = Bnr::exchange('EUR'); | ||
``` | ||
Response | ||
``` | ||
4.8057 | ||
``` | ||
|
||
## Changelog | ||
|
||
Please see the [changelog](changelog.md) for more information on what has changed recently. | ||
|
||
## Testing | ||
|
||
``` bash | ||
./vendor/bin/phpunit test | ||
``` | ||
|
||
## Contributing | ||
|
||
Please see [contributing.md](contributing.md) for details and a todolist. | ||
|
||
## Security | ||
|
||
If you discover any security related issues, please email <andrei.ciungulete@andali.ro> instead of using the issue tracker. | ||
|
||
## Credits | ||
|
||
- [Andrei Ciungulete][link-author] | ||
- [All Contributors][link-contributors] | ||
|
||
## License | ||
|
||
Please see the [license file](license.md) for more information. | ||
|
||
[ico-version]: https://img.shields.io/packagist/v/andalisolutions/laravel-bnr.svg?style=flat-square | ||
[ico-downloads]: https://img.shields.io/packagist/dt/andalisolutions/laravel-bnr.svg?style=flat-square | ||
[ico-build]: https://github.com/andalisolutions/laravel-bnr/workflows/tests/badge.svg | ||
[ico-styleci]: https://styleci.io/repos/244713925/shield | ||
[ico-scrutinizer]: https://img.shields.io/scrutinizer/g/andalisolutions/laravel-bnr.svg?style=flat-square | ||
|
||
[link-packagist]: https://packagist.org/packages/andalisolutions/laravel-bnr | ||
[link-downloads]: https://packagist.org/packages/andalisolutions/laravel-bnr | ||
[link-build]: https://github.com/andalisolutions/laravel-bnr/actions | ||
[link-styleci]: https://styleci.io/repos/245011612 | ||
[link-scrutinizer]: https://scrutinizer-ci.com/g/andalisolutions/laravel-bnr | ||
[link-author]: https://github.com/andalisolutions | ||
[link-contributors]: ../../contributors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Andali\Bnr; | ||
|
||
use Carbon\Carbon; | ||
use Illuminate\Support\Facades\Http; | ||
use Illuminate\Support\Str; | ||
|
||
class Bnr | ||
{ | ||
const API_BNR = 'https://www.bnr.ro/files/xml/curs_{{date}}.xml'; | ||
|
||
public function exchange(string $currency = 'EUR', $date = null) | ||
{ | ||
$api = Str::of(static::API_BNR)->replace('{{date}}', Carbon::parse($date)->format('Y_n_j')); | ||
$xmlString = Http::get($api)->body(); | ||
|
||
return Str::of($xmlString)->match('/<Rate currency=\"'.$currency.'\">([0-9.]*)<\/Rate>/')->__toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace Andali\Bnr; | ||
|
||
use Illuminate\Support\ServiceProvider; | ||
|
||
class BnrServiceProvider extends ServiceProvider | ||
{ | ||
public function register(): void | ||
{ | ||
$this->app->singleton('bnr', fn ($app) => new Bnr); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Andali\Bnr\Facades; | ||
|
||
use Illuminate\Support\Facades\Facade; | ||
|
||
/** | ||
* @method static string exchange(string $currency = 'EUR', $date = NULL) | ||
*/ | ||
class Bnr extends Facade | ||
{ | ||
/** | ||
* Get the registered name of the component. | ||
* | ||
* @return string | ||
*/ | ||
protected static function getFacadeAccessor() | ||
{ | ||
return 'bnr'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Andali\Bnr\Tests; | ||
|
||
use Andali\Bnr\Facades\Bnr; | ||
|
||
class BnrTests extends TestCase | ||
{ | ||
/** @test */ | ||
public function api_response_is_correct_for_eur() | ||
{ | ||
$getExchangeRate = BNR::exchange('EUR', '2020-03-03'); | ||
$this->assertEquals(4.8074, $getExchangeRate); | ||
} | ||
|
||
/** @test */ | ||
public function api_response_is_correct_for_eur_without_date() | ||
{ | ||
$getExchangeRate = BNR::exchange('EUR'); | ||
$this->assertIsString($getExchangeRate); | ||
} | ||
|
||
/** @test */ | ||
public function api_response_is_correct_for_usd() | ||
{ | ||
$getExchangeRate = BNR::exchange('USD', '2020-03-03'); | ||
$this->assertEquals(4.3263, $getExchangeRate); | ||
} | ||
} |
Oops, something went wrong.