Skip to content

Commit

Permalink
refactor (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtARTs36 authored Nov 28, 2022
1 parent 6f132db commit 9e5e20d
Show file tree
Hide file tree
Showing 38 changed files with 903 additions and 164 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.gitignore export-ignore
.gitattributes export-ignore
.php-cs-fixer.php export-ignore
44 changes: 44 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Testing

on:
push:
branches: [ master, 'up' ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- uses: nanasess/setup-php@v3.3.2
with:
php-version: '8.1'

- name: Validate composer.json
run: composer validate

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v2
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}-2
restore-keys: |
${{ runner.os }}-php-
- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer install --no-progress --no-suggest

- name: Lint
run: composer lint

- name: Stat Analyse
run: composer stat-analyse

- name: Test
run: composer test
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/composer.lock
/vendor/
/.phpunit.result.cache
/.php-cs-fixer.cache
30 changes: 30 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

$finder = PhpCsFixer\Finder::create()->in(['src', 'tests']);

return (new \PhpCsFixer\Config())
->registerCustomFixers([
new \ArtARTs36\PhpCsFixerGoodFixers\Fixer\InterfaceMethodPhpDocSummaryFixer(),
new \ArtARTs36\PhpCsFixerGoodFixers\Fixer\DisableFunctionFixer(),
new \ArtARTs36\PhpCsFixerGoodFixers\Fixer\LaravelCommandNoEmptyDescriptionFixer(),
])
->setRules([
'full_opening_tag' => true,
'not_operator_with_successor_space' => true,
'trailing_comma_in_multiline' => true,
'no_multiline_whitespace_around_double_arrow' => true,
'array_indentation' => true,
'binary_operator_spaces' => [
'operators' => [
'=' => 'single_space',
'=>' => null,
'|' => null,
],
],
'@PSR12' => true,
'PhpCsFixerGoodFixers/interface_method_php_doc_summary' => true,
'PhpCsFixerGoodFixers/disable_function' => true,
'PhpCsFixerGoodFixers/laravel_command_no_empty_description' => true,
'mb_str_functions' => true,
])
->setFinder($finder);
37 changes: 37 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
## Laravel RuCurrency

![PHP Composer](https://github.com/ArtARTs36/laravel-ru-currency/workflows/Testing/badge.svg?branch=master)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
<a href="https://poser.pugx.org/artarts36/laravel-ru-currency/d/total.svg">
<img src="https://poser.pugx.org/artarts36/laravel-ru-currency/d/total.svg" alt="Total Downloads">
</a>

This package provides currencies with courses For Laravel

## Installation

1. Run: `composer require artarts36/laravel-ru-currency`
2. Add provider `ArtARTs36\LaravelRuCurrency\Provider\CurrencyProvider::class` into your providers in app.php
3. Run: `php artisan migrate`
4. Run: `php artisan db:seed --class="\ArtARTs36\LaravelRuCurrency\Database\Seeders\RuCurrencySeeder"`
5. Run: `php artisan ru-currency:fetch-courses`

If you see the error `Target [Psr\Http\Client\ClientInterface] is not instantiable while building [ArtARTs36\LaravelRuCurrency\Operation\Course\Fetcher\CourseFetcher, ArtARTs36\CbrCourseFinder\Finder]`, then add the following line to your provider:
```php
$this->app->bind(ClientInterface::class, \GuzzleHttp\Client::class);
```

## Commands for Application

| Command | Description |
|---------------------------------------------|------------------------------|
| ru-currency:fetch-courses | Fetch actual courses |
| ru-currency:fetch-courses --date=2020-02-03 | Fetch actual courses at date |

## Development Console

| Command | Description |
|-----------------------|------------------------------------|
| composer lint | Check code on PSR (PHP CS Sniffer) |
| composer stat-analyse | Run stat-analyse (PHPStan) |
| composer test | Run tests (PHPUnit) |
46 changes: 32 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,43 @@
"name": "artarts36/laravel-ru-currency",
"description": "Laravel Rus Currency",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "ArtARTs36",
"email": "temicska99@mail.ru"
}
],
"require": {
"php": "^7.4 | ^8.0",
"artarts36/cbr-course-finder": "^1.1",
"illuminate/database": "^8",
"illuminate/support": "^8",
"illuminate/console": "^8",
"illuminate/config": "^8"
"php": "^8.1",
"artarts36/cbr-course-finder": "^2.0.0",
"illuminate/database": "^9",
"illuminate/support": "^9",
"illuminate/console": "^9",
"illuminate/config": "^9"
},
"require-dev": {
"nunomaduro/larastan": "^2.2",
"artarts36/php-cs-fixer-good-fixers": "^0.1.2",
"orchestra/testbench": "^7.14",
"guzzlehttp/guzzle": "^7.5"
},
"license": "MIT",
"autoload": {
"psr-4": {
"ArtARTs36\\LaravelRuCurrency\\": "src/",
"ArtARTs36\\LaravelRuCurrency\\Database\\": "database"
"ArtARTs36\\LaravelRuCurrency\\Database\\": "database",
"ArtARTs36\\LaravelRuCurrency\\Tests\\": "tests"
}
},
"authors": [
{
"name": "ArtARTs36",
"email": "temicska99@mail.ru"
}
]
"scripts": {
"lint": [
"php-cs-fixer fix --dry-run --verbose --diff --ansi --allow-risky=yes"
],
"test": [
"vendor/phpunit/phpunit/phpunit"
],
"stat-analyse": [
"./vendor/bin/phpstan analyse --memory-limit=2G"
]
}
}
2 changes: 1 addition & 1 deletion config/ru_currency.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use ArtARTs36\CbrCourseFinder\CurrencyCode;
use ArtARTs36\CbrCourseFinder\Data\CurrencyCode;

