From 7081e80ee461643d60dc588a98853a082fa5c97a Mon Sep 17 00:00:00 2001 From: Peter Thaleikis Date: Mon, 14 Nov 2022 15:23:46 +0100 Subject: [PATCH] Better type casting --- src/UsesParsers.php | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/src/UsesParsers.php b/src/UsesParsers.php index e93e783..c3b261e 100644 --- a/src/UsesParsers.php +++ b/src/UsesParsers.php @@ -129,15 +129,15 @@ public function csvDecodeWithHeader( } // Helper method to cast types - protected function castType(string $entry) + public function castType(string $entry) { // Looks like an int? - if ($entry == (int) $entry) { + if ($entry == (string) (int) $entry) { return (int) $entry; } // Looks like a float? - if ($entry == (float) $entry) { + if ($entry == (string) (float) $entry) { return (float) $entry; } @@ -145,6 +145,9 @@ protected function castType(string $entry) } + + + /** * A boilerplate function to process the various calling options for `parseX` functions. */ @@ -235,12 +238,27 @@ public function parseCsv(?string $csvStringOrUrl = null): array } - // // Associate - // $csv = array_map('str_getcsv', file($file)); - // array_walk($csv, function(&$a) use ($csv) { - // $a = array_combine($csv[0], $a); - // }); - // array_shift($csv); + + + + + + + + + + + + + + + + + + + + +