Skip to content

Commit 180c673

Browse files
committed
Make Path and Options immutable
1 parent cff450f commit 180c673

62 files changed

Lines changed: 600 additions & 630 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/adapter/etl-adapter-avro/src/Flow/ETL/Adapter/Avro/FlixTech/AvroLoader.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@
1313

1414
final readonly class AvroLoader implements Closure, FileLoader, Loader
1515
{
16+
private Path $path;
17+
1618
public function __construct(
17-
private Path $path,
19+
Path $path,
1820
private ?Schema $schema = null,
1921
) {
2022
throw new RuntimeException('Avro integration was abandoned due to lack of availability of good Avro libraries.');
21-
$this->path->options()->setWhenEmpty(Option::CONTENT_TYPE->value, ContentType::AVRO);
23+
$this->path = $path->setOptionWhenEmpty(Option::CONTENT_TYPE->value, ContentType::AVRO);
2224
}
2325

2426
public function closure(FlowContext $context) : void

src/adapter/etl-adapter-avro/tests/Flow/ETL/Adapter/Avro/Tests/Integration/AvroTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ public function test_using_pattern_path() : void
4747
{
4848
$this->expectExceptionMessage("AvroLoader path can't be pattern, given: /path/*/pattern.avro");
4949

50-
to_avro(new Path('/path/*/pattern.avro'));
50+
to_avro(Path::from('/path/*/pattern.avro'));
5151
}
5252
}

src/adapter/etl-adapter-chartjs/src/Flow/ETL/Adapter/ChartJS/ChartJSLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ final class ChartJSLoader implements Closure, Loader
2121

2222
public function __construct(private readonly Chart $type)
2323
{
24-
$this->template = new Path(__DIR__ . '/Resources/template/full_page.html');
24+
$this->template = Path::from(__DIR__ . '/Resources/template/full_page.html');
2525
}
2626

2727
public function closure(FlowContext $context) : void

src/adapter/etl-adapter-csv/src/Flow/ETL/Adapter/CSV/CSVLoader.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ final class CSVLoader implements Closure, FileLoader, Loader
2222

2323
private string $newLineSeparator = PHP_EOL;
2424

25+
private readonly Path $path;
26+
2527
private string $separator = ',';
2628

27-
public function __construct(
28-
private readonly Path $path,
29-
) {
30-
$this->path->options()->setWhenEmpty(Option::CONTENT_TYPE->value, ContentType::CSV);
29+
public function __construct(Path $path)
30+
{
31+
$this->path = $path->setOptionWhenEmpty(Option::CONTENT_TYPE, ContentType::CSV);
3132
}
3233

3334
public function closure(FlowContext $context) : void
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Flow\ETL\Adapter\CSV\Tests\Unit;
6+
7+
use function Flow\Filesystem\DSL\path;
8+
use Flow\ETL\Adapter\CSV\CSVLoader;
9+
use Flow\Filesystem\Path\Option;
10+
use Flow\Filesystem\Path\Option\ContentType;
11+
use PHPUnit\Framework\TestCase;
12+
13+
final class CSVLoaderTest extends TestCase
14+
{
15+
public function test_setting_content_type_on_path() : void
16+
{
17+
$loader = new CSVLoader(path(__DIR__ . '/file.csv'));
18+
19+
self::assertEquals($loader->destination()->getOption(Option::CONTENT_TYPE), ContentType::CSV);
20+
}
21+
}

src/adapter/etl-adapter-excel/tests/Flow/ETL/Adapter/Excel/Tests/Unit/ExcelExtractorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ public function test_non_local_file() : void
2525
$this->expectException(InvalidArgumentException::class);
2626
$this->expectExceptionMessage('Only local filesystem paths are supported by ExcelExtractor due to the limitation of underlying library.');
2727

28-
from_excel(new Path('remote://unknown_file.xlsx'));
28+
from_excel(Path::from('remote://unknown_file.xlsx'));
2929
}
3030
}

src/adapter/etl-adapter-json/src/Flow/ETL/Adapter/JSON/JsonLinesLoader.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ final class JsonLinesLoader implements Closure, FileLoader, Loader
1515

1616
private int $flags = JSON_THROW_ON_ERROR;
1717

18-
public function __construct(private readonly Path $path)
18+
private readonly Path $path;
19+
20+
public function __construct(Path $path)
1921
{
20-
$this->path->options()->setWhenEmpty(Option::CONTENT_TYPE->value, ContentType::JSON);
22+
$this->path = $path->setOptionWhenEmpty(Option::CONTENT_TYPE->value, ContentType::JSON);
2123
}
2224

2325
public function closure(FlowContext $context) : void

src/adapter/etl-adapter-json/src/Flow/ETL/Adapter/JSON/JsonLoader.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,18 @@ final class JsonLoader implements Closure, FileLoader, Loader
1515

1616
private int $flags = JSON_THROW_ON_ERROR;
1717

18+
private readonly Path $path;
19+
1820
private bool $putRowsInNewLines = false;
1921

2022
/**
2123
* @var array<string, int>
2224
*/
2325
private array $writes = [];
2426

25-
public function __construct(private readonly Path $path)
27+
public function __construct(Path $path)
2628
{
27-
$this->path->options()->setWhenEmpty(Option::CONTENT_TYPE->value, ContentType::JSON);
29+
$this->path = $path->setOptionWhenEmpty(Option::CONTENT_TYPE, ContentType::JSON);
2830
}
2931

3032
public function closure(FlowContext $context) : void
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Flow\ETL\Adapter\JSON\Tests\Unit;
6+
7+
use function Flow\Filesystem\DSL\path;
8+
use Flow\ETL\Adapter\JSON\JsonLinesLoader;
9+
use Flow\Filesystem\Path\Option;
10+
use Flow\Filesystem\Path\Option\ContentType;
11+
use PHPUnit\Framework\TestCase;
12+
13+
final class JsonLinesLoaderTest extends TestCase
14+
{
15+
public function test_setting_content_type_on_path() : void
16+
{
17+
$loader = new JsonLinesLoader(path(__DIR__ . '/file.json'));
18+
19+
self::assertEquals($loader->destination()->getOption(Option::CONTENT_TYPE), ContentType::JSON);
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Flow\ETL\Adapter\JSON\Tests\Unit;
6+
7+
use function Flow\Filesystem\DSL\path;
8+
use Flow\ETL\Adapter\JSON\JsonLoader;
9+
use Flow\Filesystem\Path\Option;
10+
use Flow\Filesystem\Path\Option\ContentType;
11+
use PHPUnit\Framework\TestCase;
12+
13+
final class JsonLoaderTest extends TestCase
14+
{
15+
public function test_setting_content_type_on_path() : void
16+
{
17+
$loader = new JsonLoader(path(__DIR__ . '/file.json'));
18+
19+
self::assertEquals($loader->destination()->getOption(Option::CONTENT_TYPE), ContentType::JSON);
20+
}
21+
}

0 commit comments

Comments
 (0)