Skip to content

Commit 0ab1f46

Browse files
committed
Replaced nullable property of types with optional and union type
1 parent 7729cfe commit 0ab1f46

209 files changed

Lines changed: 3975 additions & 4824 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.

phpstan.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,4 @@ parameters:
9292
-
9393
function: 'dj()'
9494
includes:
95-
- tools/phpstan/vendor/spaze/phpstan-disallowed-calls/extension.neon
95+
- tools/phpstan/vendor/spaze/phpstan-disallowed-calls/extension.neon

src/adapter/etl-adapter-chartjs/tests/Flow/ETL/Adapter/ChartJS/Tests/Integration/ChartJSLoaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ public function test_loading_data_to_pie_chart() : void
277277
32555.32,
278278
13853.8,
279279
7854.33,
280-
10853.0,
280+
10853,
281281
4760.31,
282282
],
283283
'label' => '2023-01-01',

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function load(Rows $rows, FlowContext $context) : void
4545
return;
4646
}
4747

48-
$normalizer = new RowsNormalizer(new EntryNormalizer($context->config->caster(), $this->dateTimeFormat));
48+
$normalizer = new RowsNormalizer(new EntryNormalizer($this->dateTimeFormat));
4949

5050
$headers = $rows->first()->entries()->map(fn (Entry $entry) => $entry->name());
5151

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@
55
namespace Flow\ETL\Adapter\CSV\RowsNormalizer;
66

77
use function Flow\ETL\DSL\{date_interval_to_microseconds, type_json};
8-
use Flow\ETL\PHP\Type\Caster;
98
use Flow\ETL\Row\Entry;
109

1110
final readonly class EntryNormalizer
1211
{
1312
public function __construct(
14-
private Caster $caster,
1513
private string $dateTimeFormat = \DateTimeInterface::ATOM,
1614
private string $dateFormat = 'Y-m-d',
1715
) {
@@ -33,7 +31,7 @@ public function normalize(Entry $entry) : string|float|int|bool|null
3331
Entry\ListEntry::class,
3432
Entry\MapEntry::class,
3533
Entry\StructureEntry::class,
36-
Entry\JsonEntry::class => $this->caster->to(type_json())->value($entry->value()),
34+
Entry\JsonEntry::class => type_json()->cast($entry->value()),
3735
default => $entry->value(),
3836
};
3937
}

src/adapter/etl-adapter-csv/tests/Flow/ETL/Adapter/CSV/Tests/Unit/EntryNormalizerTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use function Flow\ETL\DSL\{bool_entry, date_entry, datetime_entry, float_entry, int_entry, null_entry, str_entry, time_entry, uuid_entry};
88
use Flow\ETL\Adapter\CSV\RowsNormalizer\EntryNormalizer;
9-
use Flow\ETL\PHP\Type\Caster;
109
use Flow\ETL\Row\Entry;
1110
use Flow\ETL\Tests\FlowTestCase;
1211
use PHPUnit\Framework\Attributes\DataProvider;
@@ -32,6 +31,6 @@ public static function entries_provider() : \Generator
3231
#[DataProvider('entries_provider')]
3332
public function test_normalizing_entries(Entry $entry, mixed $expected) : void
3433
{
35-
self::assertEquals($expected, (new EntryNormalizer(Caster::default()))->normalize($entry));
34+
self::assertEquals($expected, (new EntryNormalizer())->normalize($entry));
3635
}
3736
}

src/adapter/etl-adapter-doctrine/src/Flow/ETL/Adapter/Doctrine/SchemaConverter.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function toDbalTable(Schema $schema, string $tableName, array $tableOptio
4747
$columns = [];
4848

4949
foreach ($schema->definitions() as $definition) {
50-
$column = $this->flowToColumn($definition->entry()->name(), $definition->type(), $definition->metadata());
50+
$column = $this->flowToColumn($definition->entry()->name(), $definition->type(), $definition->isNullable(), $definition->metadata());
5151
$columns[$column->getName()] = $column;
5252
}
5353

@@ -72,9 +72,9 @@ private function columnToFlow(Column $column, Table $table) : Schema\Definition
7272
{
7373
$type = $this->typesMap->toFlowType($column->getType()::class);
7474

75-
$metadata = Schema\Metadata::empty();
75+
$nullable = !$column->getNotnull();
7676

77-
$type = $type->makeNullable(!$column->getNotnull());
77+
$metadata = Schema\Metadata::empty();
7878

7979
if ($column->getLength() !== null) {
8080
$metadata = $metadata->merge(DbalMetadata::length($column->getLength()));
@@ -116,7 +116,7 @@ private function columnToFlow(Column $column, Table $table) : Schema\Definition
116116
foreach ($table->getPrimaryKey()?->getColumns() ?? [] as $primaryKeyColumn) {
117117
if ($primaryKeyColumn === $column->getName()) {
118118
$metadata = $metadata->merge(DbalMetadata::primaryKey($table->getPrimaryKey()?->getName() ?? ''));
119-
$type = $type->makeNullable(false);
119+
$nullable = false;
120120
}
121121
}
122122

@@ -130,13 +130,13 @@ private function columnToFlow(Column $column, Table $table) : Schema\Definition
130130
}
131131
}
132132

133-
return new Schema\Definition($column->getName(), $type, $metadata);
133+
return new Schema\Definition($column->getName(), $type, $nullable, $metadata);
134134
}
135135

