Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App update #1

Merged
merged 15 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -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"
4 changes: 2 additions & 2 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ on:
pull_request:
push:
branches:
- 'refs/pull/*'
- 'main'
- "refs/pull/*"
- "main"

jobs:
matrix:
Expand Down
48 changes: 0 additions & 48 deletions .github/workflows/phpcs.yml

This file was deleted.

11 changes: 11 additions & 0 deletions .laminas-ci.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"additional_checks": [
{
"name": "PHPStan",
"job": {
"command": "./vendor/bin/phpstan analyse",
"php": "8.2"
}
}
]
}
22 changes: 20 additions & 2 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php

declare(strict_types=1);

/*
* This file is part of the CAF Parser package.
*
* (c) SILARHI <[email protected]>
*
* 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.

Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/
16 changes: 7 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,18 @@
],
"authors": [
{
"name": "Guillaume Sainthillier",
"email": "[email protected]"
},
{
"name": "Rémy Roussel",
"email": "[email protected]"
"name": "SILARHI",
"email": "[email protected]"
}
],
"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": {
Expand Down
5 changes: 5 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
level: 8
paths:
- src
- tests
31 changes: 31 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

/*
* This file is part of the CAF Parser package.
*
* (c) SILARHI <[email protected]>
*
* 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,
]);
};
2 changes: 1 addition & 1 deletion src/Model/PaymentSlip.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class PaymentSlip
{
/** @var PaymentSlipLine[] */
private $lines = [];
private array $lines = [];

public function addLine(PaymentSlipLine $line): self
{
Expand Down
24 changes: 8 additions & 16 deletions src/Model/PaymentSlipLine.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
3 changes: 2 additions & 1 deletion src/Parser/PaymentSlipParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Silarhi\Caf\Parser;

use function count;

use DateTime;
use DateTimeInterface;
use Silarhi\Caf\Exceptions\ParseException;
Expand All @@ -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();
Expand Down
36 changes: 19 additions & 17 deletions tests/Parser/PaymentSlipParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,63 +11,65 @@
* 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;
use Silarhi\Caf\Parser\PaymentSlipParser;

class PaymentSlipParserTest extends TestCase
{
public function testEmptyInput()
public function testEmptyInput(): void
{
$this->expectException(ParseException::class);

$parser = new PaymentSlipParser();
$parser->parse('');
}

public function testUnexpectedInput()
public function testUnexpectedInput(): void
{
$this->expectException(ParseException::class);

$parser = new PaymentSlipParser();
$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
}
}