Skip to content

Commit

Permalink
Remove from* methods from scalar entry classes (#804)
Browse files Browse the repository at this point in the history
  • Loading branch information
stloyd committed Nov 20, 2023
1 parent b89f2f3 commit 5fe5631
Show file tree
Hide file tree
Showing 9 changed files with 5 additions and 170 deletions.
6 changes: 5 additions & 1 deletion UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,17 @@ More details can be found in [this issue](https://github.com/flow-php/flow/issue

- Removed etl-adapter-amphp
- Removed etl-adapter-reactphp
- Removed LocalSocketPipeline
- Removed `LocalSocketPipeline`
- Removed `DataFrame::pipeline()`

### 12) `CollectionEntry` removal

After adding native & logical types into the Flow, we remove the `CollectionEntry` as obsolete. New types that cover it better are: `ListType`, `MapType` & `StructureType` along with related new entry types.

### 13) Removed `from*()` methods from scalar entries

Removed `BooleanEntry::from()`, `FloatEntry::from()`, `IntegerEntry::from()`, `StringEntry::fromDateTime()` methods in favor of using DSL functions.

---

## Upgrading from 0.3.x to 0.4.x
Expand Down
23 changes: 0 additions & 23 deletions src/core/etl/src/Flow/ETL/Row/Entry/BooleanEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,6 @@ public function __construct(private readonly string $name, private readonly bool
$this->type = ScalarType::boolean();
}

public static function from(string $name, bool|int|string $value) : self
{
if (\is_bool($value)) {
return new self($name, $value);
}

$value = \mb_strtolower(\trim((string) $value));

if (!\in_array($value, ['1', '0', 'true', 'false', 'yes', 'no'], true)) {
throw InvalidArgumentException::because('Value "%s" can\'t be casted to boolean.', $value);
}

if ($value === 'true' || $value === 'yes') {
return new self($name, true);
}

if ($value === 'false' || $value === 'no') {
return new self($name, false);
}

return new self($name, (bool) $value);
}

public function __serialize() : array
{
return ['name' => $this->name, 'value' => $this->value, 'type' => $this->type];
Expand Down
9 changes: 0 additions & 9 deletions src/core/etl/src/Flow/ETL/Row/Entry/FloatEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,6 @@ public function __construct(private readonly string $name, private readonly floa
$this->type = ScalarType::float();
}

public static function from(string $name, float|int|string $value) : self
{
if (!\is_numeric($value) || $value != (int) $value) {
throw InvalidArgumentException::because(\sprintf('Value "%s" can\'t be casted to integer.', $value));
}

return new self($name, (float) $value);
}

public function __serialize() : array
{
return ['name' => $this->name, 'value' => $this->value, 'precision' => $this->precision, 'type' => $this->type];
Expand Down
9 changes: 0 additions & 9 deletions src/core/etl/src/Flow/ETL/Row/Entry/IntegerEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,6 @@ public function __construct(private readonly string $name, private readonly int
$this->type = ScalarType::integer();
}

public static function from(string $name, float|int|string $value) : self
{
if (!\is_numeric($value) || $value != (int) $value) {
throw InvalidArgumentException::because(\sprintf('Value "%s" can\'t be casted to integer.', $value));
}

return new self($name, (int) $value);
}

public function __serialize() : array
{
return ['name' => $this->name, 'value' => $this->value, 'type' => $this->type];
Expand Down
8 changes: 0 additions & 8 deletions src/core/etl/src/Flow/ETL/Row/Entry/StringEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@ public function __construct(private readonly string $name, private string $value
$this->type = ScalarType::string();
}

/**
* @throws InvalidArgumentException
*/
public static function fromDateTime(string $name, \DateTimeInterface $dateTime, string $format = \DateTimeInterface::ATOM) : self
{
return new self($name, $dateTime->format($format));
}

/**
* @throws InvalidArgumentException
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,6 @@ public static function is_equal_data_provider() : \Generator
yield 'different names characters and equal values' => [false, new BooleanEntry('NAME', true), new BooleanEntry('name', true)];
}

public static function valid_false_entries() : \Generator
{
yield [false];
yield [0];
yield ['0'];
yield ['false'];
yield ['no'];
}

public static function valid_true_entries() : \Generator
{
yield [true];
yield [1];
yield ['1'];
yield ['true'];
yield ['yes'];
}

/**
* @dataProvider valid_false_entries
*/
public function test_creates_false_entry_from_not_boolean_values($value) : void
{
$entry = BooleanEntry::from('entry-name', $value);

$this->assertFalse($entry->value());
}

/**
* @dataProvider valid_true_entries
*/
public function test_creates_true_entry_from_not_boolean_values($value) : void
{
$entry = BooleanEntry::from('entry-name', $value);

$this->assertTrue($entry->value());
}

public function test_entry_name_can_be_zero() : void
{
$this->assertSame('0', (new BooleanEntry('0', true))->name());
Expand All @@ -78,13 +40,6 @@ public function test_map() : void
);
}

public function test_prevents_from_creating_entry_from_random_value() : void
{
$this->expectExceptionMessage('Value "random-value" can\'t be casted to boolean');

BooleanEntry::from('entry-name', 'random-value');
}

public function test_prevents_from_creating_entry_with_empty_entry_name() : void
{
$this->expectExceptionMessage('Entry name cannot be empty');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@

final class FloatEntryTest extends TestCase
{
public static function invalid_entries() : \Generator
{
yield ['random_value'];
}

public static function is_equal_data_provider() : \Generator
{
yield 'equal names and values' => [true, new FloatEntry('name', 1.0), new FloatEntry('name', 1.0)];
Expand All @@ -24,24 +19,6 @@ public static function is_equal_data_provider() : \Generator
yield 'different names characters and different values with high precision' => [false, new FloatEntry('NAME', 1.205502), new FloatEntry('name', 1.205501)];
}

public static function valid_float_entries() : \Generator
{
yield [100];
yield [100.00];
yield ['100'];
yield ['100.00'];
}

/**
* @dataProvider valid_float_entries
*/
public function test_creates_true_entry_from_not_boolean_values($value) : void
{
$entry = FloatEntry::from('entry-name', $value);

$this->assertEquals((int) $value, $entry->value());
}

public function test_entry_name_can_be_zero() : void
{
$this->assertSame('0', (new FloatEntry('0', 0))->name());
Expand All @@ -65,16 +42,6 @@ public function test_map() : void
);
}

/**
* @dataProvider invalid_entries
*/
public function test_prevents_from_creating_entry_from_invalid_entry_values($value) : void
{
$this->expectExceptionMessage(\sprintf('Value "%s" can\'t be casted to integer', $value));

FloatEntry::from('entry-name', $value);
}

public function test_prevents_from_creating_entry_with_empty_entry_name() : void
{
$this->expectExceptionMessage('Entry name cannot be empty');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@

final class IntegerEntryTest extends TestCase
{
public static function invalid_entries() : \Generator
{
yield ['random_value'];
yield [100.50];
yield ['100.5'];
}

public static function is_equal_data_provider() : \Generator
{
yield 'equal names and values' => [true, new IntegerEntry('name', 1), new IntegerEntry('name', 1)];
Expand All @@ -24,24 +17,6 @@ public static function is_equal_data_provider() : \Generator
yield 'different names characters and equal values' => [false, new IntegerEntry('NAME', 1), new IntegerEntry('name', 1)];
}

public static function valid_integer_entries() : \Generator
{
yield [100];
yield [100.00];
yield ['100'];
yield ['100.00'];
}

/**
* @dataProvider valid_integer_entries
*/
public function test_creates_true_entry_from_not_boolean_values($value) : void
{
$entry = IntegerEntry::from('entry-name', $value);

$this->assertEquals((int) $value, $entry->value());
}

public function test_entry_name_can_be_zero() : void
{
$this->assertSame('0', (new IntegerEntry('0', 0))->name());
Expand All @@ -65,16 +40,6 @@ public function test_map() : void
);
}

/**
* @dataProvider invalid_entries
*/
public function test_prevents_from_creating_entry_from_invalid_entry_values($value) : void
{
$this->expectExceptionMessage(\sprintf('Value "%s" can\'t be casted to integer', $value));

IntegerEntry::from('entry-name', $value);
}

public function test_prevents_from_creating_entry_with_empty_entry_name() : void
{
$this->expectExceptionMessage('Entry name cannot be empty');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ public static function is_equal_data_provider() : \Generator
yield 'different names characters and equal values' => [false, new StringEntry('NAME', 'value'), new StringEntry('name', 'value')];
}

public function test_creates_datetime_value() : void
{
$entry = StringEntry::fromDateTime('datetime', new \DateTimeImmutable('2021-06-01 00:00:00 UTC'));

$this->assertEquals('2021-06-01T00:00:00+00:00', $entry->value());
}

public function test_creates_lowercase_value() : void
{
$entry = StringEntry::lowercase('lowercase', 'It Should Be Lowercase');
Expand Down

0 comments on commit 5fe5631

Please sign in to comment.