Skip to content

Commit

Permalink
Remove useless constant
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Nov 10, 2023
1 parent f8d4a6f commit 77d9ea5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
8 changes: 5 additions & 3 deletions docs/9.0/reader/record-mapping.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ built-in methods support the `nullable` and the `mixed` types.
- They will return `null` or a specified default value, if the cell value is `null` and the type is `nullable`
- If the value can not be cast they will throw an exception.

For scalar conversion, type casting is done via PHP's `ext-filter` extension.

All classes are defined under the `League\Csv\Serializer` namespace.

### CastToString
Expand Down Expand Up @@ -262,8 +264,8 @@ use League\Csv\Serializer\Cell;
public function setData(array $data): void;
```

If the conversion succeeds, then the property wthat was needing the data
will be set with an `array` of float values.
If the conversion succeeds, then the property will be set with an `array` of `float` values.
The `type` option only supports scalar type (`string`, `int`, `float` and `bool`)

### Creating your own TypeCasting class

Expand Down Expand Up @@ -295,7 +297,7 @@ use League\Csv\Serializer\TypeCastingFailed;
/**
* @implements TypeCasting<Money|null>
*/
class CastToMoney implements TypeCasting
final class CastToMoney implements TypeCasting
{
public function __construct(
string $propertyType, //always required and given by the Serializer implementation
Expand Down
4 changes: 0 additions & 4 deletions src/Serializer/CastToArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@
*/
final class CastToArray implements TypeCasting
{
public const SHAPE_JSON = 'json';
public const SHAPE_LIST = 'list';
public const SHAPE_CSV = 'csv';

private readonly string $class;
private readonly bool $isNullable;
private readonly int $filterFlag;
Expand Down
16 changes: 8 additions & 8 deletions src/Serializer/CastToArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,56 +31,56 @@ public function testItCanConvertToArraygWithoutArguments(string $shape, string $
public static function providesValidStringForArray(): iterable
{
yield 'using the list shape' => [
'shape' => CastToArray::SHAPE_LIST,
'shape' => 'list',
'type' => 'string',
'input' => '1,2,3,4',
'expected' => ['1', '2', '3', '4'],
];

yield 'using the list shape with the float type' => [
'shape' => CastToArray::SHAPE_LIST,
'shape' => 'list',
'type' => 'float',
'input' => '1,2,3,4',
'expected' => [1.0, 2.0, 3.0, 4.0],
];

yield 'using the list shape with the int type' => [
'shape' => CastToArray::SHAPE_LIST,
'shape' => 'list',
'type' => 'int',
'input' => '1,2,3,4',
'expected' => [1, 2, 3, 4],
];

yield 'using the list shape with the bool type' => [
'shape' => CastToArray::SHAPE_LIST,
'shape' => 'list',
'type' => 'bool',
'input' => '1,on,true,yes',
'expected' => [true, true, true, true],
];

yield 'using the json shape' => [
'shape' => CastToArray::SHAPE_JSON,
'shape' => 'json',
'type' => 'string',
'input' => '[1,2,3,4]',
'expected' => [1, 2, 3, 4],
];

yield 'using the json shape is not affected by the type argument' => [
'shape' => CastToArray::SHAPE_JSON,
'shape' => 'json',
'type' => 'iterable',
'input' => '[1,2,3,4]',
'expected' => [1, 2, 3, 4],
];

yield 'using the csv shape' => [
'shape' => CastToArray::SHAPE_CSV,
'shape' => 'csv',
'type' => 'string',
'input' => '"1",2,3,"4"',
'expected' => ['1', '2', '3', '4'],
];

yield 'using the csv shape with type int' => [
'shape' => CastToArray::SHAPE_CSV,
'shape' => 'csv',
'type' => 'int',
'input' => '"1",2,3,"4"',
'expected' => [1, 2, 3, 4],
Expand Down

0 comments on commit 77d9ea5

Please sign in to comment.