From 89b600da83f7db4656fafb2fa3895613582ae676 Mon Sep 17 00:00:00 2001 From: Guillaume Sainthillier Date: Fri, 9 Feb 2024 11:19:48 +0100 Subject: [PATCH 01/15] append root php files to php cs fixer config --- .php-cs-fixer.dist.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 3838cce..51bcf45 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -10,8 +10,14 @@ EOF; $finder = PhpCsFixer\Finder::create() - ->in(__DIR__.'/src') - ->in(__DIR__.'/tests'); + ->in([ + __DIR__.'/src', + __DIR__.'/tests', + ]) + ->append([ + __FILE__, + __DIR__ . '/rector.php', + ]); $config = new PhpCsFixer\Config(); return $config From a18ce4a265e67ddb658904dc4e47ea104cccd92f Mon Sep 17 00:00:00 2001 From: Guillaume Sainthillier Date: Fri, 9 Feb 2024 11:20:26 +0100 Subject: [PATCH 02/15] update authors --- composer.json | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 93e1701..ed87550 100644 --- a/composer.json +++ b/composer.json @@ -10,12 +10,8 @@ ], "authors": [ { - "name": "Guillaume Sainthillier", - "email": "guillaume@silarhi.fr" - }, - { - "name": "Rémy Roussel", - "email": "remy@silarhi.fr" + "name": "SILARHI", + "email": "hello@silarhi.fr" } ], "require": { From 9f2ba24d2874c8d410c9e95c25b87a63a91eec70 Mon Sep 17 00:00:00 2001 From: Guillaume Sainthillier Date: Fri, 9 Feb 2024 11:20:49 +0100 Subject: [PATCH 03/15] remove redundant job --- .github/workflows/phpcs.yml | 48 ------------------------------------- 1 file changed, 48 deletions(-) delete mode 100644 .github/workflows/phpcs.yml diff --git a/.github/workflows/phpcs.yml b/.github/workflows/phpcs.yml deleted file mode 100644 index 0c12f29..0000000 --- a/.github/workflows/phpcs.yml +++ /dev/null @@ -1,48 +0,0 @@ -name: PHP-CS-Fixer -on: - pull_request: - push: - branches: - - 'refs/pull/*' - - 'main' - - -jobs: - run: - name: PHP-CS-Fixer ${{ matrix.php }} on ${{ matrix.os }} - runs-on: ${{ matrix.os }} - - strategy: - matrix: - os: [ ubuntu-latest ] - php: [ '8.0' ] - - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Install PHP - uses: shivammathur/setup-php@v2 - with: - coverage: none - php-version: ${{ matrix.php }} - ini-values: memory_limit=-1 - tools: composer:v2 - - - name: Determine composer cache directory - id: composer-cache - run: echo "::set-output name=directory::$(composer config cache-dir)" - - - name: Cache composer dependencies - uses: actions/cache@v2 - with: - path: ${{ steps.composer-cache.outputs.directory }} - key: ${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ matrix.php }}-composer- - - - name: Install Dependencies - run: composer update --no-progress --ansi - - - name: PHP-CS-Fixer - run: ./vendor/bin/php-cs-fixer fix --dry-run --diff \ No newline at end of file From fc26da43c74742463c07202776afc36322784b61 Mon Sep 17 00:00:00 2001 From: Guillaume Sainthillier Date: Fri, 9 Feb 2024 11:24:13 +0100 Subject: [PATCH 04/15] update php semantic version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index ed87550..b8832c7 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ } ], "require": { - "php": "^7.2 || ^8" + "php": ">= 7.2" }, "require-dev": { "friendsofphp/php-cs-fixer": "^2.18|^3.0", From 7fbdfcdb2a714e279199b04711cc1375b28fcd24 Mon Sep 17 00:00:00 2001 From: Guillaume Sainthillier Date: Fri, 9 Feb 2024 11:24:24 +0100 Subject: [PATCH 05/15] add rector --- composer.json | 1 + rector.php | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 rector.php diff --git a/composer.json b/composer.json index b8832c7..a17e42b 100644 --- a/composer.json +++ b/composer.json @@ -20,6 +20,7 @@ "require-dev": { "friendsofphp/php-cs-fixer": "^2.18|^3.0", "phpunit/phpunit": "^8.5.21|^9.5.10" + "rector/rector": "^1.0" }, "autoload": { "psr-4": { diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..9b7ca80 --- /dev/null +++ b/rector.php @@ -0,0 +1,31 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +use Rector\Config\RectorConfig; +use Rector\PHPUnit\Set\PHPUnitSetList; +use Rector\Set\ValueObject\LevelSetList; + +return static function (RectorConfig $rectorConfig): void { + $rectorConfig->paths([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]); + + $rectorConfig->importNames(); + $rectorConfig->importShortClasses(); + + $rectorConfig->sets([ + LevelSetList::UP_TO_PHP_72, + PHPUnitSetList::PHPUNIT_90, + ]); +}; From f31ec6f8b0fda0115b0f3932158f39850b17fa9c Mon Sep 17 00:00:00 2001 From: Guillaume Sainthillier Date: Fri, 9 Feb 2024 11:24:31 +0100 Subject: [PATCH 06/15] add phpstan --- .github/workflows/phpstan.yml | 50 ++++++++++++++++++++++++++ composer.json | 1 + phpstan.neon | 5 +++ tests/Parser/PaymentSlipParserTest.php | 28 +++++++++------ 4 files changed, 74 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/phpstan.yml create mode 100644 phpstan.neon diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml new file mode 100644 index 0000000..65912b9 --- /dev/null +++ b/.github/workflows/phpstan.yml @@ -0,0 +1,50 @@ +name: "PHPStan" + +on: + pull_request: + push: + branches: + - "refs/pull/*" + - 'main' + +jobs: + run: + name: PHPStan ${{ matrix.php }} on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest] + php: ["8.1"] + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + coverage: none + php-version: ${{ matrix.php }} + ini-values: memory_limit=-1 + tools: composer:v2 + + - name: Determine composer cache directory + id: composer-cache + run: | + echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + + - name: Cache composer dependencies + uses: actions/cache@v4.0.0 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ matrix.php }}-composer- + + - name: Install Dependencies + run: composer update --no-progress --ansi + + - name: PHPStan + run: ./vendor/bin/phpstan analyse diff --git a/composer.json b/composer.json index a17e42b..4557e25 100644 --- a/composer.json +++ b/composer.json @@ -20,6 +20,7 @@ "require-dev": { "friendsofphp/php-cs-fixer": "^2.18|^3.0", "phpunit/phpunit": "^8.5.21|^9.5.10" + "phpstan/phpstan": "^1.10", "rector/rector": "^1.0" }, "autoload": { diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..51e3685 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,5 @@ +parameters: + level: 8 + paths: + - src + - tests \ No newline at end of file diff --git a/tests/Parser/PaymentSlipParserTest.php b/tests/Parser/PaymentSlipParserTest.php index f82c46e..6eadba5 100644 --- a/tests/Parser/PaymentSlipParserTest.php +++ b/tests/Parser/PaymentSlipParserTest.php @@ -19,7 +19,7 @@ class PaymentSlipParserTest extends TestCase { - public function testEmptyInput() + public function testEmptyInput(): void { $this->expectException(ParseException::class); @@ -27,7 +27,7 @@ public function testEmptyInput() $parser->parse(''); } - public function testUnexpectedInput() + public function testUnexpectedInput(): void { $this->expectException(ParseException::class); @@ -35,37 +35,45 @@ public function testUnexpectedInput() $parser->parse('Lorem ipsum dolor sit amet'); } - public function testUnparseable2ndCafRow() + public function testUnparseable2ndCafRow(): void { $this->expectException(ParseException::class); $this->expectExceptionMessageMatches('/^CAF Row n°2 could not be parsed$/'); $parser = new PaymentSlipParser(); - $parser->parse(file_get_contents(__DIR__ . '/../fixtures/LA44ZZ/caf_LA44_unparseable_2nd_row.txt')); + $content = file_get_contents(__DIR__ . '/../fixtures/LA44ZZ/caf_LA44_unparseable_2nd_row.txt'); + $this->assertNotFalse($content); + $parser->parse($content); } - public function testParsing() + public function testParsing(): void { $parser = new PaymentSlipParser(); - $result = $parser->parse(file_get_contents(__DIR__ . '/../fixtures/LA44ZZ/caf_LA44.txt')); + $content = file_get_contents(__DIR__ . '/../fixtures/LA44ZZ/caf_LA44.txt'); + $this->assertNotFalse($content); + $result = $parser->parse($content); $this->assertNotNull($result); //@TODO test parsed rows & line values } - public function testParsing2() + public function testParsing2(): void { $parser = new PaymentSlipParser(); - $result = $parser->parse(file_get_contents(__DIR__ . '/../fixtures/LA44ZZ/caf_LA44_2.txt')); + $content = file_get_contents(__DIR__ . '/../fixtures/LA44ZZ/caf_LA44_2.txt'); + $this->assertNotFalse($content); + $result = $parser->parse($content); $this->assertNotNull($result); //@TODO test parsed rows & line values } - public function testParsing3() + public function testParsing3(): void { $parser = new PaymentSlipParser(); - $result = $parser->parse(file_get_contents(__DIR__ . '/../fixtures/LA44ZZ/caf_LA44_3.txt')); + $content = file_get_contents(__DIR__ . '/../fixtures/LA44ZZ/caf_LA44_3.txt'); + $this->assertNotFalse($content); + $result = $parser->parse($content); $this->assertNotNull($result); //@TODO test parsed rows & line values From a4c1deb4ef4e4a6d6a70ab09fee85d073135da92 Mon Sep 17 00:00:00 2001 From: Guillaume Sainthillier Date: Fri, 9 Feb 2024 11:24:39 +0100 Subject: [PATCH 07/15] update package versions --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 4557e25..5a74f08 100644 --- a/composer.json +++ b/composer.json @@ -18,8 +18,8 @@ "php": ">= 7.2" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^2.18|^3.0", - "phpunit/phpunit": "^8.5.21|^9.5.10" + "friendsofphp/php-cs-fixer": "^3.49", + "phpunit/phpunit": "^8.5.21|^9.5.10", "phpstan/phpstan": "^1.10", "rector/rector": "^1.0" }, From 9b3dd7eee1e8d4fb8d6cfb008c3d37dc896984c5 Mon Sep 17 00:00:00 2001 From: Guillaume Sainthillier Date: Fri, 9 Feb 2024 11:27:55 +0100 Subject: [PATCH 08/15] remove todos --- tests/Parser/PaymentSlipParserTest.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/Parser/PaymentSlipParserTest.php b/tests/Parser/PaymentSlipParserTest.php index 6eadba5..491c732 100644 --- a/tests/Parser/PaymentSlipParserTest.php +++ b/tests/Parser/PaymentSlipParserTest.php @@ -53,8 +53,6 @@ public function testParsing(): void $this->assertNotFalse($content); $result = $parser->parse($content); $this->assertNotNull($result); - - //@TODO test parsed rows & line values } public function testParsing2(): void @@ -64,8 +62,6 @@ public function testParsing2(): void $this->assertNotFalse($content); $result = $parser->parse($content); $this->assertNotNull($result); - - //@TODO test parsed rows & line values } public function testParsing3(): void @@ -75,7 +71,5 @@ public function testParsing3(): void $this->assertNotFalse($content); $result = $parser->parse($content); $this->assertNotNull($result); - - //@TODO test parsed rows & line values } } From 8ef30016d6d0aee84b92d1390644895940d2ac06 Mon Sep 17 00:00:00 2001 From: Guillaume Sainthillier Date: Fri, 9 Feb 2024 11:28:27 +0100 Subject: [PATCH 09/15] run php cs fixer --- .php-cs-fixer.dist.php | 16 ++++++++++++++-- src/Parser/PaymentSlipParser.php | 3 ++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 51bcf45..f710329 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -1,5 +1,16 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + $header = <<<'EOF' This file is part of the CAF Parser package. @@ -11,8 +22,8 @@ $finder = PhpCsFixer\Finder::create() ->in([ - __DIR__.'/src', - __DIR__.'/tests', + __DIR__ . '/src', + __DIR__ . '/tests', ]) ->append([ __FILE__, @@ -20,6 +31,7 @@ ]); $config = new PhpCsFixer\Config(); + return $config ->setRules([ '@Symfony' => true, diff --git a/src/Parser/PaymentSlipParser.php b/src/Parser/PaymentSlipParser.php index 8affef1..5450a45 100644 --- a/src/Parser/PaymentSlipParser.php +++ b/src/Parser/PaymentSlipParser.php @@ -14,6 +14,7 @@ namespace Silarhi\Caf\Parser; use function count; + use DateTime; use DateTimeInterface; use Silarhi\Caf\Exceptions\ParseException; @@ -38,7 +39,7 @@ public function parse(string $content): PaymentSlip throw new ParseException('Input CAF LA44 could not be parsed'); } - //Normalize Carriage return before splitting + // Normalize Carriage return before splitting $tableContent = str_replace("\r\n", "\n", $matches[0][1]); $paymentSlip = new PaymentSlip(); From 6e17e167d8c3676ba8c46c501d2c3a7c0410ab0a Mon Sep 17 00:00:00 2001 From: Guillaume Sainthillier Date: Fri, 9 Feb 2024 11:29:36 +0100 Subject: [PATCH 10/15] fix test namespace --- tests/Parser/PaymentSlipParserTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Parser/PaymentSlipParserTest.php b/tests/Parser/PaymentSlipParserTest.php index 491c732..0a6dab5 100644 --- a/tests/Parser/PaymentSlipParserTest.php +++ b/tests/Parser/PaymentSlipParserTest.php @@ -11,7 +11,7 @@ * with this source code in the file LICENSE. */ -namespace Silarhi\Caf\Tests\Utils; +namespace Silarhi\Caf\Tests\Parser; use PHPUnit\Framework\TestCase; use Silarhi\Caf\Exceptions\ParseException; From 6d4104a28538c4694927b1d9a8d804be7d91352b Mon Sep 17 00:00:00 2001 From: Guillaume Sainthillier Date: Fri, 9 Feb 2024 11:29:59 +0100 Subject: [PATCH 11/15] add dependabot alerts --- .github/dependabot.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..fc88e12 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,13 @@ +version: 2 +updates: + - allow: + - dependency-type: "all" + directory: "/" + package-ecosystem: "composer" + schedule: + interval: "weekly" + versioning-strategy: "increase" + - directory: "/" + package-ecosystem: "github-actions" + schedule: + interval: "weekly" From 969aac929e9bde5411435624a0d4e41b38eb07bc Mon Sep 17 00:00:00 2001 From: Guillaume Sainthillier Date: Fri, 9 Feb 2024 11:41:26 +0100 Subject: [PATCH 12/15] Drop php 7 support --- composer.json | 4 ++-- rector.php | 2 +- src/Model/PaymentSlip.php | 2 +- src/Model/PaymentSlipLine.php | 24 ++++++++---------------- 4 files changed, 12 insertions(+), 20 deletions(-) diff --git a/composer.json b/composer.json index 5a74f08..7c726e4 100644 --- a/composer.json +++ b/composer.json @@ -15,11 +15,11 @@ } ], "require": { - "php": ">= 7.2" + "php": ">= 8.0" }, "require-dev": { "friendsofphp/php-cs-fixer": "^3.49", - "phpunit/phpunit": "^8.5.21|^9.5.10", + "phpunit/phpunit": "^9.5.10", "phpstan/phpstan": "^1.10", "rector/rector": "^1.0" }, diff --git a/rector.php b/rector.php index 9b7ca80..90acaa4 100644 --- a/rector.php +++ b/rector.php @@ -25,7 +25,7 @@ $rectorConfig->importShortClasses(); $rectorConfig->sets([ - LevelSetList::UP_TO_PHP_72, + LevelSetList::UP_TO_PHP_80, PHPUnitSetList::PHPUNIT_90, ]); }; diff --git a/src/Model/PaymentSlip.php b/src/Model/PaymentSlip.php index d13d152..c8b46c2 100644 --- a/src/Model/PaymentSlip.php +++ b/src/Model/PaymentSlip.php @@ -16,7 +16,7 @@ class PaymentSlip { /** @var PaymentSlipLine[] */ - private $lines = []; + private array $lines = []; public function addLine(PaymentSlipLine $line): self { diff --git a/src/Model/PaymentSlipLine.php b/src/Model/PaymentSlipLine.php index b80377f..28c2804 100644 --- a/src/Model/PaymentSlipLine.php +++ b/src/Model/PaymentSlipLine.php @@ -17,29 +17,21 @@ class PaymentSlipLine { - /** @var string|null */ - private $reference; + private ?string $reference; - /** @var string */ - private $beneficiaryReference; + private string $beneficiaryReference; - /** @var string */ - private $beneficiaryName; + private string $beneficiaryName; - /** @var DateTimeInterface */ - private $startDate; + private DateTimeInterface $startDate; - /** @var DateTimeInterface */ - private $endDate; + private DateTimeInterface $endDate; - /** @var float */ - private $grossAmount; + private float $grossAmount; - /** @var float */ - private $deduction; + private float $deduction; - /** @var float */ - private $netAmount; + private float $netAmount; public function getReference(): ?string { From 21723f043416428868973210e892e43ff6ccc92f Mon Sep 17 00:00:00 2001 From: Guillaume Sainthillier Date: Fri, 9 Feb 2024 12:01:16 +0100 Subject: [PATCH 13/15] use laminas ci actions to run phpstan --- .github/workflows/phpstan.yml | 50 ----------------------------------- .laminas-ci.json | 11 ++++++++ 2 files changed, 11 insertions(+), 50 deletions(-) delete mode 100644 .github/workflows/phpstan.yml create mode 100644 .laminas-ci.json diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml deleted file mode 100644 index 65912b9..0000000 --- a/.github/workflows/phpstan.yml +++ /dev/null @@ -1,50 +0,0 @@ -name: "PHPStan" - -on: - pull_request: - push: - branches: - - "refs/pull/*" - - 'main' - -jobs: - run: - name: PHPStan ${{ matrix.php }} on ${{ matrix.os }} - runs-on: ${{ matrix.os }} - - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest] - php: ["8.1"] - - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Install PHP - uses: shivammathur/setup-php@v2 - with: - coverage: none - php-version: ${{ matrix.php }} - ini-values: memory_limit=-1 - tools: composer:v2 - - - name: Determine composer cache directory - id: composer-cache - run: | - echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - - - name: Cache composer dependencies - uses: actions/cache@v4.0.0 - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ matrix.php }}-composer- - - - name: Install Dependencies - run: composer update --no-progress --ansi - - - name: PHPStan - run: ./vendor/bin/phpstan analyse diff --git a/.laminas-ci.json b/.laminas-ci.json new file mode 100644 index 0000000..46a9f39 --- /dev/null +++ b/.laminas-ci.json @@ -0,0 +1,11 @@ +{ + "additional_checks": [ + { + "name": "PHPStan", + "job": { + "command": "./vendor/bin/phpstan analyse", + "php": "8.2" + } + } + ] +} From acbf3ff76c92cac84788a8717f1fd9c5773a90ce Mon Sep 17 00:00:00 2001 From: Guillaume Sainthillier Date: Fri, 9 Feb 2024 12:03:36 +0100 Subject: [PATCH 14/15] prettify yaml files --- .github/workflows/continuous-integration.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 1981e25..2556741 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -4,8 +4,8 @@ on: pull_request: push: branches: - - 'refs/pull/*' - - 'main' + - "refs/pull/*" + - "main" jobs: matrix: From 47110b4db60ee070ee74dbe461b9c8f6aba3c37e Mon Sep 17 00:00:00 2001 From: Guillaume Sainthillier Date: Fri, 9 Feb 2024 12:03:47 +0100 Subject: [PATCH 15/15] prettify readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9eb65b2..94c66e0 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,6 @@ $paymentSlip = $parser->parse('My Content'); foreach($paymentSlip->getLines() as $line) { assert($line instanceof \Silarhi\Caf\Model\PaymentSlipLine); } -``` +``` [composer]: http://getcomposer.org/