From 3b20e13722f54decf7a8855f077fbbd4b804d0b6 Mon Sep 17 00:00:00 2001 From: webeweb Date: Wed, 12 Jun 2024 17:47:00 +0200 Subject: [PATCH] Fix type error into String helper when argument is not a string --- src/Helper/StringHelper.php | 4 ++++ tests/Helper/StringHelperTest.php | 12 ++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Helper/StringHelper.php b/src/Helper/StringHelper.php index a8dc7f0d1..c421c9b40 100644 --- a/src/Helper/StringHelper.php +++ b/src/Helper/StringHelper.php @@ -189,6 +189,10 @@ public static function parseArray(array $values): string { if (true === is_array($value)) { $buffer = trim(implode(" ", $value)); + } elseif (true === is_bool($value)) { + $buffer = static::parseBoolean($value); + } elseif (true === is_numeric($value)) { + $buffer = $value; } else { $buffer = trim($value); } diff --git a/tests/Helper/StringHelperTest.php b/tests/Helper/StringHelperTest.php index 4ebb14b8a..99aa081af 100644 --- a/tests/Helper/StringHelperTest.php +++ b/tests/Helper/StringHelperTest.php @@ -145,16 +145,20 @@ public function testMoreThan(): void { public function testParseArray(): void { $arg = [ - "exception" => null, - "id" => "id", - "class" => [ + "exception" => null, + "id" => "id", + "class" => [ "class1", "class2", "class3 class4", ], + "data-type-boolean" => true, + "data-type-float" => 0.1, + "data-type-integer" => 1, ]; + $exp = 'id="id" class="class1 class2 class3 class4" data-type-boolean="true" data-type-float="0.1" data-type-integer="1"'; - $this->assertEquals('id="id" class="class1 class2 class3 class4"', StringHelper::parseArray($arg)); + $this->assertEquals($exp, StringHelper::parseArray($arg)); } /**