136136
/**
137137
* @param Type<mixed> $type
138138
*/
139-
private function flowToColumn(string $name, Type $type, ?Schema\Metadata $metadata = null) : Column
139+
private function flowToColumn(string $name, Type $type, bool $nullable, ?Schema\Metadata $metadata = null) : Column
140140
{
141141
$dbalTypeClass = $this->typesMap->toDbalType($type::class);
142142

@@ -159,13 +159,13 @@ private function flowToColumn(string $name, Type $type, ?Schema\Metadata $metada
159159
}
160160

161161
$options = [
162-
'notnull' => !$type->nullable(),
162+
'notnull' => !$nullable,
163163
];
164164

165165
if ($type instanceof FloatType) {
166166
// with decimals precision and scale are confusing, in float precision is number of digits, not digits before/after decimal point
167167
// with decimals precision is total number of digits, and scale is number of digits after decimal point
168-
$options['scale'] = $type->precision;
168+
$options['scale'] = 6;
169169
}
170170

171171
if ($metadata?->has(DbalMetadata::LENGTH->value)) {

src/adapter/etl-adapter-doctrine/tests/Flow/ETL/Adapter/Doctrine/Tests/Integration/DbalDataFrameFactoryTest.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,16 @@ public function test_dataframe_factory_with_schema() : void
110110
'ref' => 'id',
111111
'type' => [
112112
'type' => 'integer',
113-
'nullable' => false,
114113
],
114+
'nullable' => false,
115115
'metadata' => [],
116116
],
117117
[
118118
'ref' => 'name',
119119
'type' => [
120120
'type' => 'string',
121-
'nullable' => false,
122121
],
122+
'nullable' => false,
123123
'metadata' => [],
124124
],
125125
[
@@ -128,14 +128,12 @@ public function test_dataframe_factory_with_schema() : void
128128
'type' => 'map',
129129
'key' => [
130130
'type' => 'string',
131-
'nullable' => false,
132131
],
133132
'value' => [
134133
'type' => 'integer',
135-
'nullable' => false,
136134
],
137-
'nullable' => false,
138135
],
136+
'nullable' => false,
139137
'metadata' => [],
140138
],
141139
],

src/adapter/etl-adapter-doctrine/tests/Flow/ETL/Adapter/Doctrine/Tests/Integration/DbalLimitOffsetExtractorTest.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,16 +252,16 @@ public function test_extracting_entire_table_using_qb_with_schema() : void
252252
'ref' => 'id',
253253
'type' => [
254254
'type' => 'integer',
255-
'nullable' => false,
256255
],
256+
'nullable' => false,
257257
'metadata' => [],
258258
],
259259
[
260260
'ref' => 'name',
261261
'type' => [
262262
'type' => 'string',
263-
'nullable' => false,
264263
],
264+
'nullable' => false,
265265
'metadata' => [],
266266
],
267267
[
@@ -270,14 +270,12 @@ public function test_extracting_entire_table_using_qb_with_schema() : void
270270
'type' => 'map',
271271
'key' => [
272272
'type' => 'string',
273-
'nullable' => false,
274273
],
275274
'value' => [
276275
'type' => 'integer',
277-
'nullable' => false,
278276
],
279-
'nullable' => false,
280277
],
278+
'nullable' => false,
281279
'metadata' => [],
282280
],
283281
],

src/adapter/etl-adapter-doctrine/tests/Flow/ETL/Adapter/Doctrine/Tests/Integration/DbalQueryExtractorTest.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,16 +169,16 @@ public function test_extracting_multiple_rows_with_schema() : void
169169
'ref' => 'id',
170170
'type' => [
171171
'type' => 'integer',
172-
'nullable' => false,
173172
],
173+
'nullable' => false,
174174
'metadata' => [],
175175
],
176176
[
177177
'ref' => 'name',
178178
'type' => [
179179
'type' => 'string',
180-
'nullable' => false,
181180
],
181+
'nullable' => false,
182182
'metadata' => [],
183183
],
184184
[
@@ -187,14 +187,12 @@ public function test_extracting_multiple_rows_with_schema() : void
187187
'type' => 'map',
188188
'key' => [
189189
'type' => 'string',
190-
'nullable' => false,
191190
],
192191
'value' => [
193192
'type' => 'integer',
194-
'nullable' => false,
195193
],
196-
'nullable' => false,
197194
],
195+
'nullable' => false,
198196
'metadata' => [],
199197
],
200198
],

src/adapter/etl-adapter-parquet/src/Flow/ETL/Adapter/Parquet/ParquetLoader.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use Flow\ETL\{FlowContext, Loader, Rows};
88
use Flow\ETL\Loader\Closure;
9-
use Flow\ETL\PHP\Type\Caster;
109
use Flow\ETL\Schema;
1110
use Flow\Filesystem\Path;
1211
use Flow\Parquet\{Options, Writer};
@@ -34,7 +33,7 @@ final class ParquetLoader implements Closure, Loader, Loader\FileLoader
3433
public function __construct(private readonly Path $path)
3534
{
3635
$this->converter = new SchemaConverter();
37-
$this->normalizer = new RowsNormalizer(Caster::default());
36+
$this->normalizer = new RowsNormalizer();
3837
$this->options = Options::default();
3938
}
4039

0 commit comments

Comments
 (0)