From 77d9ea5164cade2f7fc530dfa17933469e4ea981 Mon Sep 17 00:00:00 2001 From: ignace nyamagana butera Date: Fri, 10 Nov 2023 08:37:10 +0100 Subject: [PATCH] Remove useless constant --- docs/9.0/reader/record-mapping.md | 8 +++++--- src/Serializer/CastToArray.php | 4 ---- src/Serializer/CastToArrayTest.php | 16 ++++++++-------- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/docs/9.0/reader/record-mapping.md b/docs/9.0/reader/record-mapping.md index 2c55b412..e47c8180 100644 --- a/docs/9.0/reader/record-mapping.md +++ b/docs/9.0/reader/record-mapping.md @@ -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 @@ -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 @@ -295,7 +297,7 @@ use League\Csv\Serializer\TypeCastingFailed; /** * @implements TypeCasting */ -class CastToMoney implements TypeCasting +final class CastToMoney implements TypeCasting { public function __construct( string $propertyType, //always required and given by the Serializer implementation diff --git a/src/Serializer/CastToArray.php b/src/Serializer/CastToArray.php index d3eb7a86..e0c9f2ac 100644 --- a/src/Serializer/CastToArray.php +++ b/src/Serializer/CastToArray.php @@ -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; diff --git a/src/Serializer/CastToArrayTest.php b/src/Serializer/CastToArrayTest.php index 7d656bf9..5e61b12a 100644 --- a/src/Serializer/CastToArrayTest.php +++ b/src/Serializer/CastToArrayTest.php @@ -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],