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" 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: 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 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" + } + } + ] +} diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 3838cce..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. @@ -10,10 +21,17 @@ 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 ->setRules([ '@Symfony' => true, 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/ diff --git a/composer.json b/composer.json index 93e1701..7c726e4 100644 --- a/composer.json +++ b/composer.json @@ -10,20 +10,18 @@ ], "authors": [ { - "name": "Guillaume Sainthillier", - "email": "guillaume@silarhi.fr" - }, - { - "name": "Rémy Roussel", - "email": "remy@silarhi.fr" + "name": "SILARHI", + "email": "hello@silarhi.fr" } ], "require": { - "php": "^7.2 || ^8" + "php": ">= 8.0" }, "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": "^9.5.10", + "phpstan/phpstan": "^1.10", + "rector/rector": "^1.0" }, "autoload": { "psr-4": { 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/rector.php b/rector.php new file mode 100644 index 0000000..90acaa4 --- /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_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 { 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(); diff --git a/tests/Parser/PaymentSlipParserTest.php b/tests/Parser/PaymentSlipParserTest.php index f82c46e..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; @@ -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,39 +35,41 @@ 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 } }