return [
'default' => CurrencyCode::ISO_RUB,
Expand Down
9 changes: 5 additions & 4 deletions database/Seeders/RuCurrencySeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

namespace ArtARTs36\LaravelRuCurrency\Database\Seeders;

use ArtARTs36\CbrCourseFinder\CurrencyCode;
use ArtARTs36\LaravelRuCurrency\Models\Currency;
use ArtARTs36\CbrCourseFinder\Data\CurrencyCode;
use ArtARTs36\LaravelRuCurrency\Contracts\CurrencyRepository;
use ArtARTs36\LaravelRuCurrency\Model\Currency;
use Illuminate\Database\Seeder;

class RuCurrencySeeder extends Seeder
{
public function run(): void
public function run(CurrencyRepository $currencies): void
{
Currency::query()->insert([
$currencies->insert([
[
Currency::FIELD_ISO_CODE => CurrencyCode::ISO_RUB,
Currency::FIELD_TITLE => 'Российский рубль',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateMoneyCurrenciesTable extends Migration
class CreateRuCurrencyCurrenciesTable extends Migration
{
/**
* Run the migrations.
Expand All @@ -13,7 +13,7 @@ class CreateMoneyCurrenciesTable extends Migration
*/
public function up()
{
Schema::create('money__currencies', function (Blueprint $table) {
Schema::create('ru_currency__currencies', function (Blueprint $table) {
$table->id();
$table->string('title', 75);
$table->string('iso_code', 3)->unique()->index();
Expand All @@ -28,6 +28,6 @@ public function up()
*/
public function down()
{
Schema::dropIfExists('money__currencies');
Schema::dropIfExists('ru_currency__currencies');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateMoneyCoursesTable extends Migration
class CreateRuCurrencyCoursesTable extends Migration
{
/**
* Run the migrations.
Expand All @@ -13,14 +13,14 @@ class CreateMoneyCoursesTable extends Migration
*/
public function up()
{
Schema::create('money__courses', function (Blueprint $table) {
Schema::create('ru_currency__courses', function (Blueprint $table) {
$table->id();

$table->unsignedBigInteger('from_currency_id');
$table->foreign('from_currency_id')->on('money__currencies')->references('id');
$table->foreign('from_currency_id')->on('ru_currency__currencies')->references('id');

$table->unsignedBigInteger('to_currency_id');
$table->foreign('to_currency_id')->on('money__currencies')->references('id');
$table->foreign('to_currency_id')->on('ru_currency__currencies')->references('id');

$table->integer('nominal');
$table->float('value');
Expand All @@ -38,6 +38,6 @@ public function up()
*/
public function down()
{
Schema::dropIfExists('money__courses');
Schema::dropIfExists('ru_currency__courses');
}
}
13 changes: 13 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
includes:
- ./vendor/nunomaduro/larastan/extension.neon

parameters:

paths:
- src

level: 8

checkMissingIterableValueType: false

checkGenericClassInNonGenericObjectType: false
23 changes: 23 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" backupStaticAttributes="false" colors="true" verbose="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
<testsuites>
<testsuite name=":service_name Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<php>
<env name="APP_ENV" value="testing"/>
<env name="BCRYPT_ROUNDS" value="4"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="MAIL_DRIVER" value="array"/>
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
</php>
</phpunit>
8 changes: 8 additions & 0 deletions src/Contracts/CourseCreatingException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace ArtARTs36\LaravelRuCurrency\Contracts;

interface CourseCreatingException extends \Throwable
{
//
}
15 changes: 15 additions & 0 deletions src/Contracts/CourseCreator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace ArtARTs36\LaravelRuCurrency\Contracts;

use ArtARTs36\CbrCourseFinder\Data\CourseBag;

interface CourseCreator
{
/**
* Create courses from external data.
* @return int - count of created courses
* @throws CourseCreatingException
*/
public function create(CourseBag $courses): int;
}
15 changes: 15 additions & 0 deletions src/Contracts/CourseFetcher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace ArtARTs36\LaravelRuCurrency\Contracts;

use ArtARTs36\CbrCourseFinder\Contracts\SearchException;

interface CourseFetcher
{
/**
* Fetch courses at date.
* @throws CourseCreatingException
* @throws SearchException
*/
public function fetchAt(\DateTimeInterface $date): int;
}
12 changes: 12 additions & 0 deletions src/Contracts/CourseRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace ArtARTs36\LaravelRuCurrency\Contracts;

interface CourseRepository
{
/**
* Insert courses.
* @param array<array<string, mixed>> $values
*/
public function insertOrIgnore(array $values): int;
}
17 changes: 16 additions & 1 deletion src/Contracts/CurrencyRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,26 @@

namespace ArtARTs36\LaravelRuCurrency\Contracts;

use ArtARTs36\LaravelRuCurrency\Model\Currency;
use Illuminate\Support\Collection;

interface CurrencyRepository
{
public function pluck(string $key, string $value): Collection;
/**
* Map id on iso_code.
* @return Collection<string, int>
*/
public function mapIdOnIsoCode(): Collection;

/**
* Get all currencies.
* @return Collection<Currency>
*/
public function all(): Collection;

/**
* Insert currencies.
* @param array<array<string, mixed>> $values
*/
public function insert(array $values): void;
}
Loading

0 comments on commit 9e5e20d

Please sign in to comment.