Skip to content

Commit 85af356

Browse files
authored
Merge pull request #8 from php-etl/feature/phpstan
Feature/phpstan
2 parents 723e4dc + 56efffc commit 85af356

File tree

8 files changed

+56
-1
lines changed

8 files changed

+56
-1
lines changed

.github/workflows/actions.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
with:
5555
args: --prefer-dist
5656
php_version: 8.0
57-
57+
php_extensions: xdebug zip
5858
- name: PHPStan
5959
uses: php-actions/phpstan@v2
6060
with:

src/CSV/FingersCrossed/Extractor.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ public function extract(): iterable
2727

2828
$currentLine = $this->skipLines + 1;
2929

30+
$columns = [];
31+
$columnCount = 0;
32+
$cellCount = 0;
33+
3034
/**
3135
* @var int $rowIndex
3236
* @var Row $row

src/CSV/FingersCrossed/Loader.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ public function __construct(
2525
$this->logger = $logger ?? new NullLogger();
2626
}
2727

28+
/**
29+
* @return \Generator
30+
*/
2831
public function load(): \Generator
2932
{
3033
$line = yield;

src/CSV/Safe/Extractor.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ public function extract(): iterable
2727

2828
$currentLine = $this->skipLines + 1;
2929

30+
$columns = [];
31+
$columnCount = 0;
32+
$cellCount = 0;
33+
3034
/**
3135
* @var int $rowIndex
3236
* @var Row $row

src/CSV/Safe/Loader.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ public function __construct(
2525
$this->logger = $logger ?? new NullLogger();
2626
}
2727

28+
/**
29+
* @return \Generator
30+
*/
2831
public function load(): \Generator
2932
{
3033
$line = yield;

src/Sheet/FingersCrossed/Loader.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,18 @@ public function __construct(
2424
private string $sheetName,
2525
?LoggerInterface $logger = null
2626
) {
27+
/** @phpstan-ignore-next-line */
2728
$this->writer->getCurrentSheet()->setName($this->sheetName);
2829
$this->logger = $logger ?? new NullLogger();
2930
}
3031

32+
/**
33+
* @return \Generator
34+
*/
3135
public function load(): \Generator
3236
{
3337
$line = yield;
38+
3439
$this->writer->addRow(
3540
new Row(array_map(fn ($value) => new Cell($value), array_keys($line)), null)
3641
);

src/Sheet/Safe/Loader.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,14 @@ public function __construct(
2424
private string $sheetName,
2525
?LoggerInterface $logger = null
2626
) {
27+
/** @phpstan-ignore-next-line */
2728
$this->writer->getCurrentSheet()->setName($this->sheetName);
2829
$this->logger = $logger ?? new NullLogger();
2930
}
3031

32+
/**
33+
* @return \Generator
34+
*/
3135
public function load(): \Generator
3236
{
3337
$line = yield;

tests/functional/CSV/Safe/LoaderTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Kiboko\Component\PHPUnitExtension\PipelineAssertTrait;
88
use Kiboko\Component\Flow\Spreadsheet\CSV\Safe\Loader;
99
use PHPUnit\Framework\TestCase;
10+
use Psr\Log\Test\TestLogger;
1011
use Vfs\FileSystem;
1112

1213
final class LoaderTest extends TestCase
@@ -60,4 +61,35 @@ public function testLoadCsvSuccessful()
6061
new Loader($this->writer)
6162
);
6263
}
64+
65+
public function testLoadCsvWithLogger()
66+
{
67+
$this->writer->openToFile('vfs://test.csv');
68+
69+
$this->assertPipelineLoadsLike(
70+
[
71+
[
72+
'first name' => 'john',
73+
'last name' => 'doe',
74+
],
75+
[
76+
'first name' => 'jean',
77+
'last name' => 'dupont',
78+
],
79+
],
80+
[
81+
[
82+
'first name' => 'john',
83+
'last name' => 'doe',
84+
],
85+
[
86+
'first name' => 'jean',
87+
'last name' => 'dupont',
88+
],
89+
],
90+
new Loader($this->writer, new TestLogger())
91+
);
92+
93+
$this->assertFileEquals(__DIR__.'/../data/users.csv', 'vfs://test.csv');
94+
}
6395
}

0 commit comments

Comments
 (0)